Coverage Report

Created: 2026-11-23 00:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5T.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
 * Module Info: This module contains most of the "core" functionality of
15
 *      the H5T interface, including the API initialization code, etc.
16
 *      Many routines that are infrequently used, or are specialized for
17
 *      one particular datatype class are in another module.
18
 */
19
20
/****************/
21
/* Module Setup */
22
/****************/
23
24
#include "H5Tmodule.h" /* This source code file is part of the H5T module */
25
26
/***********/
27
/* Headers */
28
/***********/
29
#include "H5private.h"   /* Generic Functions                        */
30
#include "H5ACprivate.h" /* Metadata cache                           */
31
#include "H5CXprivate.h" /* API Contexts                             */
32
#include "H5Dprivate.h"  /* Datasets                                 */
33
#include "H5Eprivate.h"  /* Error handling                           */
34
#include "H5ESprivate.h" /* Event Sets                               */
35
#include "H5Fprivate.h"  /* Files                                    */
36
#include "H5FLprivate.h" /* Free Lists                               */
37
#include "H5FOprivate.h" /* File objects                             */
38
#include "H5Gprivate.h"  /* Groups                                   */
39
#include "H5Iprivate.h"  /* IDs                                      */
40
#include "H5MMprivate.h" /* Memory management                        */
41
#include "H5Pprivate.h"  /* Property lists                           */
42
#include "H5Tpkg.h"      /* Datatypes                                */
43
#include "H5VLprivate.h" /* Virtual Object Layer                     */
44
#include "H5VMprivate.h" /* Vectors and arrays                       */
45
46
/* Datatype conversion functions */
47
#include "H5Tconv_integer.h"
48
#include "H5Tconv_float.h"
49
#include "H5Tconv_string.h"
50
#include "H5Tconv_bitfield.h"
51
#include "H5Tconv_compound.h"
52
#include "H5Tconv_reference.h"
53
#include "H5Tconv_enum.h"
54
#include "H5Tconv_vlen.h"
55
#include "H5Tconv_array.h"
56
#include "H5Tconv_complex.h"
57
58
/****************/
59
/* Local Macros */
60
/****************/
61
62
6.44k
#define H5T_ENCODE_VERSION 0
63
64
/*
65
 * The default number of slots allocated in the
66
 * datatype conversion path table.
67
 */
68
6
#define H5T_DEF_CONV_TABLE_SLOTS 128
69
70
/*
71
 * Type initialization macros
72
 *
73
 * These use the "template macro" technique to reduce the amount of gratuitous
74
 * duplicated code when initializing the datatypes for the library.  The main
75
 * template macro is the H5T_INIT_TYPE() macro below.
76
 *
77
 */
78
79
/* Define the code template for bitfields for the "GUTS" in the H5T_INIT_TYPE macro */
80
#define H5T_INIT_TYPE_BITFIELD_CORE                                                                          \
81
72
    {                                                                                                        \
82
72
        dt->shared->type = H5T_BITFIELD;                                                                     \
83
72
    }
84
85
#define H5T_INIT_TYPE_BITFIELD_COMMON(ENDIANNESS)                                                            \
86
48
    {                                                                                                        \
87
48
        H5T_INIT_TYPE_NUM_COMMON(ENDIANNESS)                                                                 \
88
48
        H5T_INIT_TYPE_BITFIELD_CORE;                                                                         \
89
48
    }
90
91
#define H5T_INIT_TYPE_BITFIELDLE_CORE                                                                        \
92
24
    {                                                                                                        \
93
24
        H5T_INIT_TYPE_BITFIELD_COMMON(H5T_ORDER_LE)                                                          \
94
24
    }
95
96
#define H5T_INIT_TYPE_BITFIELDBE_CORE                                                                        \
97
24
    {                                                                                                        \
98
24
        H5T_INIT_TYPE_BITFIELD_COMMON(H5T_ORDER_BE)                                                          \
99
24
    }
100
101
/* Define the code template for times for the "GUTS" in the H5T_INIT_TYPE macro */
102
#define H5T_INIT_TYPE_TIME_CORE                                                                              \
103
24
    {                                                                                                        \
104
24
        dt->shared->type = H5T_TIME;                                                                         \
105
24
    }
106
107
/* Define the code template for types which reset the offset for the "GUTS" in the H5T_INIT_TYPE macro */
108
#define H5T_INIT_TYPE_OFFSET_CORE                                                                            \
109
30
    {                                                                                                        \
110
30
        dt->shared->u.atomic.offset = 0;                                                                     \
111
30
    }
112
113
/* Define common code for all numeric types (floating-point & int, signed & unsigned) */
114
#define H5T_INIT_TYPE_NUM_COMMON(ENDIANNESS)                                                                 \
115
264
    {                                                                                                        \
116
264
        dt->shared->u.atomic.order   = ENDIANNESS;                                                           \
117
264
        dt->shared->u.atomic.offset  = 0;                                                                    \
118
264
        dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO;                                                         \
119
264
        dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO;                                                         \
120
264
    }
121
122
/* Define the code templates for standard 16-bit floats for the "GUTS" in the H5T_INIT_TYPE macro */
123
#define H5T_INIT_TYPE_FLOAT16_COMMON(ENDIANNESS)                                                             \
124
12
    {                                                                                                        \
125
12
        H5T_INIT_TYPE_NUM_COMMON(ENDIANNESS)                                                                 \
126
12
        dt->shared->u.atomic.u.f.sign  = 15;                                                                 \
127
12
        dt->shared->u.atomic.u.f.epos  = 10;                                                                 \
128
12
        dt->shared->u.atomic.u.f.esize = 5;                                                                  \
129
12
        dt->shared->u.atomic.u.f.ebias = 0xf;                                                                \
130
12
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
131
12
        dt->shared->u.atomic.u.f.msize = 10;                                                                 \
132
12
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
133
12
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
134
12
    }
135
136
#define H5T_INIT_TYPE_FLOAT16LE_CORE                                                                         \
137
6
    {                                                                                                        \
138
6
        H5T_INIT_TYPE_FLOAT16_COMMON(H5T_ORDER_LE)                                                           \
139
6
    }
140
141
#define H5T_INIT_TYPE_FLOAT16BE_CORE                                                                         \
142
6
    {                                                                                                        \
143
6
        H5T_INIT_TYPE_FLOAT16_COMMON(H5T_ORDER_BE)                                                           \
144
6
    }
145
146
/* Define the code templates for standard 16-bit bfloat16 floats for the "GUTS" in the H5T_INIT_TYPE macro */
147
#define H5T_INIT_TYPE_BFLOAT16_COMMON(ENDIANNESS)                                                            \
148
12
    {                                                                                                        \
149
12
        H5T_INIT_TYPE_NUM_COMMON(ENDIANNESS)                                                                 \
150
12
        dt->shared->u.atomic.u.f.sign  = 15;                                                                 \
151
12
        dt->shared->u.atomic.u.f.epos  = 7;                                                                  \
152
12
        dt->shared->u.atomic.u.f.esize = 8;                                                                  \
153
12
        dt->shared->u.atomic.u.f.ebias = 0x7f;                                                               \
154
12
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
155
12
        dt->shared->u.atomic.u.f.msize = 7;                                                                  \
156
12
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
157
12
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
158
12
    }
159
160
#define H5T_INIT_TYPE_BFLOAT16LE_CORE                                                                        \
161
6
    {                                                                                                        \
162
6
        H5T_INIT_TYPE_BFLOAT16_COMMON(H5T_ORDER_LE)                                                          \
163
6
    }
164
165
#define H5T_INIT_TYPE_BFLOAT16BE_CORE                                                                        \
166
6
    {                                                                                                        \
167
6
        H5T_INIT_TYPE_BFLOAT16_COMMON(H5T_ORDER_BE)                                                          \
168
6
    }
169
170
/* Define the code templates for standard FP8 E4M3 8-bit floats for the "GUTS" in the H5T_INIT_TYPE macro */
171
#define H5T_INIT_TYPE_FLOAT8E4M3_CORE                                                                        \
172
6
    {                                                                                                        \
173
6
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_LE) /* Simply pick LE here */                                     \
174
6
        dt->shared->u.atomic.u.f.sign  = 7;                                                                  \
175
6
        dt->shared->u.atomic.u.f.epos  = 3;                                                                  \
176
6
        dt->shared->u.atomic.u.f.esize = 4;                                                                  \
177
6
        dt->shared->u.atomic.u.f.ebias = 0x7;                                                                \
178
6
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
179
6
        dt->shared->u.atomic.u.f.msize = 3;                                                                  \
180
6
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
181
6
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
182
6
    }
183
184
/* Define the code templates for standard FP8 E5M2 8-bit floats for the "GUTS" in the H5T_INIT_TYPE macro */
185
#define H5T_INIT_TYPE_FLOAT8E5M2_CORE                                                                        \
186
6
    {                                                                                                        \
187
6
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_LE) /* Simply pick LE here */                                     \
188
6
        dt->shared->u.atomic.u.f.sign  = 7;                                                                  \
189
6
        dt->shared->u.atomic.u.f.epos  = 2;                                                                  \
190
6
        dt->shared->u.atomic.u.f.esize = 5;                                                                  \
191
6
        dt->shared->u.atomic.u.f.ebias = 0xf;                                                                \
192
6
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
193
6
        dt->shared->u.atomic.u.f.msize = 2;                                                                  \
194
6
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
195
6
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
196
6
    }
197
198
/* Define the code templates for standard FP6 E2M3 6-bit floats for the "GUTS" in the H5T_INIT_TYPE macro */
199
#define H5T_INIT_TYPE_FLOAT6E2M3_CORE                                                                        \
200
6
    {                                                                                                        \
201
6
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_LE) /* Simply pick LE here */                                     \
202
6
        dt->shared->u.atomic.prec      = 6;                                                                  \
203
6
        dt->shared->u.atomic.u.f.sign  = 5;                                                                  \
204
6
        dt->shared->u.atomic.u.f.epos  = 3;                                                                  \
205
6
        dt->shared->u.atomic.u.f.esize = 2;                                                                  \
206
6
        dt->shared->u.atomic.u.f.ebias = 0x1;                                                                \
207
6
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
208
6
        dt->shared->u.atomic.u.f.msize = 3;                                                                  \
209
6
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
210
6
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
211
6
    }
212
213
/* Define the code templates for standard FP6 E3M2 6-bit floats for the "GUTS" in the H5T_INIT_TYPE macro */
214
#define H5T_INIT_TYPE_FLOAT6E3M2_CORE                                                                        \
215
6
    {                                                                                                        \
216
6
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_LE) /* Simply pick LE here */                                     \
217
6
        dt->shared->u.atomic.prec      = 6;                                                                  \
218
6
        dt->shared->u.atomic.u.f.sign  = 5;                                                                  \
219
6
        dt->shared->u.atomic.u.f.epos  = 2;                                                                  \
220
6
        dt->shared->u.atomic.u.f.esize = 3;                                                                  \
221
6
        dt->shared->u.atomic.u.f.ebias = 0x3;                                                                \
222
6
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
223
6
        dt->shared->u.atomic.u.f.msize = 2;                                                                  \
224
6
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
225
6
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
226
6
    }
227
228
/* Define the code templates for standard FP4 E2M1 4-bit floats for the "GUTS" in the H5T_INIT_TYPE macro */
229
#define H5T_INIT_TYPE_FLOAT4E2M1_CORE                                                                        \
230
6
    {                                                                                                        \
231
6
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_LE) /* Simply pick LE here */                                     \
232
6
        dt->shared->u.atomic.prec      = 4;                                                                  \
233
6
        dt->shared->u.atomic.u.f.sign  = 3;                                                                  \
234
6
        dt->shared->u.atomic.u.f.epos  = 1;                                                                  \
235
6
        dt->shared->u.atomic.u.f.esize = 2;                                                                  \
236
6
        dt->shared->u.atomic.u.f.ebias = 0x1;                                                                \
237
6
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
238
6
        dt->shared->u.atomic.u.f.msize = 1;                                                                  \
239
6
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
240
6
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
241
6
    }
242
243
/* Define the code templates for standard floats for the "GUTS" in the H5T_INIT_TYPE macro */
244
#define H5T_INIT_TYPE_FLOAT_COMMON(ENDIANNESS)                                                               \
245
12
    {                                                                                                        \
246
12
        H5T_INIT_TYPE_NUM_COMMON(ENDIANNESS)                                                                 \
247
12
        dt->shared->u.atomic.u.f.sign  = 31;                                                                 \
248
12
        dt->shared->u.atomic.u.f.epos  = 23;                                                                 \
249
12
        dt->shared->u.atomic.u.f.esize = 8;                                                                  \
250
12
        dt->shared->u.atomic.u.f.ebias = 0x7f;                                                               \
251
12
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
252
12
        dt->shared->u.atomic.u.f.msize = 23;                                                                 \
253
12
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
254
12
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
255
12
    }
256
257
#define H5T_INIT_TYPE_FLOATLE_CORE                                                                           \
258
6
    {                                                                                                        \
259
6
        H5T_INIT_TYPE_FLOAT_COMMON(H5T_ORDER_LE)                                                             \
260
6
    }
261
262
#define H5T_INIT_TYPE_FLOATBE_CORE                                                                           \
263
6
    {                                                                                                        \
264
6
        H5T_INIT_TYPE_FLOAT_COMMON(H5T_ORDER_BE)                                                             \
265
6
    }
266
267
/* Define the code templates for standard doubles for the "GUTS" in the H5T_INIT_TYPE macro */
268
#define H5T_INIT_TYPE_DOUBLE_COMMON(ENDIANNESS)                                                              \
269
12
    {                                                                                                        \
270
12
        H5T_INIT_TYPE_NUM_COMMON(ENDIANNESS)                                                                 \
271
12
        dt->shared->u.atomic.u.f.sign  = 63;                                                                 \
272
12
        dt->shared->u.atomic.u.f.epos  = 52;                                                                 \
273
12
        dt->shared->u.atomic.u.f.esize = 11;                                                                 \
274
12
        dt->shared->u.atomic.u.f.ebias = 0x03ff;                                                             \
275
12
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
276
12
        dt->shared->u.atomic.u.f.msize = 52;                                                                 \
277
12
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
278
12
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
279
12
    }
280
281
#define H5T_INIT_TYPE_DOUBLELE_CORE                                                                          \
282
6
    {                                                                                                        \
283
6
        H5T_INIT_TYPE_DOUBLE_COMMON(H5T_ORDER_LE)                                                            \
284
6
    }
285
286
#define H5T_INIT_TYPE_DOUBLEBE_CORE                                                                          \
287
6
    {                                                                                                        \
288
6
        H5T_INIT_TYPE_DOUBLE_COMMON(H5T_ORDER_BE)                                                            \
289
6
    }
290
291
/* Define the code templates for VAX float for the "GUTS" in the H5T_INIT_TYPE macro */
292
#define H5T_INIT_TYPE_FLOATVAX_CORE                                                                          \
293
6
    {                                                                                                        \
294
6
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_VAX)                                                              \
295
6
        dt->shared->u.atomic.u.f.sign  = 31;                                                                 \
296
6
        dt->shared->u.atomic.u.f.epos  = 23;                                                                 \
297
6
        dt->shared->u.atomic.u.f.esize = 8;                                                                  \
298
6
        dt->shared->u.atomic.u.f.ebias = 0x81;                                                               \
299
6
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
300
6
        dt->shared->u.atomic.u.f.msize = 23;                                                                 \
301
6
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
302
6
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
303
6
        dt->shared->version            = H5O_DTYPE_VERSION_3;                                                \
304
6
    }
305
306
/* Define the code templates for VAX double for the "GUTS" in the H5T_INIT_TYPE macro */
307
#define H5T_INIT_TYPE_DOUBLEVAX_CORE                                                                         \
308
6
    {                                                                                                        \
309
6
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_VAX)                                                              \
310
6
        dt->shared->u.atomic.u.f.sign  = 63;                                                                 \
311
6
        dt->shared->u.atomic.u.f.epos  = 52;                                                                 \
312
6
        dt->shared->u.atomic.u.f.esize = 11;                                                                 \
313
6
        dt->shared->u.atomic.u.f.ebias = 0x0401;                                                             \
314
6
        dt->shared->u.atomic.u.f.mpos  = 0;                                                                  \
315
6
        dt->shared->u.atomic.u.f.msize = 52;                                                                 \
316
6
        dt->shared->u.atomic.u.f.norm  = H5T_NORM_IMPLIED;                                                   \
317
6
        dt->shared->u.atomic.u.f.pad   = H5T_PAD_ZERO;                                                       \
318
6
        dt->shared->version            = H5O_DTYPE_VERSION_3;                                                \
319
6
    }
320
321
/* Define the code templates for standard signed integers for the "GUTS" in the H5T_INIT_TYPE macro */
322
#define H5T_INIT_TYPE_SINT_COMMON(ENDIANNESS)                                                                \
323
48
    {                                                                                                        \
324
48
        H5T_INIT_TYPE_NUM_COMMON(ENDIANNESS)                                                                 \
325
48
        dt->shared->u.atomic.u.i.sign = H5T_SGN_2;                                                           \
326
48
    }
327
328
#define H5T_INIT_TYPE_SINTLE_CORE                                                                            \
329
24
    {                                                                                                        \
330
24
        H5T_INIT_TYPE_SINT_COMMON(H5T_ORDER_LE)                                                              \
331
24
    }
332
333
#define H5T_INIT_TYPE_SINTBE_CORE                                                                            \
334
24
    {                                                                                                        \
335
24
        H5T_INIT_TYPE_SINT_COMMON(H5T_ORDER_BE)                                                              \
336
24
    }
337
338
/* Define the code templates for standard unsigned integers for the "GUTS" in the H5T_INIT_TYPE macro */
339
#define H5T_INIT_TYPE_UINT_COMMON(ENDIANNESS)                                                                \
340
48
    {                                                                                                        \
341
48
        H5T_INIT_TYPE_NUM_COMMON(ENDIANNESS)                                                                 \
342
48
        dt->shared->u.atomic.u.i.sign = H5T_SGN_NONE;                                                        \
343
48
    }
344
345
#define H5T_INIT_TYPE_UINTLE_CORE                                                                            \
346
24
    {                                                                                                        \
347
24
        H5T_INIT_TYPE_UINT_COMMON(H5T_ORDER_LE)                                                              \
348
24
    }
349
350
#define H5T_INIT_TYPE_UINTBE_CORE                                                                            \
351
24
    {                                                                                                        \
352
24
        H5T_INIT_TYPE_UINT_COMMON(H5T_ORDER_BE)                                                              \
353
24
    }
354
355
/* Define a macro for common code for all newly allocate datatypes */
356
#define H5T_INIT_TYPE_ALLOC_COMMON(TYPE)                                                                     \
357
36
    {                                                                                                        \
358
36
        dt->sh_loc.type  = H5O_SHARE_TYPE_UNSHARED;                                                          \
359
36
        dt->shared->type = TYPE;                                                                             \
360
36
    }
361
362
/* Define the code templates for opaque for the "GUTS" in the H5T_INIT_TYPE macro */
363
#define H5T_INIT_TYPE_OPAQ_CORE                                                                              \
364
6
    {                                                                                                        \
365
6
        H5T_INIT_TYPE_ALLOC_COMMON(H5T_OPAQUE)                                                               \
366
6
        dt->shared->u.opaque.tag = H5MM_xstrdup("");                                                         \
367
6
    }
368
369
/* Define the code templates for strings for the "GUTS" in the H5T_INIT_TYPE macro */
370
#define H5T_INIT_TYPE_STRING_COMMON                                                                          \
371
12
    {                                                                                                        \
372
12
        H5T_INIT_TYPE_ALLOC_COMMON(H5T_STRING)                                                               \
373
12
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_NONE)                                                             \
374
12
        dt->shared->u.atomic.u.s.cset = H5F_DEFAULT_CSET;                                                    \
375
12
    }
376
377
#define H5T_INIT_TYPE_CSTRING_CORE                                                                           \
378
6
    {                                                                                                        \
379
6
        H5T_INIT_TYPE_STRING_COMMON                                                                          \
380
6
        dt->shared->u.atomic.u.s.pad = H5T_STR_NULLTERM;                                                     \
381
6
    }
382
383
#define H5T_INIT_TYPE_FORSTRING_CORE                                                                         \
384
6
    {                                                                                                        \
385
6
        H5T_INIT_TYPE_STRING_COMMON                                                                          \
386
6
        dt->shared->u.atomic.u.s.pad = H5T_STR_SPACEPAD;                                                     \
387
6
    }
388
389
/* Define the code templates for references for the "GUTS" in the H5T_INIT_TYPE macro */
390
#define H5T_INIT_TYPE_REF_COMMON                                                                             \
391
18
    {                                                                                                        \
392
18
        H5T_INIT_TYPE_ALLOC_COMMON(H5T_REFERENCE)                                                            \
393
18
        H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_NONE)                                                             \
394
18
        dt->shared->force_conv        = true;                                                                \
395
18
        dt->shared->u.atomic.u.r.file = NULL;                                                                \
396
18
        dt->shared->u.atomic.u.r.loc  = H5T_LOC_BADLOC;                                                      \
397
18
        dt->shared->u.atomic.u.r.cls  = NULL;                                                                \
398
18
    }
399
400
#define H5T_INIT_TYPE_OBJREF_CORE                                                                            \
401
6
    {                                                                                                        \
402
6
        H5T_INIT_TYPE_REF_COMMON                                                                             \
403
6
        dt->shared->u.atomic.u.r.rtype   = H5R_OBJECT1;                                                      \
404
6
        dt->shared->u.atomic.u.r.opaque  = false;                                                            \
405
6
        dt->shared->u.atomic.u.r.version = 0;                                                                \
406
6
    }
407
408
#define H5T_INIT_TYPE_REGREF_CORE                                                                            \
409
6
    {                                                                                                        \
410
6
        H5T_INIT_TYPE_REF_COMMON                                                                             \
411
6
        dt->shared->u.atomic.u.r.rtype   = H5R_DATASET_REGION1;                                              \
412
6
        dt->shared->u.atomic.u.r.opaque  = false;                                                            \
413
6
        dt->shared->u.atomic.u.r.version = 0;                                                                \
414
6
    }
415
416
/* rtype value is only used as a placeholder to differentiate the type from
417
 * other types, any opaque (i.e. "new") reference type could be used.
418
 */
419
#define H5T_INIT_TYPE_REF_CORE                                                                               \
420
6
    {                                                                                                        \
421
6
        H5T_INIT_TYPE_REF_COMMON                                                                             \
422
6
        dt->shared->u.atomic.u.r.rtype   = H5R_OBJECT2;                                                      \
423
6
        dt->shared->u.atomic.u.r.opaque  = true;                                                             \
424
6
        dt->shared->u.atomic.u.r.version = H5R_ENCODE_VERSION;                                               \
425
6
        dt->shared->version              = H5O_DTYPE_VERSION_4;                                              \
426
6
    }
427
428
/* Define the code templates for the "SIZE_TMPL" in the H5T_INIT_TYPE macro */
429
#define H5T_INIT_TYPE_SET_SIZE(SIZE)                                                                         \
430
258
    {                                                                                                        \
431
258
        dt->shared->size          = SIZE;                                                                    \
432
258
        dt->shared->u.atomic.prec = 8 * (SIZE);                                                              \
433
258
    }
434
435
#define H5T_INIT_TYPE_NOSET_SIZE(SIZE)                                                                       \
436
90
    {                                                                                                        \
437
90
    }
438
439
/* Define the code templates for the "CRT_TMPL" in the H5T_INIT_TYPE macro */
440
#define H5T_INIT_TYPE_COPY_CREATE(BASE)                                                                      \
441
312
    {                                                                                                        \
442
312
        /* Base off of existing datatype */                                                                  \
443
312
        if (NULL == (dt = H5T_copy(BASE, H5T_COPY_TRANSIENT)))                                               \
444
312
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "duplicating base type failed");                   \
445
312
    }
446
447
#define H5T_INIT_TYPE_ALLOC_CREATE(BASE)                                                                     \
448
36
    {                                                                                                        \
449
36
        /* Allocate new datatype info */                                                                     \
450
36
        if (NULL == (dt = H5T__alloc()))                                                                     \
451
36
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "memory allocation failed");                      \
452
36
    }
453
454
#define H5T_INIT_TYPE(GUTS, GLOBAL, CRT_TMPL, BASE, SIZE_TMPL, SIZE)                                         \
455
348
    {                                                                                                        \
456
348
        /* Get new datatype struct */                                                                        \
457
348
        H5_GLUE3(H5T_INIT_TYPE_, CRT_TMPL, _CREATE)                                                          \
458
348
        (BASE)                                                                                               \
459
348
                                                                                                             \
460
348
            /* Adjust information for all types */                                                           \
461
348
            dt->shared->state = H5T_STATE_IMMUTABLE;                                                         \
462
348
        H5_GLUE3(H5T_INIT_TYPE_, SIZE_TMPL, _SIZE)                                                           \
463
348
        (SIZE)                                                                                               \
464
348
                                                                                                             \
465
348
            /* Adjust information for this type */                                                           \
466
348
            H5_GLUE3(H5T_INIT_TYPE_, GUTS, _CORE)                                                            \
467
348
                                                                                                             \
468
348
            /* Register result */                                                                            \
469
348
            if (((GLOBAL) = H5I_register(H5I_DATATYPE, dt, false)) < 0)                                      \
470
348
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register datatype atom");       \
471
348
    }
472
473
/******************/
474
/* Local Typedefs */
475
/******************/
476
477
/* Typedef for recursive const-correct datatype copying routines */
478
typedef H5T_t *(*H5T_copy_func_t)(H5T_t *old_dt);
479
480
/********************/
481
/* Local Prototypes */
482
/********************/
483
static herr_t H5T__register_int(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst,
484
                                H5T_lib_conv_t func);
485
static herr_t H5T__register(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_conv_func_t *conv);
486
static htri_t H5T__compiler_conv(H5T_t *src, H5T_t *dst);
487
static herr_t H5T__set_size(H5T_t *dt, size_t size);
488
static herr_t H5T__close_cb(void *dt, void **request);
489
static herr_t H5T__init_path_table(void);
490
static bool   H5T__path_table_search(const H5T_t *src, const H5T_t *dst, int *idx, int *last_cmp);
491
static H5T_path_t *H5T__path_find_real(const H5T_t *src, const H5T_t *dst, const char *name,
492
                                       H5T_conv_func_t *conv);
493
static herr_t      H5T__path_find_init_new_path(H5T_path_t *path, const H5T_t *src, const H5T_t *dst,
494
                                                H5T_conv_func_t *conv, H5T_conv_ctx_t *conv_ctx);
495
static herr_t      H5T__path_free(H5T_path_t *path, H5T_conv_ctx_t *conv_ctx);
496
static bool        H5T_path_match(H5T_path_t *path, H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst,
497
                                  H5VL_object_t *owned_vol_obj, H5T_conv_t func);
498
static bool   H5T_path_match_find_type_with_volobj(const H5T_t *datatype, const H5VL_object_t *owned_vol_obj);
499
static bool   H5T__detect_vlen_ref(const H5T_t *dt);
500
static H5T_t *H5T__initiate_copy(const H5T_t *old_dt);
501
static H5T_t *H5T__copy_transient(H5T_t *old_dt);
502
static H5T_t *H5T__copy_all(H5T_t *old_dt);
503
static herr_t H5T__complete_copy(H5T_t *new_dt, const H5T_t *old_dt, H5T_shared_t *reopened_fo,
504
                                 bool set_memory_type, H5T_copy_func_t copyfn);
505
506
/*****************************/
507
/* Library Private Variables */
508
/*****************************/
509
510
/* The native endianness of the platform */
511
H5T_order_t H5T_native_order_g = H5T_ORDER_ERROR;
512
513
/*********************/
514
/* Package Variables */
515
/*********************/
516
517
/* Package initialization variable */
518
bool H5_PKG_INIT_VAR = false;
519
520
/*
521
 * Predefined data types. These are initialized at runtime by H5T__init_package().
522
 *
523
 * If more of these are added, the new ones must be added to the list of
524
 * types to reset in H5T_term_package().
525
 */
526
hid_t H5T_IEEE_F16BE_g = H5I_INVALID_HID;
527
hid_t H5T_IEEE_F16LE_g = H5I_INVALID_HID;
528
hid_t H5T_IEEE_F32BE_g = H5I_INVALID_HID;
529
hid_t H5T_IEEE_F32LE_g = H5I_INVALID_HID;
530
hid_t H5T_IEEE_F64BE_g = H5I_INVALID_HID;
531
hid_t H5T_IEEE_F64LE_g = H5I_INVALID_HID;
532
533
hid_t H5T_FLOAT_BFLOAT16BE_g = H5I_INVALID_HID;
534
hid_t H5T_FLOAT_BFLOAT16LE_g = H5I_INVALID_HID;
535
hid_t H5T_FLOAT_F8E4M3_g     = H5I_INVALID_HID;
536
hid_t H5T_FLOAT_F8E5M2_g     = H5I_INVALID_HID;
537
hid_t H5T_FLOAT_F6E2M3_g     = H5I_INVALID_HID;
538
hid_t H5T_FLOAT_F6E3M2_g     = H5I_INVALID_HID;
539
hid_t H5T_FLOAT_F4E2M1_g     = H5I_INVALID_HID;
540
541
hid_t H5T_COMPLEX_IEEE_F16BE_g = H5I_INVALID_HID;
542
hid_t H5T_COMPLEX_IEEE_F16LE_g = H5I_INVALID_HID;
543
hid_t H5T_COMPLEX_IEEE_F32BE_g = H5I_INVALID_HID;
544
hid_t H5T_COMPLEX_IEEE_F32LE_g = H5I_INVALID_HID;
545
hid_t H5T_COMPLEX_IEEE_F64BE_g = H5I_INVALID_HID;
546
hid_t H5T_COMPLEX_IEEE_F64LE_g = H5I_INVALID_HID;
547
548
hid_t H5T_VAX_F32_g = H5I_INVALID_HID;
549
hid_t H5T_VAX_F64_g = H5I_INVALID_HID;
550
551
hid_t H5T_STD_I8BE_g        = H5I_INVALID_HID;
552
hid_t H5T_STD_I8LE_g        = H5I_INVALID_HID;
553
hid_t H5T_STD_I16BE_g       = H5I_INVALID_HID;
554
hid_t H5T_STD_I16LE_g       = H5I_INVALID_HID;
555
hid_t H5T_STD_I32BE_g       = H5I_INVALID_HID;
556
hid_t H5T_STD_I32LE_g       = H5I_INVALID_HID;
557
hid_t H5T_STD_I64BE_g       = H5I_INVALID_HID;
558
hid_t H5T_STD_I64LE_g       = H5I_INVALID_HID;
559
hid_t H5T_STD_U8BE_g        = H5I_INVALID_HID;
560
hid_t H5T_STD_U8LE_g        = H5I_INVALID_HID;
561
hid_t H5T_STD_U16BE_g       = H5I_INVALID_HID;
562
hid_t H5T_STD_U16LE_g       = H5I_INVALID_HID;
563
hid_t H5T_STD_U32BE_g       = H5I_INVALID_HID;
564
hid_t H5T_STD_U32LE_g       = H5I_INVALID_HID;
565
hid_t H5T_STD_U64BE_g       = H5I_INVALID_HID;
566
hid_t H5T_STD_U64LE_g       = H5I_INVALID_HID;
567
hid_t H5T_STD_B8BE_g        = H5I_INVALID_HID;
568
hid_t H5T_STD_B8LE_g        = H5I_INVALID_HID;
569
hid_t H5T_STD_B16BE_g       = H5I_INVALID_HID;
570
hid_t H5T_STD_B16LE_g       = H5I_INVALID_HID;
571
hid_t H5T_STD_B32BE_g       = H5I_INVALID_HID;
572
hid_t H5T_STD_B32LE_g       = H5I_INVALID_HID;
573
hid_t H5T_STD_B64BE_g       = H5I_INVALID_HID;
574
hid_t H5T_STD_B64LE_g       = H5I_INVALID_HID;
575
hid_t H5T_STD_REF_OBJ_g     = H5I_INVALID_HID;
576
hid_t H5T_STD_REF_DSETREG_g = H5I_INVALID_HID;
577
hid_t H5T_STD_REF_g         = H5I_INVALID_HID;
578
579
hid_t H5T_UNIX_D32BE_g = H5I_INVALID_HID;
580
hid_t H5T_UNIX_D32LE_g = H5I_INVALID_HID;
581
hid_t H5T_UNIX_D64BE_g = H5I_INVALID_HID;
582
hid_t H5T_UNIX_D64LE_g = H5I_INVALID_HID;
583
584
hid_t H5T_C_S1_g = H5I_INVALID_HID;
585
586
hid_t H5T_FORTRAN_S1_g = H5I_INVALID_HID;
587
588
hid_t H5T_NATIVE_SCHAR_g           = H5I_INVALID_HID;
589
hid_t H5T_NATIVE_UCHAR_g           = H5I_INVALID_HID;
590
hid_t H5T_NATIVE_SHORT_g           = H5I_INVALID_HID;
591
hid_t H5T_NATIVE_USHORT_g          = H5I_INVALID_HID;
592
hid_t H5T_NATIVE_INT_g             = H5I_INVALID_HID;
593
hid_t H5T_NATIVE_UINT_g            = H5I_INVALID_HID;
594
hid_t H5T_NATIVE_LONG_g            = H5I_INVALID_HID;
595
hid_t H5T_NATIVE_ULONG_g           = H5I_INVALID_HID;
596
hid_t H5T_NATIVE_LLONG_g           = H5I_INVALID_HID;
597
hid_t H5T_NATIVE_ULLONG_g          = H5I_INVALID_HID;
598
hid_t H5T_NATIVE_FLOAT16_g         = H5I_INVALID_HID;
599
hid_t H5T_NATIVE_FLOAT_g           = H5I_INVALID_HID;
600
hid_t H5T_NATIVE_DOUBLE_g          = H5I_INVALID_HID;
601
hid_t H5T_NATIVE_LDOUBLE_g         = H5I_INVALID_HID;
602
hid_t H5T_NATIVE_FLOAT_COMPLEX_g   = H5I_INVALID_HID;
603
hid_t H5T_NATIVE_DOUBLE_COMPLEX_g  = H5I_INVALID_HID;
604
hid_t H5T_NATIVE_LDOUBLE_COMPLEX_g = H5I_INVALID_HID;
605
hid_t H5T_NATIVE_B8_g              = H5I_INVALID_HID;
606
hid_t H5T_NATIVE_B16_g             = H5I_INVALID_HID;
607
hid_t H5T_NATIVE_B32_g             = H5I_INVALID_HID;
608
hid_t H5T_NATIVE_B64_g             = H5I_INVALID_HID;
609
hid_t H5T_NATIVE_OPAQUE_g          = H5I_INVALID_HID;
610
hid_t H5T_NATIVE_HADDR_g           = H5I_INVALID_HID;
611
hid_t H5T_NATIVE_HSIZE_g           = H5I_INVALID_HID;
612
hid_t H5T_NATIVE_HSSIZE_g          = H5I_INVALID_HID;
613
hid_t H5T_NATIVE_HERR_g            = H5I_INVALID_HID;
614
hid_t H5T_NATIVE_HBOOL_g           = H5I_INVALID_HID;
615
616
hid_t H5T_NATIVE_INT8_g        = H5I_INVALID_HID;
617
hid_t H5T_NATIVE_UINT8_g       = H5I_INVALID_HID;
618
hid_t H5T_NATIVE_INT_LEAST8_g  = H5I_INVALID_HID;
619
hid_t H5T_NATIVE_UINT_LEAST8_g = H5I_INVALID_HID;
620
hid_t H5T_NATIVE_INT_FAST8_g   = H5I_INVALID_HID;
621
hid_t H5T_NATIVE_UINT_FAST8_g  = H5I_INVALID_HID;
622
623
hid_t H5T_NATIVE_INT16_g        = H5I_INVALID_HID;
624
hid_t H5T_NATIVE_UINT16_g       = H5I_INVALID_HID;
625
hid_t H5T_NATIVE_INT_LEAST16_g  = H5I_INVALID_HID;
626
hid_t H5T_NATIVE_UINT_LEAST16_g = H5I_INVALID_HID;
627
hid_t H5T_NATIVE_INT_FAST16_g   = H5I_INVALID_HID;
628
hid_t H5T_NATIVE_UINT_FAST16_g  = H5I_INVALID_HID;
629
630
hid_t H5T_NATIVE_INT32_g        = H5I_INVALID_HID;
631
hid_t H5T_NATIVE_UINT32_g       = H5I_INVALID_HID;
632
hid_t H5T_NATIVE_INT_LEAST32_g  = H5I_INVALID_HID;
633
hid_t H5T_NATIVE_UINT_LEAST32_g = H5I_INVALID_HID;
634
hid_t H5T_NATIVE_INT_FAST32_g   = H5I_INVALID_HID;
635
hid_t H5T_NATIVE_UINT_FAST32_g  = H5I_INVALID_HID;
636
637
hid_t H5T_NATIVE_INT64_g        = H5I_INVALID_HID;
638
hid_t H5T_NATIVE_UINT64_g       = H5I_INVALID_HID;
639
hid_t H5T_NATIVE_INT_LEAST64_g  = H5I_INVALID_HID;
640
hid_t H5T_NATIVE_UINT_LEAST64_g = H5I_INVALID_HID;
641
hid_t H5T_NATIVE_INT_FAST64_g   = H5I_INVALID_HID;
642
hid_t H5T_NATIVE_UINT_FAST64_g  = H5I_INVALID_HID;
643
644
/*
645
 * Alignment constraints for HDF5 types.  Accessing objects of these
646
 * types with improper alignment invokes C undefined behavior, so the
647
 * library lays out objects with correct alignment, always.
648
 *
649
 * A value of N indicates that the data must be aligned on an address
650
 * ADDR such that 0 == ADDR mod N. When N=1 no alignment is required;
651
 * N=0 implies that alignment constraints were not calculated.  These
652
 * values are used for structure alignment.
653
 */
654
size_t H5T_POINTER_ALIGN_g     = 0;
655
size_t H5T_HVL_ALIGN_g         = 0;
656
size_t H5T_HOBJREF_ALIGN_g     = 0;
657
size_t H5T_HDSETREGREF_ALIGN_g = 0;
658
size_t H5T_REF_ALIGN_g         = 0;
659
660
size_t H5T_NATIVE_SCHAR_ALIGN_g           = 0;
661
size_t H5T_NATIVE_UCHAR_ALIGN_g           = 0;
662
size_t H5T_NATIVE_SHORT_ALIGN_g           = 0;
663
size_t H5T_NATIVE_USHORT_ALIGN_g          = 0;
664
size_t H5T_NATIVE_INT_ALIGN_g             = 0;
665
size_t H5T_NATIVE_UINT_ALIGN_g            = 0;
666
size_t H5T_NATIVE_LONG_ALIGN_g            = 0;
667
size_t H5T_NATIVE_ULONG_ALIGN_g           = 0;
668
size_t H5T_NATIVE_LLONG_ALIGN_g           = 0;
669
size_t H5T_NATIVE_ULLONG_ALIGN_g          = 0;
670
size_t H5T_NATIVE_FLOAT16_ALIGN_g         = 0;
671
size_t H5T_NATIVE_FLOAT_ALIGN_g           = 0;
672
size_t H5T_NATIVE_DOUBLE_ALIGN_g          = 0;
673
size_t H5T_NATIVE_LDOUBLE_ALIGN_g         = 0;
674
size_t H5T_NATIVE_FLOAT_COMPLEX_ALIGN_g   = 0;
675
size_t H5T_NATIVE_DOUBLE_COMPLEX_ALIGN_g  = 0;
676
size_t H5T_NATIVE_LDOUBLE_COMPLEX_ALIGN_g = 0;
677
678
/* Alignment constraints for C99 types */
679
size_t H5T_NATIVE_INT8_ALIGN_g        = 0;
680
size_t H5T_NATIVE_UINT8_ALIGN_g       = 0;
681
size_t H5T_NATIVE_INT_LEAST8_ALIGN_g  = 0;
682
size_t H5T_NATIVE_UINT_LEAST8_ALIGN_g = 0;
683
size_t H5T_NATIVE_INT_FAST8_ALIGN_g   = 0;
684
size_t H5T_NATIVE_UINT_FAST8_ALIGN_g  = 0;
685
686
size_t H5T_NATIVE_INT16_ALIGN_g        = 0;
687
size_t H5T_NATIVE_UINT16_ALIGN_g       = 0;
688
size_t H5T_NATIVE_INT_LEAST16_ALIGN_g  = 0;
689
size_t H5T_NATIVE_UINT_LEAST16_ALIGN_g = 0;
690
size_t H5T_NATIVE_INT_FAST16_ALIGN_g   = 0;
691
size_t H5T_NATIVE_UINT_FAST16_ALIGN_g  = 0;
692
693
size_t H5T_NATIVE_INT32_ALIGN_g        = 0;
694
size_t H5T_NATIVE_UINT32_ALIGN_g       = 0;
695
size_t H5T_NATIVE_INT_LEAST32_ALIGN_g  = 0;
696
size_t H5T_NATIVE_UINT_LEAST32_ALIGN_g = 0;
697
size_t H5T_NATIVE_INT_FAST32_ALIGN_g   = 0;
698
size_t H5T_NATIVE_UINT_FAST32_ALIGN_g  = 0;
699
700
size_t H5T_NATIVE_INT64_ALIGN_g        = 0;
701
size_t H5T_NATIVE_UINT64_ALIGN_g       = 0;
702
size_t H5T_NATIVE_INT_LEAST64_ALIGN_g  = 0;
703
size_t H5T_NATIVE_UINT_LEAST64_ALIGN_g = 0;
704
size_t H5T_NATIVE_INT_FAST64_ALIGN_g   = 0;
705
size_t H5T_NATIVE_UINT_FAST64_ALIGN_g  = 0;
706
707
/* Useful floating-point values for conversion routines */
708
/* (+/- Inf for all floating-point types) */
709
#ifdef H5_HAVE__FLOAT16
710
/* Initialize these with a float literal since the f16 suffix
711
 * is non-standard C and gives warnings when compiling the
712
 * library with the -pedantic flag. These values will be
713
 * overwritten anyway.
714
 */
715
H5__Float16 H5T_NATIVE_FLOAT16_POS_INF_g = 0.0f;
716
H5__Float16 H5T_NATIVE_FLOAT16_NEG_INF_g = 0.0f;
717
#endif
718
float       H5T_NATIVE_FLOAT_POS_INF_g   = 0.0F;
719
float       H5T_NATIVE_FLOAT_NEG_INF_g   = 0.0F;
720
double      H5T_NATIVE_DOUBLE_POS_INF_g  = 0.0;
721
double      H5T_NATIVE_DOUBLE_NEG_INF_g  = 0.0;
722
long double H5T_NATIVE_LDOUBLE_POS_INF_g = 0.0L;
723
long double H5T_NATIVE_LDOUBLE_NEG_INF_g = 0.0L;
724
#ifdef H5_HAVE_COMPLEX_NUMBERS
725
H5_float_complex   H5T_NATIVE_FLOAT_COMPLEX_POS_INF_g;
726
H5_float_complex   H5T_NATIVE_FLOAT_COMPLEX_NEG_INF_g;
727
H5_double_complex  H5T_NATIVE_DOUBLE_COMPLEX_POS_INF_g;
728
H5_double_complex  H5T_NATIVE_DOUBLE_COMPLEX_NEG_INF_g;
729
H5_ldouble_complex H5T_NATIVE_LDOUBLE_COMPLEX_POS_INF_g;
730
H5_ldouble_complex H5T_NATIVE_LDOUBLE_COMPLEX_NEG_INF_g;
731
#endif
732
733
/* Declare the free list for H5T_t's and H5T_shared_t's */
734
H5FL_DEFINE(H5T_t);
735
H5FL_DEFINE(H5T_shared_t);
736
737
/* Format version bounds for datatype */
738
const unsigned H5O_dtype_ver_bounds[] = {
739
    H5O_DTYPE_VERSION_1,     /* H5F_LIBVER_EARLIEST */
740
    H5O_DTYPE_VERSION_3,     /* H5F_LIBVER_V18 */
741
    H5O_DTYPE_VERSION_3,     /* H5F_LIBVER_V110 */
742
    H5O_DTYPE_VERSION_4,     /* H5F_LIBVER_V112 */
743
    H5O_DTYPE_VERSION_4,     /* H5F_LIBVER_V114 */
744
    H5O_DTYPE_VERSION_5,     /* H5F_LIBVER_V200 */
745
    H5O_DTYPE_VERSION_LATEST /* H5F_LIBVER_LATEST */
746
};
747
748
/*******************/
749
/* Local Variables */
750
/*******************/
751
752
/*
753
 * The path database. Each path has a source and destination data type pair
754
 * which is used as the key by which the `entries' array is sorted.
755
 */
756
static struct {
757
    int          npaths; /*number of paths defined               */
758
    size_t       apaths; /*number of paths allocated             */
759
    H5T_path_t **path;   /*sorted array of path pointers         */
760
    int          nsoft;  /*number of soft conversions defined    */
761
    size_t       asoft;  /*number of soft conversions allocated  */
762
    H5T_soft_t  *soft;   /*unsorted array of soft conversions    */
763
} H5T_g;
764
765
/* Declare the free list for H5T_path_t's */
766
H5FL_DEFINE_STATIC(H5T_path_t);
767
768
/* Datatype ID class */
769
static const H5I_class_t H5I_DATATYPE_CLS[1] = {{
770
    H5I_DATATYPE, /* ID class value */
771
    0,            /* Class flags    */
772
    8,            /* # of reserved IDs for class */
773
    H5T__close_cb /* Callback routine for closing objects of this class */
774
}};
775
776
/* Flag indicating "top" of interface has been initialized */
777
static bool H5T_top_package_initialize_s = false;
778
779
/*-------------------------------------------------------------------------
780
 * Function:    H5T_init
781
 *
782
 * Purpose:    Initialize the interface from some other package.
783
 *
784
 * Return:    Success:    non-negative
785
 *            Failure:    negative
786
 *
787
 * Programmer:    Robb Matzke
788
 *              Wednesday, December 16, 1998
789
 *
790
 *-------------------------------------------------------------------------
791
 */
792
herr_t
793
H5T_init(void)
794
12
{
795
12
    herr_t ret_value = SUCCEED; /* Return value */
796
797
12
    FUNC_ENTER_NOAPI(FAIL)
798
    /* FUNC_ENTER() does all the work */
799
800
12
done:
801
12
    FUNC_LEAVE_NOAPI(ret_value)
802
12
} /* end H5T_init() */
803
804
/*-------------------------------------------------------------------------
805
 * Function:    H5T__init_inf
806
 *
807
 * Purpose:    Initialize the +/- Infinity floating-poing values for type
808
 *              conversion.
809
 *
810
 * Return:    Success:    non-negative
811
 *            Failure:    negative
812
 *
813
 *-------------------------------------------------------------------------
814
 */
815
static herr_t
816
H5T__init_inf(void)
817
6
{
818
6
    H5T_t        *dst_p;               /* Datatype type operate on */
819
6
    H5T_atomic_t *dst;                 /* Datatype's atomic info   */
820
6
    uint8_t      *d;                   /* Pointer to value to set  */
821
6
    size_t        half_size;           /* Half the type size       */
822
6
    size_t        u;                   /* Local index value        */
823
6
    herr_t        ret_value = SUCCEED; /* Return value             */
824
825
6
    FUNC_ENTER_PACKAGE
826
827
    /* Get the float datatype */
828
6
    if (NULL == (dst_p = (H5T_t *)H5I_object(H5T_NATIVE_FLOAT_g)))
829
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
830
6
    dst = &dst_p->shared->u.atomic;
831
832
    /* Check that we can re-order the bytes correctly */
833
6
    if (H5T_ORDER_LE != H5T_native_order_g && H5T_ORDER_BE != H5T_native_order_g)
834
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
835
836
    /* +Inf */
837
6
    d = (uint8_t *)&H5T_NATIVE_FLOAT_POS_INF_g;
838
6
    H5T__bit_set(d, dst->u.f.sign, (size_t)1, false);
839
6
    H5T__bit_set(d, dst->u.f.epos, dst->u.f.esize, true);
840
6
    H5T__bit_set(d, dst->u.f.mpos, dst->u.f.msize, false);
841
842
    /* Swap the bytes if the machine architecture is big-endian */
843
6
    if (H5T_ORDER_BE == H5T_native_order_g) {
844
0
        half_size = dst_p->shared->size / 2;
845
0
        for (u = 0; u < half_size; u++) {
846
0
            uint8_t tmp                      = d[dst_p->shared->size - (u + 1)];
847
0
            d[dst_p->shared->size - (u + 1)] = d[u];
848
0
            d[u]                             = tmp;
849
0
        } /* end for */
850
0
    }     /* end if */
851
852
    /* -Inf */
853
6
    d = (uint8_t *)&H5T_NATIVE_FLOAT_NEG_INF_g;
854
6
    H5T__bit_set(d, dst->u.f.sign, (size_t)1, true);
855
6
    H5T__bit_set(d, dst->u.f.epos, dst->u.f.esize, true);
856
6
    H5T__bit_set(d, dst->u.f.mpos, dst->u.f.msize, false);
857
858
    /* Swap the bytes if the machine architecture is big-endian */
859
6
    if (H5T_ORDER_BE == H5T_native_order_g) {
860
0
        half_size = dst_p->shared->size / 2;
861
0
        for (u = 0; u < half_size; u++) {
862
0
            uint8_t tmp                      = d[dst_p->shared->size - (u + 1)];
863
0
            d[dst_p->shared->size - (u + 1)] = d[u];
864
0
            d[u]                             = tmp;
865
0
        } /* end for */
866
0
    }     /* end if */
867
868
    /* Get the double datatype */
869
6
    if (NULL == (dst_p = (H5T_t *)H5I_object(H5T_NATIVE_DOUBLE_g)))
870
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
871
6
    dst = &dst_p->shared->u.atomic;
872
873
    /* Check that we can re-order the bytes correctly */
874
6
    if (H5T_ORDER_LE != H5T_native_order_g && H5T_ORDER_BE != H5T_native_order_g)
875
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
876
877
    /* +Inf */
878
6
    d = (uint8_t *)&H5T_NATIVE_DOUBLE_POS_INF_g;
879
6
    H5T__bit_set(d, dst->u.f.sign, (size_t)1, false);
880
6
    H5T__bit_set(d, dst->u.f.epos, dst->u.f.esize, true);
881
6
    H5T__bit_set(d, dst->u.f.mpos, dst->u.f.msize, false);
882
883
    /* Swap the bytes if the machine architecture is big-endian */
884
6
    if (H5T_ORDER_BE == H5T_native_order_g) {
885
0
        half_size = dst_p->shared->size / 2;
886
0
        for (u = 0; u < half_size; u++) {
887
0
            uint8_t tmp                      = d[dst_p->shared->size - (u + 1)];
888
0
            d[dst_p->shared->size - (u + 1)] = d[u];
889
0
            d[u]                             = tmp;
890
0
        } /* end for */
891
0
    }     /* end if */
892
893
    /* -Inf */
894
6
    d = (uint8_t *)&H5T_NATIVE_DOUBLE_NEG_INF_g;
895
6
    H5T__bit_set(d, dst->u.f.sign, (size_t)1, true);
896
6
    H5T__bit_set(d, dst->u.f.epos, dst->u.f.esize, true);
897
6
    H5T__bit_set(d, dst->u.f.mpos, dst->u.f.msize, false);
898
899
    /* Swap the bytes if the machine architecture is big-endian */
900
6
    if (H5T_ORDER_BE == H5T_native_order_g) {
901
0
        half_size = dst_p->shared->size / 2;
902
0
        for (u = 0; u < half_size; u++) {
903
0
            uint8_t tmp                      = d[dst_p->shared->size - (u + 1)];
904
0
            d[dst_p->shared->size - (u + 1)] = d[u];
905
0
            d[u]                             = tmp;
906
0
        } /* end for */
907
0
    }     /* end if */
908
909
    /* Get the long double datatype */
910
6
    if (NULL == (dst_p = (H5T_t *)H5I_object(H5T_NATIVE_LDOUBLE_g)))
911
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
912
6
    dst = &dst_p->shared->u.atomic;
913
914
    /* Check that we can re-order the bytes correctly */
915
6
    if (H5T_ORDER_LE != H5T_native_order_g && H5T_ORDER_BE != H5T_native_order_g)
916
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
917
918
    /* +Inf */
919
6
    d = (uint8_t *)&H5T_NATIVE_LDOUBLE_POS_INF_g;
920
6
    H5T__bit_set(d, dst->u.f.sign, (size_t)1, false);
921
6
    H5T__bit_set(d, dst->u.f.epos, dst->u.f.esize, true);
922
6
    H5T__bit_set(d, dst->u.f.mpos, dst->u.f.msize, false);
923
924
    /* Swap the bytes if the machine architecture is big-endian */
925
6
    if (H5T_ORDER_BE == H5T_native_order_g) {
926
0
        half_size = dst_p->shared->size / 2;
927
0
        for (u = 0; u < half_size; u++) {
928
0
            uint8_t tmp                      = d[dst_p->shared->size - (u + 1)];
929
0
            d[dst_p->shared->size - (u + 1)] = d[u];
930
0
            d[u]                             = tmp;
931
0
        } /* end for */
932
0
    }     /* end if */
933
934
    /* -Inf */
935
6
    d = (uint8_t *)&H5T_NATIVE_LDOUBLE_NEG_INF_g;
936
6
    H5T__bit_set(d, dst->u.f.sign, (size_t)1, true);
937
6
    H5T__bit_set(d, dst->u.f.epos, dst->u.f.esize, true);
938
6
    H5T__bit_set(d, dst->u.f.mpos, dst->u.f.msize, false);
939
940
    /* Swap the bytes if the machine architecture is big-endian */
941
6
    if (H5T_ORDER_BE == H5T_native_order_g) {
942
0
        half_size = dst_p->shared->size / 2;
943
0
        for (u = 0; u < half_size; u++) {
944
0
            uint8_t tmp                      = d[dst_p->shared->size - (u + 1)];
945
0
            d[dst_p->shared->size - (u + 1)] = d[u];
946
0
            d[u]                             = tmp;
947
0
        } /* end for */
948
0
    }     /* end if */
949
950
#ifdef H5_HAVE__FLOAT16
951
    /* Get the _Float16 datatype */
952
    if (NULL == (dst_p = (H5T_t *)H5I_object(H5T_NATIVE_FLOAT16_g)))
953
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
954
    dst = &dst_p->shared->u.atomic;
955
956
    /* Check that we can re-order the bytes correctly */
957
    if (H5T_ORDER_LE != H5T_native_order_g && H5T_ORDER_BE != H5T_native_order_g)
958
        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
959
960
    /* +Inf */
961
    d = (uint8_t *)&H5T_NATIVE_FLOAT16_POS_INF_g;
962
    H5T__bit_set(d, dst->u.f.sign, (size_t)1, false);
963
    H5T__bit_set(d, dst->u.f.epos, dst->u.f.esize, true);
964
    H5T__bit_set(d, dst->u.f.mpos, dst->u.f.msize, false);
965
966
    /* Swap the bytes if the machine architecture is big-endian */
967
    if (H5T_ORDER_BE == H5T_native_order_g) {
968
        half_size = dst_p->shared->size / 2;
969
        for (u = 0; u < half_size; u++) {
970
            uint8_t tmp                      = d[dst_p->shared->size - (u + 1)];
971
            d[dst_p->shared->size - (u + 1)] = d[u];
972
            d[u]                             = tmp;
973
        } /* end for */
974
    }     /* end if */
975
976
    /* -Inf */
977
    d = (uint8_t *)&H5T_NATIVE_FLOAT16_NEG_INF_g;
978
    H5T__bit_set(d, dst->u.f.sign, (size_t)1, true);
979
    H5T__bit_set(d, dst->u.f.epos, dst->u.f.esize, true);
980
    H5T__bit_set(d, dst->u.f.mpos, dst->u.f.msize, false);
981
982
    /* Swap the bytes if the machine architecture is big-endian */
983
    if (H5T_ORDER_BE == H5T_native_order_g) {
984
        half_size = dst_p->shared->size / 2;
985
        for (u = 0; u < half_size; u++) {
986
            uint8_t tmp                      = d[dst_p->shared->size - (u + 1)];
987
            d[dst_p->shared->size - (u + 1)] = d[u];
988
            d[u]                             = tmp;
989
        } /* end for */
990
    }     /* end if */
991
#endif
992
993
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
994
    /*
995
     * A complex number is considered to be infinite if any of its parts
996
     * (real or imaginary) is infinite, so simply set the real part of
997
     * the complex number positive/negative infinity values to the
998
     * positive/negative infinity value for the base floating-point type.
999
     * The imaginary part should be zeroed-out bits.
1000
     */
1001
6
    memcpy(&H5T_NATIVE_FLOAT_COMPLEX_POS_INF_g, &H5T_NATIVE_FLOAT_POS_INF_g, sizeof(float));
1002
6
    memcpy(&H5T_NATIVE_FLOAT_COMPLEX_NEG_INF_g, &H5T_NATIVE_FLOAT_NEG_INF_g, sizeof(float));
1003
6
    memcpy(&H5T_NATIVE_DOUBLE_COMPLEX_POS_INF_g, &H5T_NATIVE_DOUBLE_POS_INF_g, sizeof(double));
1004
6
    memcpy(&H5T_NATIVE_DOUBLE_COMPLEX_NEG_INF_g, &H5T_NATIVE_DOUBLE_NEG_INF_g, sizeof(double));
1005
6
    memcpy(&H5T_NATIVE_LDOUBLE_COMPLEX_POS_INF_g, &H5T_NATIVE_LDOUBLE_POS_INF_g, sizeof(long double));
1006
6
    memcpy(&H5T_NATIVE_LDOUBLE_COMPLEX_NEG_INF_g, &H5T_NATIVE_LDOUBLE_NEG_INF_g, sizeof(long double));
1007
6
#endif
1008
1009
6
done:
1010
6
    FUNC_LEAVE_NOAPI(ret_value)
1011
6
} /* end H5T__init_inf() */
1012
1013
/*--------------------------------------------------------------------------
1014
NAME
1015
   H5T__init_package -- Initialize interface-specific information
1016
USAGE
1017
    herr__t H5T_init_package()
1018
RETURNS
1019
    Non-negative on success/Negative on failure
1020
DESCRIPTION
1021
    Initializes any interface-specific data or routines.
1022
--------------------------------------------------------------------------*/
1023
herr_t
1024
H5T__init_package(void)
1025
6
{
1026
6
    H5T_t  *native_schar   = NULL; /* Datatype structure for native signed char */
1027
6
    H5T_t  *native_uchar   = NULL; /* Datatype structure for native unsigned char */
1028
6
    H5T_t  *native_short   = NULL; /* Datatype structure for native short */
1029
6
    H5T_t  *native_ushort  = NULL; /* Datatype structure for native unsigned short */
1030
6
    H5T_t  *native_int     = NULL; /* Datatype structure for native int */
1031
6
    H5T_t  *native_uint    = NULL; /* Datatype structure for native unsigned int */
1032
6
    H5T_t  *native_long    = NULL; /* Datatype structure for native long */
1033
6
    H5T_t  *native_ulong   = NULL; /* Datatype structure for native unsigned long */
1034
6
    H5T_t  *native_llong   = NULL; /* Datatype structure for native long long */
1035
6
    H5T_t  *native_ullong  = NULL; /* Datatype structure for native unsigned long long */
1036
6
    H5T_t  *native_float   = NULL; /* Datatype structure for native float */
1037
6
    H5T_t  *native_double  = NULL; /* Datatype structure for native double */
1038
6
    H5T_t  *native_ldouble = NULL; /* Datatype structure for native long double */
1039
6
    H5T_t  *std_u8le       = NULL; /* Datatype structure for unsigned 8-bit little-endian integer */
1040
6
    H5T_t  *std_u8be       = NULL; /* Datatype structure for unsigned 8-bit big-endian integer */
1041
6
    H5T_t  *std_u16le      = NULL; /* Datatype structure for unsigned 16-bit little-endian integer */
1042
6
    H5T_t  *std_u16be      = NULL; /* Datatype structure for unsigned 16-bit big-endian integer */
1043
6
    H5T_t  *std_u32le      = NULL; /* Datatype structure for unsigned 32-bit little-endian integer */
1044
6
    H5T_t  *std_u32be      = NULL; /* Datatype structure for unsigned 32-bit big-endian integer */
1045
6
    H5T_t  *std_u64le      = NULL; /* Datatype structure for unsigned 64-bit little-endian integer */
1046
6
    H5T_t  *std_u64be      = NULL; /* Datatype structure for unsigned 64-bit big-endian integer */
1047
6
    H5T_t  *dt             = NULL;
1048
6
    H5T_t  *tmp_float      = NULL;
1049
6
    H5T_t  *fixedpt        = NULL; /* Datatype structure for native int */
1050
6
    H5T_t  *floatpt        = NULL; /* Datatype structure for native float */
1051
6
    H5T_t  *string         = NULL; /* Datatype structure for C string */
1052
6
    H5T_t  *bitfield       = NULL; /* Datatype structure for bitfield */
1053
6
    H5T_t  *compound       = NULL; /* Datatype structure for compound objects */
1054
6
    H5T_t  *enum_type      = NULL; /* Datatype structure for enum objects */
1055
6
    H5T_t  *vlen           = NULL; /* Datatype structure for vlen objects */
1056
6
    H5T_t  *array          = NULL; /* Datatype structure for array objects */
1057
6
    H5T_t  *cplx           = NULL; /* Datatype structure for complex number objects */
1058
6
    H5T_t  *objref         = NULL; /* Datatype structure for deprecated reference objects */
1059
6
    H5T_t  *regref         = NULL; /* Datatype structure for deprecated region references */
1060
6
    H5T_t  *ref            = NULL; /* Datatype structure for opaque references */
1061
6
    hsize_t dim[1]         = {1};  /* Dimension info for array datatype */
1062
6
    herr_t  status;
1063
6
    bool    copied_dtype =
1064
6
        true; /* Flag to indicate whether datatype was copied or allocated (for error cleanup) */
1065
#ifdef H5_HAVE__FLOAT16
1066
    H5T_t *native_float16 = NULL; /* Datatype structure for native _Float16 type */
1067
#endif
1068
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1069
6
    H5T_t *native_float_complex  = NULL; /* Datatype structure for native float _Complex / _Fcomplex type */
1070
6
    H5T_t *native_double_complex = NULL; /* Datatype structure for native double _Complex / _Dcomplex type */
1071
6
    H5T_t *native_ldouble_complex =
1072
6
        NULL; /* Datatype structure for native long double _Complex / _Lcomplex type */
1073
6
#endif
1074
6
    herr_t ret_value = SUCCEED; /* Return value */
1075
1076
6
    FUNC_ENTER_PACKAGE
1077
1078
    /* Initialize the ID group for the file IDs */
1079
6
    if (H5I_register_type(H5I_DATATYPE_CLS) < 0)
1080
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize interface");
1081
1082
    /* Make certain there aren't too many classes of datatypes defined */
1083
    /* Only 16 (numbered 0-15) are supported in the current file format */
1084
6
    HDcompile_assert(H5T_NCLASSES < 16);
1085
1086
    /* Initialize native floating-point datatypes */
1087
6
    if (H5T__init_native_float_types() < 0)
1088
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize floating-point types");
1089
1090
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1091
    /* Initialize native complex number datatypes */
1092
6
    if (H5T__init_native_complex_types() < 0)
1093
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize complex number types");
1094
6
#endif
1095
1096
    /* Initialize all other native types */
1097
6
    if (H5T__init_native_internal() < 0)
1098
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize integers");
1099
1100
    /* Get the atomic datatype structures needed by the initialization code below */
1101
6
    if (NULL == (native_schar = (H5T_t *)H5I_object(H5T_NATIVE_SCHAR_g)))
1102
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1103
6
    if (NULL == (native_uchar = (H5T_t *)H5I_object(H5T_NATIVE_UCHAR_g)))
1104
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1105
6
    if (NULL == (native_short = (H5T_t *)H5I_object(H5T_NATIVE_SHORT_g)))
1106
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1107
6
    if (NULL == (native_ushort = (H5T_t *)H5I_object(H5T_NATIVE_USHORT_g)))
1108
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1109
6
    if (NULL == (native_int = (H5T_t *)H5I_object(H5T_NATIVE_INT_g)))
1110
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1111
6
    if (NULL == (native_uint = (H5T_t *)H5I_object(H5T_NATIVE_UINT_g)))
1112
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1113
6
    if (NULL == (native_long = (H5T_t *)H5I_object(H5T_NATIVE_LONG_g)))
1114
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1115
6
    if (NULL == (native_ulong = (H5T_t *)H5I_object(H5T_NATIVE_ULONG_g)))
1116
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1117
6
    if (NULL == (native_llong = (H5T_t *)H5I_object(H5T_NATIVE_LLONG_g)))
1118
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1119
6
    if (NULL == (native_ullong = (H5T_t *)H5I_object(H5T_NATIVE_ULLONG_g)))
1120
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1121
#ifdef H5_HAVE__FLOAT16
1122
    if (NULL == (native_float16 = (H5T_t *)H5I_object(H5T_NATIVE_FLOAT16_g)))
1123
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1124
#endif
1125
6
    if (NULL == (native_float = (H5T_t *)H5I_object(H5T_NATIVE_FLOAT_g)))
1126
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1127
6
    if (NULL == (native_double = (H5T_t *)H5I_object(H5T_NATIVE_DOUBLE_g)))
1128
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1129
6
    if (NULL == (native_ldouble = (H5T_t *)H5I_object(H5T_NATIVE_LDOUBLE_g)))
1130
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1131
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1132
6
    if (NULL == (native_float_complex = (H5T_t *)H5I_object(H5T_NATIVE_FLOAT_COMPLEX_g)))
1133
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1134
6
    if (NULL == (native_double_complex = (H5T_t *)H5I_object(H5T_NATIVE_DOUBLE_COMPLEX_g)))
1135
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1136
6
    if (NULL == (native_ldouble_complex = (H5T_t *)H5I_object(H5T_NATIVE_LDOUBLE_COMPLEX_g)))
1137
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1138
6
#endif
1139
1140
    /*------------------------------------------------------------
1141
     * Derived native types
1142
     *------------------------------------------------------------
1143
     */
1144
1145
    /* 1-byte bit field */
1146
12
    H5T_INIT_TYPE(BITFIELD, H5T_NATIVE_B8_g, COPY, native_uint, SET, 1)
1147
1148
    /* 2-byte bit field */
1149
12
    H5T_INIT_TYPE(BITFIELD, H5T_NATIVE_B16_g, COPY, native_uint, SET, 2)
1150
1151
    /* 4-byte bit field */
1152
12
    H5T_INIT_TYPE(BITFIELD, H5T_NATIVE_B32_g, COPY, native_uint, SET, 4)
1153
1154
    /* 8-byte bit field */
1155
12
    H5T_INIT_TYPE(BITFIELD, H5T_NATIVE_B64_g, COPY, native_uint, SET, 8)
1156
1157
    /* haddr_t */
1158
12
    H5T_INIT_TYPE(OFFSET, H5T_NATIVE_HADDR_g, COPY, native_uint, SET, sizeof(haddr_t))
1159
1160
    /* hsize_t */
1161
12
    H5T_INIT_TYPE(OFFSET, H5T_NATIVE_HSIZE_g, COPY, native_uint, SET, sizeof(hsize_t))
1162
1163
    /* hssize_t */
1164
12
    H5T_INIT_TYPE(OFFSET, H5T_NATIVE_HSSIZE_g, COPY, native_int, SET, sizeof(hssize_t))
1165
1166
    /* herr_t */
1167
12
    H5T_INIT_TYPE(OFFSET, H5T_NATIVE_HERR_g, COPY, native_int, SET, sizeof(herr_t))
1168
1169
    /* bool */
1170
12
    H5T_INIT_TYPE(OFFSET, H5T_NATIVE_HBOOL_g, COPY, native_uint, SET, sizeof(bool))
1171
1172
    /*------------------------------------------------------------
1173
     * IEEE Types
1174
     *------------------------------------------------------------
1175
     */
1176
1177
    /* IEEE 2-byte little-endian float */
1178
12
    H5T_INIT_TYPE(FLOAT16LE, H5T_IEEE_F16LE_g, COPY, native_double, SET, 2)
1179
1180
    /* IEEE 2-byte big-endian float */
1181
12
    H5T_INIT_TYPE(FLOAT16BE, H5T_IEEE_F16BE_g, COPY, native_double, SET, 2)
1182
1183
    /* IEEE 4-byte little-endian float */
1184
12
    H5T_INIT_TYPE(FLOATLE, H5T_IEEE_F32LE_g, COPY, native_double, SET, 4)
1185
1186
    /* IEEE 4-byte big-endian float */
1187
12
    H5T_INIT_TYPE(FLOATBE, H5T_IEEE_F32BE_g, COPY, native_double, SET, 4)
1188
1189
    /* IEEE 8-byte little-endian float */
1190
12
    H5T_INIT_TYPE(DOUBLELE, H5T_IEEE_F64LE_g, COPY, native_double, SET, 8)
1191
1192
    /* IEEE 8-byte big-endian float */
1193
12
    H5T_INIT_TYPE(DOUBLEBE, H5T_IEEE_F64BE_g, COPY, native_double, SET, 8)
1194
1195
    /*------------------------------------------------------------
1196
     * Alternative floating-point types
1197
     *------------------------------------------------------------
1198
     */
1199
1200
    /* 2-byte little-endian bfloat16 float type */
1201
12
    H5T_INIT_TYPE(BFLOAT16LE, H5T_FLOAT_BFLOAT16LE_g, COPY, native_double, SET, 2)
1202
1203
    /* 2-byte big-endian bfloat16 float type */
1204
12
    H5T_INIT_TYPE(BFLOAT16BE, H5T_FLOAT_BFLOAT16BE_g, COPY, native_double, SET, 2)
1205
1206
    /* 8-bit FP8 E4M3 float type */
1207
12
    H5T_INIT_TYPE(FLOAT8E4M3, H5T_FLOAT_F8E4M3_g, COPY, native_double, SET, 1)
1208
1209
    /* 8-bit FP8 E5M2 float type */
1210
12
    H5T_INIT_TYPE(FLOAT8E5M2, H5T_FLOAT_F8E5M2_g, COPY, native_double, SET, 1)
1211
1212
    /* 6-bit FP6 E2M3 float type */
1213
12
    H5T_INIT_TYPE(FLOAT6E2M3, H5T_FLOAT_F6E2M3_g, COPY, native_double, SET, 1)
1214
1215
    /* 6-bit FP6 E3M2 float type */
1216
12
    H5T_INIT_TYPE(FLOAT6E3M2, H5T_FLOAT_F6E3M2_g, COPY, native_double, SET, 1)
1217
1218
    /* 4-bit FP4 E2M1 float type */
1219
12
    H5T_INIT_TYPE(FLOAT4E2M1, H5T_FLOAT_F4E2M1_g, COPY, native_double, SET, 1)
1220
1221
    /*------------------------------------------------------------
1222
     * VAX Types
1223
     *------------------------------------------------------------
1224
     */
1225
1226
    /* VAX 4-byte float */
1227
12
    H5T_INIT_TYPE(FLOATVAX, H5T_VAX_F32_g, COPY, native_double, SET, 4)
1228
1229
    /* VAX 8-byte double */
1230
12
    H5T_INIT_TYPE(DOUBLEVAX, H5T_VAX_F64_g, COPY, native_double, SET, 8)
1231
1232
    /*------------------------------------------------------------
1233
     * C99 types
1234
     *------------------------------------------------------------
1235
     */
1236
1237
    /* 1-byte little-endian (endianness is irrelevant) signed integer */
1238
12
    H5T_INIT_TYPE(SINTLE, H5T_STD_I8LE_g, COPY, native_int, SET, 1)
1239
1240
    /* 1-byte big-endian (endianness is irrelevant) signed integer */
1241
12
    H5T_INIT_TYPE(SINTBE, H5T_STD_I8BE_g, COPY, native_int, SET, 1)
1242
1243
    /* 2-byte little-endian signed integer */
1244
12
    H5T_INIT_TYPE(SINTLE, H5T_STD_I16LE_g, COPY, native_int, SET, 2)
1245
1246
    /* 2-byte big-endian signed integer */
1247
12
    H5T_INIT_TYPE(SINTBE, H5T_STD_I16BE_g, COPY, native_int, SET, 2)
1248
1249
    /* 4-byte little-endian signed integer */
1250
12
    H5T_INIT_TYPE(SINTLE, H5T_STD_I32LE_g, COPY, native_int, SET, 4)
1251
1252
    /* 4-byte big-endian signed integer */
1253
12
    H5T_INIT_TYPE(SINTBE, H5T_STD_I32BE_g, COPY, native_int, SET, 4)
1254
1255
    /* 8-byte little-endian signed integer */
1256
12
    H5T_INIT_TYPE(SINTLE, H5T_STD_I64LE_g, COPY, native_int, SET, 8)
1257
1258
    /* 8-byte big-endian signed integer */
1259
12
    H5T_INIT_TYPE(SINTBE, H5T_STD_I64BE_g, COPY, native_int, SET, 8)
1260
1261
    /* 1-byte little-endian (endianness is irrelevant) unsigned integer */
1262
12
    H5T_INIT_TYPE(UINTLE, H5T_STD_U8LE_g, COPY, native_uint, SET, 1)
1263
6
    std_u8le = dt; /* Keep type for later */
1264
1265
    /* 1-byte big-endian (endianness is irrelevant) unsigned integer */
1266
6
    H5T_INIT_TYPE(UINTBE, H5T_STD_U8BE_g, COPY, native_uint, SET, 1)
1267
6
    std_u8be = dt; /* Keep type for later */
1268
1269
    /* 2-byte little-endian unsigned integer */
1270
6
    H5T_INIT_TYPE(UINTLE, H5T_STD_U16LE_g, COPY, native_uint, SET, 2)
1271
6
    std_u16le = dt; /* Keep type for later */
1272
1273
    /* 2-byte big-endian unsigned integer */
1274
6
    H5T_INIT_TYPE(UINTBE, H5T_STD_U16BE_g, COPY, native_uint, SET, 2)
1275
6
    std_u16be = dt; /* Keep type for later */
1276
1277
    /* 4-byte little-endian unsigned integer */
1278
6
    H5T_INIT_TYPE(UINTLE, H5T_STD_U32LE_g, COPY, native_uint, SET, 4)
1279
6
    std_u32le = dt; /* Keep type for later */
1280
1281
    /* 4-byte big-endian unsigned integer */
1282
6
    H5T_INIT_TYPE(UINTBE, H5T_STD_U32BE_g, COPY, native_uint, SET, 4)
1283
6
    std_u32be = dt; /* Keep type for later */
1284
1285
    /* 8-byte little-endian unsigned integer */
1286
6
    H5T_INIT_TYPE(UINTLE, H5T_STD_U64LE_g, COPY, native_uint, SET, 8)
1287
6
    std_u64le = dt; /* Keep type for later */
1288
1289
    /* 8-byte big-endian unsigned integer */
1290
6
    H5T_INIT_TYPE(UINTBE, H5T_STD_U64BE_g, COPY, native_uint, SET, 8)
1291
6
    std_u64be = dt; /* Keep type for later */
1292
1293
    /*------------------------------------------------------------
1294
     * Native, Little- & Big-endian bitfields
1295
     *------------------------------------------------------------
1296
     */
1297
1298
    /* little-endian (order is irrelevant) 8-bit bitfield */
1299
6
    H5T_INIT_TYPE(BITFIELDLE, H5T_STD_B8LE_g, COPY, std_u8le, NOSET, -)
1300
6
    bitfield = dt; /* Keep type for later */
1301
1302
    /* big-endian (order is irrelevant) 8-bit bitfield */
1303
6
    H5T_INIT_TYPE(BITFIELDBE, H5T_STD_B8BE_g, COPY, std_u8be, NOSET, -)
1304
1305
    /* Little-endian 16-bit bitfield */
1306
12
    H5T_INIT_TYPE(BITFIELDLE, H5T_STD_B16LE_g, COPY, std_u16le, NOSET, -)
1307
1308
    /* Big-endian 16-bit bitfield */
1309
12
    H5T_INIT_TYPE(BITFIELDBE, H5T_STD_B16BE_g, COPY, std_u16be, NOSET, -)
1310
1311
    /* Little-endian 32-bit bitfield */
1312
12
    H5T_INIT_TYPE(BITFIELDLE, H5T_STD_B32LE_g, COPY, std_u32le, NOSET, -)
1313
1314
    /* Big-endian 32-bit bitfield */
1315
12
    H5T_INIT_TYPE(BITFIELDBE, H5T_STD_B32BE_g, COPY, std_u32be, NOSET, -)
1316
1317
    /* Little-endian 64-bit bitfield */
1318
12
    H5T_INIT_TYPE(BITFIELDLE, H5T_STD_B64LE_g, COPY, std_u64le, NOSET, -)
1319
1320
    /* Big-endian 64-bit bitfield */
1321
12
    H5T_INIT_TYPE(BITFIELDBE, H5T_STD_B64BE_g, COPY, std_u64be, NOSET, -)
1322
1323
    /*------------------------------------------------------------
1324
     * The Unix architecture for dates and times.
1325
     *------------------------------------------------------------
1326
     */
1327
1328
    /* Little-endian 32-bit UNIX time_t */
1329
12
    H5T_INIT_TYPE(TIME, H5T_UNIX_D32LE_g, COPY, std_u32le, NOSET, -)
1330
1331
    /* Big-endian 32-bit UNIX time_t */
1332
12
    H5T_INIT_TYPE(TIME, H5T_UNIX_D32BE_g, COPY, std_u32be, NOSET, -)
1333
1334
    /* Little-endian 64-bit UNIX time_t */
1335
12
    H5T_INIT_TYPE(TIME, H5T_UNIX_D64LE_g, COPY, std_u64le, NOSET, -)
1336
1337
    /* Big-endian 64-bit UNIX time_t */
1338
12
    H5T_INIT_TYPE(TIME, H5T_UNIX_D64BE_g, COPY, std_u64be, NOSET, -)
1339
1340
    /* Indicate that the types that are created from here down are allocated
1341
     * H5FL_ALLOC(), not copied with H5T_copy()
1342
     */
1343
6
    copied_dtype = false;
1344
1345
    /* Opaque data */
1346
6
    H5T_INIT_TYPE(OPAQ, H5T_NATIVE_OPAQUE_g, ALLOC, -, SET, 1)
1347
1348
    /*------------------------------------------------------------
1349
     * The `C' architecture
1350
     *------------------------------------------------------------
1351
     */
1352
1353
    /* One-byte character string */
1354
12
    H5T_INIT_TYPE(CSTRING, H5T_C_S1_g, ALLOC, -, SET, 1)
1355
6
    string = dt; /* Keep type for later */
1356
1357
    /*------------------------------------------------------------
1358
     * The `Fortran' architecture
1359
     *------------------------------------------------------------
1360
     */
1361
1362
    /* One-byte character string */
1363
6
    H5T_INIT_TYPE(FORSTRING, H5T_FORTRAN_S1_g, ALLOC, -, SET, 1)
1364
1365
    /*------------------------------------------------------------
1366
     * Reference types
1367
     *------------------------------------------------------------
1368
     */
1369
1370
    /* Deprecated object reference type */
1371
12
    H5T_INIT_TYPE(OBJREF, H5T_STD_REF_OBJ_g, ALLOC, -, NOSET, -)
1372
6
    if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0)
1373
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location");
1374
6
    objref = dt; /* Keep type for later */
1375
1376
    /* Deprecated region reference type */
1377
6
    H5T_INIT_TYPE(REGREF, H5T_STD_REF_DSETREG_g, ALLOC, -, NOSET, -)
1378
6
    if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0)
1379
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location");
1380
6
    regref = dt; /* Keep type for later */
1381
1382
    /* Opaque reference type */
1383
6
    H5T_INIT_TYPE(REF, H5T_STD_REF_g, ALLOC, -, NOSET, -)
1384
6
    if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0)
1385
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location");
1386
6
    ref = dt; /* Keep type for later */
1387
1388
    /*------------------------------------------------------------
1389
     * Complex Number Types
1390
     *------------------------------------------------------------
1391
     */
1392
1393
    /* Complex number of 2 IEEE 2-byte little-endian floats */
1394
6
    if (NULL == (tmp_float = H5I_object(H5T_IEEE_F16LE)))
1395
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1396
6
    if (NULL == (dt = H5T__complex_create(tmp_float)))
1397
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "couldn't create complex number datatype");
1398
6
    if ((H5T_COMPLEX_IEEE_F16LE_g = H5I_register(H5I_DATATYPE, dt, false)) < 0)
1399
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register datatype atom");
1400
1401
    /* Complex number of 2 IEEE 2-byte big-endian floats */
1402
6
    if (NULL == (tmp_float = H5I_object(H5T_IEEE_F16BE)))
1403
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1404
6
    if (NULL == (dt = H5T__complex_create(tmp_float)))
1405
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "couldn't create complex number datatype");
1406
6
    if ((H5T_COMPLEX_IEEE_F16BE_g = H5I_register(H5I_DATATYPE, dt, false)) < 0)
1407
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register datatype atom");
1408
1409
    /* Complex number of 2 IEEE 4-byte little-endian floats */
1410
6
    if (NULL == (tmp_float = H5I_object(H5T_IEEE_F32LE)))
1411
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1412
6
    if (NULL == (dt = H5T__complex_create(tmp_float)))
1413
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "couldn't create complex number datatype");
1414
6
    if ((H5T_COMPLEX_IEEE_F32LE_g = H5I_register(H5I_DATATYPE, dt, false)) < 0)
1415
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register datatype atom");
1416
1417
    /* Complex number of 2 IEEE 4-byte big-endian floats */
1418
6
    if (NULL == (tmp_float = H5I_object(H5T_IEEE_F32BE)))
1419
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1420
6
    if (NULL == (dt = H5T__complex_create(tmp_float)))
1421
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "couldn't create complex number datatype");
1422
6
    if ((H5T_COMPLEX_IEEE_F32BE_g = H5I_register(H5I_DATATYPE, dt, false)) < 0)
1423
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register datatype atom");
1424
1425
    /* Complex number of 2 IEEE 8-byte little-endian floats */
1426
6
    if (NULL == (tmp_float = H5I_object(H5T_IEEE_F64LE)))
1427
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1428
6
    if (NULL == (dt = H5T__complex_create(tmp_float)))
1429
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "couldn't create complex number datatype");
1430
6
    if ((H5T_COMPLEX_IEEE_F64LE_g = H5I_register(H5I_DATATYPE, dt, false)) < 0)
1431
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register datatype atom");
1432
1433
    /* Complex number of 2 IEEE 8-byte big-endian floats */
1434
6
    if (NULL == (tmp_float = H5I_object(H5T_IEEE_F64BE)))
1435
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
1436
6
    if (NULL == (dt = H5T__complex_create(tmp_float)))
1437
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "couldn't create complex number datatype");
1438
6
    if ((H5T_COMPLEX_IEEE_F64BE_g = H5I_register(H5I_DATATYPE, dt, false)) < 0)
1439
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register datatype atom");
1440
1441
    /*
1442
     * Register conversion functions beginning with the most general and
1443
     * ending with the most specific.
1444
     */
1445
6
    fixedpt = native_int;
1446
6
    floatpt = native_float;
1447
6
    if (NULL == (compound = H5T__create(H5T_COMPOUND, (size_t)1)))
1448
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
1449
6
    if (NULL == (enum_type = H5T__create(H5T_ENUM, (size_t)1)))
1450
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
1451
6
    if (NULL == (vlen = H5T__vlen_create(native_int)))
1452
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
1453
6
    if (NULL == (array = H5T__array_create(native_int, 1, dim)))
1454
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
1455
6
    if (NULL == (cplx = H5T__complex_create(native_float)))
1456
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
1457
6
    status = 0;
1458
1459
6
    status |= H5T__register_int(H5T_PERS_SOFT, "i_i", fixedpt, fixedpt, H5T__conv_i_i);
1460
6
    status |= H5T__register_int(H5T_PERS_SOFT, "i_f", fixedpt, floatpt, H5T__conv_i_f);
1461
6
    status |= H5T__register_int(H5T_PERS_SOFT, "i_complex", fixedpt, cplx, H5T__conv_i_complex);
1462
6
    status |= H5T__register_int(H5T_PERS_SOFT, "complex_i", cplx, fixedpt, H5T__conv_complex_i);
1463
6
    status |= H5T__register_int(H5T_PERS_SOFT, "f_f", floatpt, floatpt, H5T__conv_f_f);
1464
6
    status |= H5T__register_int(H5T_PERS_SOFT, "f_i", floatpt, fixedpt, H5T__conv_f_i);
1465
6
    status |= H5T__register_int(H5T_PERS_SOFT, "f_complex", floatpt, cplx, H5T__conv_f_complex);
1466
6
    status |= H5T__register_int(H5T_PERS_SOFT, "complex_f", cplx, floatpt, H5T__conv_complex_f);
1467
6
    status |= H5T__register_int(H5T_PERS_SOFT, "complex_complex", cplx, cplx, H5T__conv_complex);
1468
6
    status |= H5T__register_int(H5T_PERS_SOFT, "s_s", string, string, H5T__conv_s_s);
1469
6
    status |= H5T__register_int(H5T_PERS_SOFT, "b_b", bitfield, bitfield, H5T__conv_b_b);
1470
6
    status |= H5T__register_int(H5T_PERS_SOFT, "ibo", fixedpt, fixedpt, H5T__conv_order);
1471
6
    status |= H5T__register_int(H5T_PERS_SOFT, "ibo(opt)", fixedpt, fixedpt, H5T__conv_order_opt);
1472
6
    status |= H5T__register_int(H5T_PERS_SOFT, "fbo", floatpt, floatpt, H5T__conv_order);
1473
6
    status |= H5T__register_int(H5T_PERS_SOFT, "fbo(opt)", floatpt, floatpt, H5T__conv_order_opt);
1474
6
    status |= H5T__register_int(H5T_PERS_SOFT, "complexbo", cplx, cplx, H5T__conv_order);
1475
6
    status |= H5T__register_int(H5T_PERS_SOFT, "complexbo(opt)", cplx, cplx, H5T__conv_order_opt);
1476
6
    status |= H5T__register_int(H5T_PERS_SOFT, "struct(no-opt)", compound, compound, H5T__conv_struct);
1477
6
    status |= H5T__register_int(H5T_PERS_SOFT, "struct(opt)", compound, compound, H5T__conv_struct_opt);
1478
6
    status |= H5T__register_int(H5T_PERS_SOFT, "enum", enum_type, enum_type, H5T__conv_enum);
1479
6
    status |= H5T__register_int(H5T_PERS_SOFT, "enum_i", enum_type, fixedpt, H5T__conv_enum_numeric);
1480
6
    status |= H5T__register_int(H5T_PERS_SOFT, "enum_f", enum_type, floatpt, H5T__conv_enum_numeric);
1481
6
    status |= H5T__register_int(H5T_PERS_SOFT, "vlen", vlen, vlen, H5T__conv_vlen);
1482
6
    status |= H5T__register_int(H5T_PERS_SOFT, "array", array, array, H5T__conv_array);
1483
6
    status |= H5T__register_int(H5T_PERS_SOFT, "objref", objref, objref, H5T__conv_noop);
1484
6
    status |= H5T__register_int(H5T_PERS_SOFT, "regref", regref, regref, H5T__conv_noop);
1485
6
    status |= H5T__register_int(H5T_PERS_SOFT, "ref", ref, ref, H5T__conv_ref);
1486
6
    status |= H5T__register_int(H5T_PERS_SOFT, "objref_ref", objref, ref, H5T__conv_ref);
1487
6
    status |= H5T__register_int(H5T_PERS_SOFT, "regref_ref", regref, ref, H5T__conv_ref);
1488
6
    status |= H5T__register_int(H5T_PERS_SOFT, "complex_array_compat", cplx, array, H5T__conv_complex_compat);
1489
6
    status |= H5T__register_int(H5T_PERS_SOFT, "array_complex_compat", array, cplx, H5T__conv_complex_compat);
1490
6
    status |=
1491
6
        H5T__register_int(H5T_PERS_SOFT, "complex_compound_compat", cplx, compound, H5T__conv_complex_compat);
1492
6
    status |=
1493
6
        H5T__register_int(H5T_PERS_SOFT, "compound_complex_compat", compound, cplx, H5T__conv_complex_compat);
1494
1495
    /*
1496
     * Native conversions should be listed last since we can use hardware to
1497
     * perform the conversion.  We list the odd types like `llong', `long',
1498
     * and `short' before the usual types like `int' and `char' so that when
1499
     * diagnostics are printed we favor the usual names over the odd names
1500
     * when two or more types are the same size.
1501
     */
1502
1503
    /* floating point */
1504
6
    status |=
1505
6
        H5T__register_int(H5T_PERS_HARD, "flt_dbl", native_float, native_double, H5T__conv_float_double);
1506
6
    status |=
1507
6
        H5T__register_int(H5T_PERS_HARD, "dbl_flt", native_double, native_float, H5T__conv_double_float);
1508
6
    status |=
1509
6
        H5T__register_int(H5T_PERS_HARD, "flt_ldbl", native_float, native_ldouble, H5T__conv_float_ldouble);
1510
6
    status |=
1511
6
        H5T__register_int(H5T_PERS_HARD, "dbl_ldbl", native_double, native_ldouble, H5T__conv_double_ldouble);
1512
6
    status |=
1513
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_flt", native_ldouble, native_float, H5T__conv_ldouble_float);
1514
6
    status |=
1515
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_dbl", native_ldouble, native_double, H5T__conv_ldouble_double);
1516
#ifdef H5_HAVE__FLOAT16
1517
    status |=
1518
        H5T__register_int(H5T_PERS_HARD, "flt16_flt", native_float16, native_float, H5T__conv__Float16_float);
1519
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_dbl", native_float16, native_double,
1520
                                H5T__conv__Float16_double);
1521
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_ldbl", native_float16, native_ldouble,
1522
                                H5T__conv__Float16_ldouble);
1523
    status |=
1524
        H5T__register_int(H5T_PERS_HARD, "flt_flt16", native_float, native_float16, H5T__conv_float__Float16);
1525
    status |= H5T__register_int(H5T_PERS_HARD, "dbl_flt16", native_double, native_float16,
1526
                                H5T__conv_double__Float16);
1527
#ifdef H5T_CONV_INTERNAL_LDOUBLE_FLOAT16
1528
    status |= H5T__register_int(H5T_PERS_HARD, "ldbl_flt16", native_ldouble, native_float16,
1529
                                H5T__conv_ldouble__Float16);
1530
#endif
1531
#endif
1532
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1533
6
    status |= H5T__register_int(H5T_PERS_HARD, "flt_fcomplex", native_float, native_float_complex,
1534
6
                                H5T__conv_float_fcomplex);
1535
6
    status |= H5T__register_int(H5T_PERS_HARD, "flt_dcomplex", native_float, native_double_complex,
1536
6
                                H5T__conv_float_dcomplex);
1537
6
    status |= H5T__register_int(H5T_PERS_HARD, "flt_lcomplex", native_float, native_ldouble_complex,
1538
6
                                H5T__conv_float_lcomplex);
1539
6
    status |= H5T__register_int(H5T_PERS_HARD, "dbl_fcomplex", native_double, native_float_complex,
1540
6
                                H5T__conv_double_fcomplex);
1541
6
    status |= H5T__register_int(H5T_PERS_HARD, "dbl_dcomplex", native_double, native_double_complex,
1542
6
                                H5T__conv_double_dcomplex);
1543
6
    status |= H5T__register_int(H5T_PERS_HARD, "dbl_lcomplex", native_double, native_ldouble_complex,
1544
6
                                H5T__conv_double_lcomplex);
1545
6
    status |= H5T__register_int(H5T_PERS_HARD, "ldbl_fcomplex", native_ldouble, native_float_complex,
1546
6
                                H5T__conv_ldouble_fcomplex);
1547
6
    status |= H5T__register_int(H5T_PERS_HARD, "ldbl_dcomplex", native_ldouble, native_double_complex,
1548
6
                                H5T__conv_ldouble_dcomplex);
1549
6
    status |= H5T__register_int(H5T_PERS_HARD, "ldbl_lcomplex", native_ldouble, native_ldouble_complex,
1550
6
                                H5T__conv_ldouble_lcomplex);
1551
#ifdef H5_HAVE__FLOAT16
1552
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_fcomplex", native_float16, native_float_complex,
1553
                                H5T__conv__Float16_fcomplex);
1554
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_dcomplex", native_float16, native_double_complex,
1555
                                H5T__conv__Float16_dcomplex);
1556
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_lcomplex", native_float16, native_ldouble_complex,
1557
                                H5T__conv__Float16_lcomplex);
1558
#endif
1559
6
#endif
1560
1561
    /* from long long */
1562
6
    status |=
1563
6
        H5T__register_int(H5T_PERS_HARD, "llong_ullong", native_llong, native_ullong, H5T__conv_llong_ullong);
1564
6
    status |=
1565
6
        H5T__register_int(H5T_PERS_HARD, "ullong_llong", native_ullong, native_llong, H5T__conv_ullong_llong);
1566
6
    status |= H5T__register_int(H5T_PERS_HARD, "llong_long", native_llong, native_long, H5T__conv_llong_long);
1567
6
    status |=
1568
6
        H5T__register_int(H5T_PERS_HARD, "llong_ulong", native_llong, native_ulong, H5T__conv_llong_ulong);
1569
6
    status |=
1570
6
        H5T__register_int(H5T_PERS_HARD, "ullong_long", native_ullong, native_long, H5T__conv_ullong_long);
1571
6
    status |=
1572
6
        H5T__register_int(H5T_PERS_HARD, "ullong_ulong", native_ullong, native_ulong, H5T__conv_ullong_ulong);
1573
6
    status |=
1574
6
        H5T__register_int(H5T_PERS_HARD, "llong_short", native_llong, native_short, H5T__conv_llong_short);
1575
6
    status |=
1576
6
        H5T__register_int(H5T_PERS_HARD, "llong_ushort", native_llong, native_ushort, H5T__conv_llong_ushort);
1577
6
    status |=
1578
6
        H5T__register_int(H5T_PERS_HARD, "ullong_short", native_ullong, native_short, H5T__conv_ullong_short);
1579
6
    status |= H5T__register_int(H5T_PERS_HARD, "ullong_ushort", native_ullong, native_ushort,
1580
6
                                H5T__conv_ullong_ushort);
1581
6
    status |= H5T__register_int(H5T_PERS_HARD, "llong_int", native_llong, native_int, H5T__conv_llong_int);
1582
6
    status |= H5T__register_int(H5T_PERS_HARD, "llong_uint", native_llong, native_uint, H5T__conv_llong_uint);
1583
6
    status |= H5T__register_int(H5T_PERS_HARD, "ullong_int", native_ullong, native_int, H5T__conv_ullong_int);
1584
6
    status |=
1585
6
        H5T__register_int(H5T_PERS_HARD, "ullong_uint", native_ullong, native_uint, H5T__conv_ullong_uint);
1586
6
    status |=
1587
6
        H5T__register_int(H5T_PERS_HARD, "llong_schar", native_llong, native_schar, H5T__conv_llong_schar);
1588
6
    status |=
1589
6
        H5T__register_int(H5T_PERS_HARD, "llong_uchar", native_llong, native_uchar, H5T__conv_llong_uchar);
1590
6
    status |=
1591
6
        H5T__register_int(H5T_PERS_HARD, "ullong_schar", native_ullong, native_schar, H5T__conv_ullong_schar);
1592
6
    status |=
1593
6
        H5T__register_int(H5T_PERS_HARD, "ullong_uchar", native_ullong, native_uchar, H5T__conv_ullong_uchar);
1594
1595
    /* From long */
1596
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_llong", native_long, native_llong, H5T__conv_long_llong);
1597
6
    status |=
1598
6
        H5T__register_int(H5T_PERS_HARD, "long_ullong", native_long, native_ullong, H5T__conv_long_ullong);
1599
6
    status |=
1600
6
        H5T__register_int(H5T_PERS_HARD, "ulong_llong", native_ulong, native_llong, H5T__conv_ulong_llong);
1601
6
    status |=
1602
6
        H5T__register_int(H5T_PERS_HARD, "ulong_ullong", native_ulong, native_ullong, H5T__conv_ulong_ullong);
1603
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_ulong", native_long, native_ulong, H5T__conv_long_ulong);
1604
6
    status |= H5T__register_int(H5T_PERS_HARD, "ulong_long", native_ulong, native_long, H5T__conv_ulong_long);
1605
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_short", native_long, native_short, H5T__conv_long_short);
1606
6
    status |=
1607
6
        H5T__register_int(H5T_PERS_HARD, "long_ushort", native_long, native_ushort, H5T__conv_long_ushort);
1608
6
    status |=
1609
6
        H5T__register_int(H5T_PERS_HARD, "ulong_short", native_ulong, native_short, H5T__conv_ulong_short);
1610
6
    status |=
1611
6
        H5T__register_int(H5T_PERS_HARD, "ulong_ushort", native_ulong, native_ushort, H5T__conv_ulong_ushort);
1612
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_int", native_long, native_int, H5T__conv_long_int);
1613
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_uint", native_long, native_uint, H5T__conv_long_uint);
1614
6
    status |= H5T__register_int(H5T_PERS_HARD, "ulong_int", native_ulong, native_int, H5T__conv_ulong_int);
1615
6
    status |= H5T__register_int(H5T_PERS_HARD, "ulong_uint", native_ulong, native_uint, H5T__conv_ulong_uint);
1616
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_schar", native_long, native_schar, H5T__conv_long_schar);
1617
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_uchar", native_long, native_uchar, H5T__conv_long_uchar);
1618
6
    status |=
1619
6
        H5T__register_int(H5T_PERS_HARD, "ulong_schar", native_ulong, native_schar, H5T__conv_ulong_schar);
1620
6
    status |=
1621
6
        H5T__register_int(H5T_PERS_HARD, "ulong_uchar", native_ulong, native_uchar, H5T__conv_ulong_uchar);
1622
1623
    /* From short */
1624
6
    status |=
1625
6
        H5T__register_int(H5T_PERS_HARD, "short_llong", native_short, native_llong, H5T__conv_short_llong);
1626
6
    status |=
1627
6
        H5T__register_int(H5T_PERS_HARD, "short_ullong", native_short, native_ullong, H5T__conv_short_ullong);
1628
6
    status |=
1629
6
        H5T__register_int(H5T_PERS_HARD, "ushort_llong", native_ushort, native_llong, H5T__conv_ushort_llong);
1630
6
    status |= H5T__register_int(H5T_PERS_HARD, "ushort_ullong", native_ushort, native_ullong,
1631
6
                                H5T__conv_ushort_ullong);
1632
6
    status |= H5T__register_int(H5T_PERS_HARD, "short_long", native_short, native_long, H5T__conv_short_long);
1633
6
    status |=
1634
6
        H5T__register_int(H5T_PERS_HARD, "short_ulong", native_short, native_ulong, H5T__conv_short_ulong);
1635
6
    status |=
1636
6
        H5T__register_int(H5T_PERS_HARD, "ushort_long", native_ushort, native_long, H5T__conv_ushort_long);
1637
6
    status |=
1638
6
        H5T__register_int(H5T_PERS_HARD, "ushort_ulong", native_ushort, native_ulong, H5T__conv_ushort_ulong);
1639
6
    status |=
1640
6
        H5T__register_int(H5T_PERS_HARD, "short_ushort", native_short, native_ushort, H5T__conv_short_ushort);
1641
6
    status |=
1642
6
        H5T__register_int(H5T_PERS_HARD, "ushort_short", native_ushort, native_short, H5T__conv_ushort_short);
1643
6
    status |= H5T__register_int(H5T_PERS_HARD, "short_int", native_short, native_int, H5T__conv_short_int);
1644
6
    status |= H5T__register_int(H5T_PERS_HARD, "short_uint", native_short, native_uint, H5T__conv_short_uint);
1645
6
    status |= H5T__register_int(H5T_PERS_HARD, "ushort_int", native_ushort, native_int, H5T__conv_ushort_int);
1646
6
    status |=
1647
6
        H5T__register_int(H5T_PERS_HARD, "ushort_uint", native_ushort, native_uint, H5T__conv_ushort_uint);
1648
6
    status |=
1649
6
        H5T__register_int(H5T_PERS_HARD, "short_schar", native_short, native_schar, H5T__conv_short_schar);
1650
6
    status |=
1651
6
        H5T__register_int(H5T_PERS_HARD, "short_uchar", native_short, native_uchar, H5T__conv_short_uchar);
1652
6
    status |=
1653
6
        H5T__register_int(H5T_PERS_HARD, "ushort_schar", native_ushort, native_schar, H5T__conv_ushort_schar);
1654
6
    status |=
1655
6
        H5T__register_int(H5T_PERS_HARD, "ushort_uchar", native_ushort, native_uchar, H5T__conv_ushort_uchar);
1656
1657
    /* From int */
1658
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_llong", native_int, native_llong, H5T__conv_int_llong);
1659
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_ullong", native_int, native_ullong, H5T__conv_int_ullong);
1660
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_llong", native_uint, native_llong, H5T__conv_uint_llong);
1661
6
    status |=
1662
6
        H5T__register_int(H5T_PERS_HARD, "uint_ullong", native_uint, native_ullong, H5T__conv_uint_ullong);
1663
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_long", native_int, native_long, H5T__conv_int_long);
1664
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_ulong", native_int, native_ulong, H5T__conv_int_ulong);
1665
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_long", native_uint, native_long, H5T__conv_uint_long);
1666
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_ulong", native_uint, native_ulong, H5T__conv_uint_ulong);
1667
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_short", native_int, native_short, H5T__conv_int_short);
1668
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_ushort", native_int, native_ushort, H5T__conv_int_ushort);
1669
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_short", native_uint, native_short, H5T__conv_uint_short);
1670
6
    status |=
1671
6
        H5T__register_int(H5T_PERS_HARD, "uint_ushort", native_uint, native_ushort, H5T__conv_uint_ushort);
1672
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_uint", native_int, native_uint, H5T__conv_int_uint);
1673
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_int", native_uint, native_int, H5T__conv_uint_int);
1674
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_schar", native_int, native_schar, H5T__conv_int_schar);
1675
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_uchar", native_int, native_uchar, H5T__conv_int_uchar);
1676
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_schar", native_uint, native_schar, H5T__conv_uint_schar);
1677
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_uchar", native_uint, native_uchar, H5T__conv_uint_uchar);
1678
1679
    /* From char */
1680
6
    status |=
1681
6
        H5T__register_int(H5T_PERS_HARD, "schar_llong", native_schar, native_llong, H5T__conv_schar_llong);
1682
6
    status |=
1683
6
        H5T__register_int(H5T_PERS_HARD, "schar_ullong", native_schar, native_ullong, H5T__conv_schar_ullong);
1684
6
    status |=
1685
6
        H5T__register_int(H5T_PERS_HARD, "uchar_llong", native_uchar, native_llong, H5T__conv_uchar_llong);
1686
6
    status |=
1687
6
        H5T__register_int(H5T_PERS_HARD, "uchar_ullong", native_uchar, native_ullong, H5T__conv_uchar_ullong);
1688
6
    status |= H5T__register_int(H5T_PERS_HARD, "schar_long", native_schar, native_long, H5T__conv_schar_long);
1689
6
    status |=
1690
6
        H5T__register_int(H5T_PERS_HARD, "schar_ulong", native_schar, native_ulong, H5T__conv_schar_ulong);
1691
6
    status |= H5T__register_int(H5T_PERS_HARD, "uchar_long", native_uchar, native_long, H5T__conv_uchar_long);
1692
6
    status |=
1693
6
        H5T__register_int(H5T_PERS_HARD, "uchar_ulong", native_uchar, native_ulong, H5T__conv_uchar_ulong);
1694
6
    status |=
1695
6
        H5T__register_int(H5T_PERS_HARD, "schar_short", native_schar, native_short, H5T__conv_schar_short);
1696
6
    status |=
1697
6
        H5T__register_int(H5T_PERS_HARD, "schar_ushort", native_schar, native_ushort, H5T__conv_schar_ushort);
1698
6
    status |=
1699
6
        H5T__register_int(H5T_PERS_HARD, "uchar_short", native_uchar, native_short, H5T__conv_uchar_short);
1700
6
    status |=
1701
6
        H5T__register_int(H5T_PERS_HARD, "uchar_ushort", native_uchar, native_ushort, H5T__conv_uchar_ushort);
1702
6
    status |= H5T__register_int(H5T_PERS_HARD, "schar_int", native_schar, native_int, H5T__conv_schar_int);
1703
6
    status |= H5T__register_int(H5T_PERS_HARD, "schar_uint", native_schar, native_uint, H5T__conv_schar_uint);
1704
6
    status |= H5T__register_int(H5T_PERS_HARD, "uchar_int", native_uchar, native_int, H5T__conv_uchar_int);
1705
6
    status |= H5T__register_int(H5T_PERS_HARD, "uchar_uint", native_uchar, native_uint, H5T__conv_uchar_uint);
1706
6
    status |=
1707
6
        H5T__register_int(H5T_PERS_HARD, "schar_uchar", native_schar, native_uchar, H5T__conv_schar_uchar);
1708
6
    status |=
1709
6
        H5T__register_int(H5T_PERS_HARD, "uchar_schar", native_uchar, native_schar, H5T__conv_uchar_schar);
1710
1711
    /* From char to floats */
1712
6
    status |=
1713
6
        H5T__register_int(H5T_PERS_HARD, "schar_flt", native_schar, native_float, H5T__conv_schar_float);
1714
6
    status |=
1715
6
        H5T__register_int(H5T_PERS_HARD, "schar_dbl", native_schar, native_double, H5T__conv_schar_double);
1716
6
    status |=
1717
6
        H5T__register_int(H5T_PERS_HARD, "schar_ldbl", native_schar, native_ldouble, H5T__conv_schar_ldouble);
1718
#ifdef H5_HAVE__FLOAT16
1719
    status |= H5T__register_int(H5T_PERS_HARD, "schar_flt16", native_schar, native_float16,
1720
                                H5T__conv_schar__Float16);
1721
#endif
1722
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1723
6
    status |= H5T__register_int(H5T_PERS_HARD, "schar_fcomplex", native_schar, native_float_complex,
1724
6
                                H5T__conv_schar_fcomplex);
1725
6
    status |= H5T__register_int(H5T_PERS_HARD, "schar_dcomplex", native_schar, native_double_complex,
1726
6
                                H5T__conv_schar_dcomplex);
1727
6
    status |= H5T__register_int(H5T_PERS_HARD, "schar_lcomplex", native_schar, native_ldouble_complex,
1728
6
                                H5T__conv_schar_lcomplex);
1729
6
#endif
1730
1731
    /* From unsigned char to floats */
1732
6
    status |=
1733
6
        H5T__register_int(H5T_PERS_HARD, "uchar_flt", native_uchar, native_float, H5T__conv_uchar_float);
1734
6
    status |=
1735
6
        H5T__register_int(H5T_PERS_HARD, "uchar_dbl", native_uchar, native_double, H5T__conv_uchar_double);
1736
6
    status |=
1737
6
        H5T__register_int(H5T_PERS_HARD, "uchar_ldbl", native_uchar, native_ldouble, H5T__conv_uchar_ldouble);
1738
#ifdef H5_HAVE__FLOAT16
1739
    status |= H5T__register_int(H5T_PERS_HARD, "uchar_flt16", native_uchar, native_float16,
1740
                                H5T__conv_uchar__Float16);
1741
#endif
1742
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1743
6
    status |= H5T__register_int(H5T_PERS_HARD, "uchar_fcomplex", native_uchar, native_float_complex,
1744
6
                                H5T__conv_uchar_fcomplex);
1745
6
    status |= H5T__register_int(H5T_PERS_HARD, "uchar_dcomplex", native_uchar, native_double_complex,
1746
6
                                H5T__conv_uchar_dcomplex);
1747
6
    status |= H5T__register_int(H5T_PERS_HARD, "uchar_lcomplex", native_uchar, native_ldouble_complex,
1748
6
                                H5T__conv_uchar_lcomplex);
1749
6
#endif
1750
1751
    /* From short to floats */
1752
6
    status |=
1753
6
        H5T__register_int(H5T_PERS_HARD, "short_flt", native_short, native_float, H5T__conv_short_float);
1754
6
    status |=
1755
6
        H5T__register_int(H5T_PERS_HARD, "short_dbl", native_short, native_double, H5T__conv_short_double);
1756
6
    status |=
1757
6
        H5T__register_int(H5T_PERS_HARD, "short_ldbl", native_short, native_ldouble, H5T__conv_short_ldouble);
1758
#ifdef H5_HAVE__FLOAT16
1759
    status |= H5T__register_int(H5T_PERS_HARD, "short_flt16", native_short, native_float16,
1760
                                H5T__conv_short__Float16);
1761
#endif
1762
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1763
6
    status |= H5T__register_int(H5T_PERS_HARD, "short_fcomplex", native_short, native_float_complex,
1764
6
                                H5T__conv_short_fcomplex);
1765
6
    status |= H5T__register_int(H5T_PERS_HARD, "short_dcomplex", native_short, native_double_complex,
1766
6
                                H5T__conv_short_dcomplex);
1767
6
    status |= H5T__register_int(H5T_PERS_HARD, "short_lcomplex", native_short, native_ldouble_complex,
1768
6
                                H5T__conv_short_lcomplex);
1769
6
#endif
1770
1771
    /* From unsigned short to floats */
1772
6
    status |=
1773
6
        H5T__register_int(H5T_PERS_HARD, "ushort_flt", native_ushort, native_float, H5T__conv_ushort_float);
1774
6
    status |=
1775
6
        H5T__register_int(H5T_PERS_HARD, "ushort_dbl", native_ushort, native_double, H5T__conv_ushort_double);
1776
6
    status |= H5T__register_int(H5T_PERS_HARD, "ushort_ldbl", native_ushort, native_ldouble,
1777
6
                                H5T__conv_ushort_ldouble);
1778
#ifdef H5_HAVE__FLOAT16
1779
    status |= H5T__register_int(H5T_PERS_HARD, "ushort_flt16", native_ushort, native_float16,
1780
                                H5T__conv_ushort__Float16);
1781
#endif
1782
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1783
6
    status |= H5T__register_int(H5T_PERS_HARD, "ushort_fcomplex", native_ushort, native_float_complex,
1784
6
                                H5T__conv_ushort_fcomplex);
1785
6
    status |= H5T__register_int(H5T_PERS_HARD, "ushort_dcomplex", native_ushort, native_double_complex,
1786
6
                                H5T__conv_ushort_dcomplex);
1787
6
    status |= H5T__register_int(H5T_PERS_HARD, "ushort_lcomplex", native_ushort, native_ldouble_complex,
1788
6
                                H5T__conv_ushort_lcomplex);
1789
6
#endif
1790
1791
    /* From int to floats */
1792
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_flt", native_int, native_float, H5T__conv_int_float);
1793
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_dbl", native_int, native_double, H5T__conv_int_double);
1794
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_ldbl", native_int, native_ldouble, H5T__conv_int_ldouble);
1795
#ifdef H5_HAVE__FLOAT16
1796
    status |=
1797
        H5T__register_int(H5T_PERS_HARD, "int_flt16", native_int, native_float16, H5T__conv_int__Float16);
1798
#endif
1799
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1800
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_fcomplex", native_int, native_float_complex,
1801
6
                                H5T__conv_int_fcomplex);
1802
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_dcomplex", native_int, native_double_complex,
1803
6
                                H5T__conv_int_dcomplex);
1804
6
    status |= H5T__register_int(H5T_PERS_HARD, "int_lcomplex", native_int, native_ldouble_complex,
1805
6
                                H5T__conv_int_lcomplex);
1806
6
#endif
1807
1808
    /* From unsigned int to floats */
1809
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_flt", native_uint, native_float, H5T__conv_uint_float);
1810
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_dbl", native_uint, native_double, H5T__conv_uint_double);
1811
6
    status |=
1812
6
        H5T__register_int(H5T_PERS_HARD, "uint_ldbl", native_uint, native_ldouble, H5T__conv_uint_ldouble);
1813
#ifdef H5_HAVE__FLOAT16
1814
    status |=
1815
        H5T__register_int(H5T_PERS_HARD, "uint_flt16", native_uint, native_float16, H5T__conv_uint__Float16);
1816
#endif
1817
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1818
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_fcomplex", native_uint, native_float_complex,
1819
6
                                H5T__conv_uint_fcomplex);
1820
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_dcomplex", native_uint, native_double_complex,
1821
6
                                H5T__conv_uint_dcomplex);
1822
6
    status |= H5T__register_int(H5T_PERS_HARD, "uint_lcomplex", native_uint, native_ldouble_complex,
1823
6
                                H5T__conv_uint_lcomplex);
1824
6
#endif
1825
1826
    /* From long to floats */
1827
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_flt", native_long, native_float, H5T__conv_long_float);
1828
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_dbl", native_long, native_double, H5T__conv_long_double);
1829
6
    status |=
1830
6
        H5T__register_int(H5T_PERS_HARD, "long_ldbl", native_long, native_ldouble, H5T__conv_long_ldouble);
1831
#ifdef H5_HAVE__FLOAT16
1832
    status |=
1833
        H5T__register_int(H5T_PERS_HARD, "long_flt16", native_long, native_float16, H5T__conv_long__Float16);
1834
#endif
1835
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1836
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_fcomplex", native_long, native_float_complex,
1837
6
                                H5T__conv_long_fcomplex);
1838
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_dcomplex", native_long, native_double_complex,
1839
6
                                H5T__conv_long_dcomplex);
1840
6
    status |= H5T__register_int(H5T_PERS_HARD, "long_lcomplex", native_long, native_ldouble_complex,
1841
6
                                H5T__conv_long_lcomplex);
1842
6
#endif
1843
1844
    /* From unsigned long to floats */
1845
6
    status |=
1846
6
        H5T__register_int(H5T_PERS_HARD, "ulong_flt", native_ulong, native_float, H5T__conv_ulong_float);
1847
6
    status |=
1848
6
        H5T__register_int(H5T_PERS_HARD, "ulong_dbl", native_ulong, native_double, H5T__conv_ulong_double);
1849
6
    status |=
1850
6
        H5T__register_int(H5T_PERS_HARD, "ulong_ldbl", native_ulong, native_ldouble, H5T__conv_ulong_ldouble);
1851
#ifdef H5_HAVE__FLOAT16
1852
    status |= H5T__register_int(H5T_PERS_HARD, "ulong_flt16", native_ulong, native_float16,
1853
                                H5T__conv_ulong__Float16);
1854
#endif
1855
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1856
6
    status |= H5T__register_int(H5T_PERS_HARD, "ulong_fcomplex", native_ulong, native_float_complex,
1857
6
                                H5T__conv_ulong_fcomplex);
1858
6
    status |= H5T__register_int(H5T_PERS_HARD, "ulong_dcomplex", native_ulong, native_double_complex,
1859
6
                                H5T__conv_ulong_dcomplex);
1860
6
    status |= H5T__register_int(H5T_PERS_HARD, "ulong_lcomplex", native_ulong, native_ldouble_complex,
1861
6
                                H5T__conv_ulong_lcomplex);
1862
6
#endif
1863
1864
    /* From long long to floats */
1865
6
    status |=
1866
6
        H5T__register_int(H5T_PERS_HARD, "llong_flt", native_llong, native_float, H5T__conv_llong_float);
1867
6
    status |=
1868
6
        H5T__register_int(H5T_PERS_HARD, "llong_dbl", native_llong, native_double, H5T__conv_llong_double);
1869
6
#ifdef H5T_CONV_INTERNAL_LLONG_LDOUBLE
1870
6
    status |=
1871
6
        H5T__register_int(H5T_PERS_HARD, "llong_ldbl", native_llong, native_ldouble, H5T__conv_llong_ldouble);
1872
6
#endif /* H5T_CONV_INTERNAL_LLONG_LDOUBLE */
1873
#ifdef H5_HAVE__FLOAT16
1874
    status |= H5T__register_int(H5T_PERS_HARD, "llong_flt16", native_llong, native_float16,
1875
                                H5T__conv_llong__Float16);
1876
#endif
1877
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1878
6
    status |= H5T__register_int(H5T_PERS_HARD, "llong_fcomplex", native_llong, native_float_complex,
1879
6
                                H5T__conv_llong_fcomplex);
1880
6
    status |= H5T__register_int(H5T_PERS_HARD, "llong_dcomplex", native_llong, native_double_complex,
1881
6
                                H5T__conv_llong_dcomplex);
1882
6
#ifdef H5T_CONV_INTERNAL_LLONG_LDOUBLE
1883
6
    status |= H5T__register_int(H5T_PERS_HARD, "llong_lcomplex", native_llong, native_ldouble_complex,
1884
6
                                H5T__conv_llong_lcomplex);
1885
6
#endif
1886
6
#endif
1887
1888
    /* From unsigned long long to floats */
1889
6
    status |=
1890
6
        H5T__register_int(H5T_PERS_HARD, "ullong_flt", native_ullong, native_float, H5T__conv_ullong_float);
1891
6
    status |=
1892
6
        H5T__register_int(H5T_PERS_HARD, "ullong_dbl", native_ullong, native_double, H5T__conv_ullong_double);
1893
6
#ifdef H5T_CONV_INTERNAL_ULLONG_LDOUBLE
1894
6
    status |= H5T__register_int(H5T_PERS_HARD, "ullong_ldbl", native_ullong, native_ldouble,
1895
6
                                H5T__conv_ullong_ldouble);
1896
6
#endif /* H5T_CONV_INTERNAL_ULLONG_LDOUBLE */
1897
#ifdef H5_HAVE__FLOAT16
1898
    status |= H5T__register_int(H5T_PERS_HARD, "ullong_flt16", native_ullong, native_float16,
1899
                                H5T__conv_ullong__Float16);
1900
#endif
1901
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
1902
6
    status |= H5T__register_int(H5T_PERS_HARD, "ullong_fcomplex", native_ullong, native_float_complex,
1903
6
                                H5T__conv_ullong_fcomplex);
1904
6
    status |= H5T__register_int(H5T_PERS_HARD, "ullong_dcomplex", native_ullong, native_double_complex,
1905
6
                                H5T__conv_ullong_dcomplex);
1906
6
#ifdef H5T_CONV_INTERNAL_ULLONG_LDOUBLE
1907
6
    status |= H5T__register_int(H5T_PERS_HARD, "ullong_lcomplex", native_ullong, native_ldouble_complex,
1908
6
                                H5T__conv_ullong_lcomplex);
1909
6
#endif
1910
6
#endif
1911
1912
    /* From floats to char */
1913
6
    status |=
1914
6
        H5T__register_int(H5T_PERS_HARD, "flt_schar", native_float, native_schar, H5T__conv_float_schar);
1915
6
    status |=
1916
6
        H5T__register_int(H5T_PERS_HARD, "dbl_schar", native_double, native_schar, H5T__conv_double_schar);
1917
6
    status |=
1918
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_schar", native_ldouble, native_schar, H5T__conv_ldouble_schar);
1919
#ifdef H5_HAVE__FLOAT16
1920
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_schar", native_float16, native_schar,
1921
                                H5T__conv__Float16_schar);
1922
#endif
1923
1924
    /* From floats to unsigned char */
1925
6
    status |=
1926
6
        H5T__register_int(H5T_PERS_HARD, "flt_uchar", native_float, native_uchar, H5T__conv_float_uchar);
1927
6
    status |=
1928
6
        H5T__register_int(H5T_PERS_HARD, "dbl_uchar", native_double, native_uchar, H5T__conv_double_uchar);
1929
6
    status |=
1930
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_uchar", native_ldouble, native_uchar, H5T__conv_ldouble_uchar);
1931
#ifdef H5_HAVE__FLOAT16
1932
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_uchar", native_float16, native_uchar,
1933
                                H5T__conv__Float16_uchar);
1934
#endif
1935
1936
    /* From floats to short */
1937
6
    status |=
1938
6
        H5T__register_int(H5T_PERS_HARD, "flt_short", native_float, native_short, H5T__conv_float_short);
1939
6
    status |=
1940
6
        H5T__register_int(H5T_PERS_HARD, "dbl_short", native_double, native_short, H5T__conv_double_short);
1941
6
    status |=
1942
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_short", native_ldouble, native_short, H5T__conv_ldouble_short);
1943
#ifdef H5_HAVE__FLOAT16
1944
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_short", native_float16, native_short,
1945
                                H5T__conv__Float16_short);
1946
#endif
1947
1948
    /* From floats to unsigned short */
1949
6
    status |=
1950
6
        H5T__register_int(H5T_PERS_HARD, "flt_ushort", native_float, native_ushort, H5T__conv_float_ushort);
1951
6
    status |=
1952
6
        H5T__register_int(H5T_PERS_HARD, "dbl_ushort", native_double, native_ushort, H5T__conv_double_ushort);
1953
6
    status |= H5T__register_int(H5T_PERS_HARD, "ldbl_ushort", native_ldouble, native_ushort,
1954
6
                                H5T__conv_ldouble_ushort);
1955
#ifdef H5_HAVE__FLOAT16
1956
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_ushort", native_float16, native_ushort,
1957
                                H5T__conv__Float16_ushort);
1958
#endif
1959
1960
    /* From floats to int */
1961
6
    status |= H5T__register_int(H5T_PERS_HARD, "flt_int", native_float, native_int, H5T__conv_float_int);
1962
6
    status |= H5T__register_int(H5T_PERS_HARD, "dbl_int", native_double, native_int, H5T__conv_double_int);
1963
6
    status |= H5T__register_int(H5T_PERS_HARD, "ldbl_int", native_ldouble, native_int, H5T__conv_ldouble_int);
1964
#ifdef H5_HAVE__FLOAT16
1965
    status |=
1966
        H5T__register_int(H5T_PERS_HARD, "flt16_int", native_float16, native_int, H5T__conv__Float16_int);
1967
#endif
1968
1969
    /* From floats to unsigned int */
1970
6
    status |= H5T__register_int(H5T_PERS_HARD, "flt_uint", native_float, native_uint, H5T__conv_float_uint);
1971
6
    status |= H5T__register_int(H5T_PERS_HARD, "dbl_uint", native_double, native_uint, H5T__conv_double_uint);
1972
6
    status |=
1973
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_uint", native_ldouble, native_uint, H5T__conv_ldouble_uint);
1974
#ifdef H5_HAVE__FLOAT16
1975
    status |=
1976
        H5T__register_int(H5T_PERS_HARD, "flt16_uint", native_float16, native_uint, H5T__conv__Float16_uint);
1977
#endif
1978
1979
    /* From floats to long */
1980
6
    status |= H5T__register_int(H5T_PERS_HARD, "flt_long", native_float, native_long, H5T__conv_float_long);
1981
6
    status |= H5T__register_int(H5T_PERS_HARD, "dbl_long", native_double, native_long, H5T__conv_double_long);
1982
6
    status |=
1983
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_long", native_ldouble, native_long, H5T__conv_ldouble_long);
1984
#ifdef H5_HAVE__FLOAT16
1985
    status |=
1986
        H5T__register_int(H5T_PERS_HARD, "flt16_long", native_float16, native_long, H5T__conv__Float16_long);
1987
#endif
1988
1989
    /* From floats to unsigned long */
1990
6
    status |=
1991
6
        H5T__register_int(H5T_PERS_HARD, "flt_ulong", native_float, native_ulong, H5T__conv_float_ulong);
1992
6
    status |=
1993
6
        H5T__register_int(H5T_PERS_HARD, "dbl_ulong", native_double, native_ulong, H5T__conv_double_ulong);
1994
6
    status |=
1995
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_ulong", native_ldouble, native_ulong, H5T__conv_ldouble_ulong);
1996
#ifdef H5_HAVE__FLOAT16
1997
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_ulong", native_float16, native_ulong,
1998
                                H5T__conv__Float16_ulong);
1999
#endif
2000
2001
    /* From floats to long long */
2002
6
    status |=
2003
6
        H5T__register_int(H5T_PERS_HARD, "flt_llong", native_float, native_llong, H5T__conv_float_llong);
2004
6
    status |=
2005
6
        H5T__register_int(H5T_PERS_HARD, "dbl_llong", native_double, native_llong, H5T__conv_double_llong);
2006
6
#ifdef H5T_CONV_INTERNAL_LDOUBLE_LLONG
2007
6
    status |=
2008
6
        H5T__register_int(H5T_PERS_HARD, "ldbl_llong", native_ldouble, native_llong, H5T__conv_ldouble_llong);
2009
6
#endif /* H5T_CONV_INTERNAL_LDOUBLE_LLONG */
2010
#ifdef H5_HAVE__FLOAT16
2011
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_llong", native_float16, native_llong,
2012
                                H5T__conv__Float16_llong);
2013
#endif
2014
2015
    /* From floats to unsigned long long */
2016
6
    status |=
2017
6
        H5T__register_int(H5T_PERS_HARD, "flt_ullong", native_float, native_ullong, H5T__conv_float_ullong);
2018
6
    status |=
2019
6
        H5T__register_int(H5T_PERS_HARD, "dbl_ullong", native_double, native_ullong, H5T__conv_double_ullong);
2020
6
#ifdef H5T_CONV_INTERNAL_LDOUBLE_ULLONG
2021
6
    status |= H5T__register_int(H5T_PERS_HARD, "ldbl_ullong", native_ldouble, native_ullong,
2022
6
                                H5T__conv_ldouble_ullong);
2023
6
#endif /* H5T_CONV_INTERNAL_LDOUBLE_ULLONG */
2024
#ifdef H5_HAVE__FLOAT16
2025
    status |= H5T__register_int(H5T_PERS_HARD, "flt16_ullong", native_float16, native_ullong,
2026
                                H5T__conv__Float16_ullong);
2027
#endif
2028
2029
6
#ifdef H5_HAVE_COMPLEX_NUMBERS
2030
    /* From complex numbers to char */
2031
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_schar", native_float_complex, native_schar,
2032
6
                                H5T__conv_fcomplex_schar);
2033
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_schar", native_double_complex, native_schar,
2034
6
                                H5T__conv_dcomplex_schar);
2035
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_schar", native_ldouble_complex, native_schar,
2036
6
                                H5T__conv_lcomplex_schar);
2037
2038
    /* From complex numbers to unsigned char */
2039
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_uchar", native_float_complex, native_uchar,
2040
6
                                H5T__conv_fcomplex_uchar);
2041
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_uchar", native_double_complex, native_uchar,
2042
6
                                H5T__conv_dcomplex_uchar);
2043
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_uchar", native_ldouble_complex, native_uchar,
2044
6
                                H5T__conv_lcomplex_uchar);
2045
2046
    /* From complex numbers to short */
2047
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_short", native_float_complex, native_short,
2048
6
                                H5T__conv_fcomplex_short);
2049
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_short", native_double_complex, native_short,
2050
6
                                H5T__conv_dcomplex_short);
2051
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_short", native_ldouble_complex, native_short,
2052
6
                                H5T__conv_lcomplex_short);
2053
2054
    /* From complex numbers to unsigned short */
2055
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_ushort", native_float_complex, native_ushort,
2056
6
                                H5T__conv_fcomplex_ushort);
2057
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_ushort", native_double_complex, native_ushort,
2058
6
                                H5T__conv_dcomplex_ushort);
2059
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_ushort", native_ldouble_complex, native_ushort,
2060
6
                                H5T__conv_lcomplex_ushort);
2061
2062
    /* From complex numbers to int */
2063
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_int", native_float_complex, native_int,
2064
6
                                H5T__conv_fcomplex_int);
2065
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_int", native_double_complex, native_int,
2066
6
                                H5T__conv_dcomplex_int);
2067
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_int", native_ldouble_complex, native_int,
2068
6
                                H5T__conv_lcomplex_int);
2069
2070
    /* From complex numbers to unsigned int */
2071
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_uint", native_float_complex, native_uint,
2072
6
                                H5T__conv_fcomplex_uint);
2073
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_uint", native_double_complex, native_uint,
2074
6
                                H5T__conv_dcomplex_uint);
2075
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_uint", native_ldouble_complex, native_uint,
2076
6
                                H5T__conv_lcomplex_uint);
2077
2078
    /* From complex numbers to long */
2079
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_long", native_float_complex, native_long,
2080
6
                                H5T__conv_fcomplex_long);
2081
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_long", native_double_complex, native_long,
2082
6
                                H5T__conv_dcomplex_long);
2083
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_long", native_ldouble_complex, native_long,
2084
6
                                H5T__conv_lcomplex_long);
2085
2086
    /* From complex numbers to unsigned long */
2087
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_ulong", native_float_complex, native_ulong,
2088
6
                                H5T__conv_fcomplex_ulong);
2089
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_ulong", native_double_complex, native_ulong,
2090
6
                                H5T__conv_dcomplex_ulong);
2091
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_ulong", native_ldouble_complex, native_ulong,
2092
6
                                H5T__conv_lcomplex_ulong);
2093
2094
    /* From complex numbers to long long */
2095
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_llong", native_float_complex, native_llong,
2096
6
                                H5T__conv_fcomplex_llong);
2097
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_llong", native_double_complex, native_llong,
2098
6
                                H5T__conv_dcomplex_llong);
2099
6
#ifdef H5T_CONV_INTERNAL_LDOUBLE_LLONG
2100
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_llong", native_ldouble_complex, native_llong,
2101
6
                                H5T__conv_lcomplex_llong);
2102
6
#endif
2103
2104
    /* From complex numbers to unsigned long long */
2105
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_ullong", native_float_complex, native_ullong,
2106
6
                                H5T__conv_fcomplex_ullong);
2107
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_ullong", native_double_complex, native_ullong,
2108
6
                                H5T__conv_dcomplex_ullong);
2109
6
#ifdef H5T_CONV_INTERNAL_LDOUBLE_ULLONG
2110
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_ullong", native_ldouble_complex, native_ullong,
2111
6
                                H5T__conv_lcomplex_ullong);
2112
6
#endif
2113
2114
    /* From complex numbers to floats */
2115
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_flt", native_float_complex, native_float,
2116
6
                                H5T__conv_fcomplex_float);
2117
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_dbl", native_float_complex, native_double,
2118
6
                                H5T__conv_fcomplex_double);
2119
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_ldbl", native_float_complex, native_ldouble,
2120
6
                                H5T__conv_fcomplex_ldouble);
2121
#ifdef H5_HAVE__FLOAT16
2122
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_flt16", native_float_complex, native_float16,
2123
                                H5T__conv_fcomplex__Float16);
2124
#endif
2125
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_flt", native_double_complex, native_float,
2126
6
                                H5T__conv_dcomplex_float);
2127
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_dbl", native_double_complex, native_double,
2128
6
                                H5T__conv_dcomplex_double);
2129
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_ldbl", native_double_complex, native_ldouble,
2130
6
                                H5T__conv_dcomplex_ldouble);
2131
#ifdef H5_HAVE__FLOAT16
2132
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_flt16", native_double_complex, native_float16,
2133
                                H5T__conv_dcomplex__Float16);
2134
#endif
2135
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_flt", native_ldouble_complex, native_float,
2136
6
                                H5T__conv_lcomplex_float);
2137
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_dbl", native_ldouble_complex, native_double,
2138
6
                                H5T__conv_lcomplex_double);
2139
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_ldbl", native_ldouble_complex, native_ldouble,
2140
6
                                H5T__conv_lcomplex_ldouble);
2141
#if defined(H5_HAVE__FLOAT16) && defined(H5T_CONV_INTERNAL_LDOUBLE_FLOAT16)
2142
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_flt16", native_ldouble_complex, native_float16,
2143
                                H5T__conv_lcomplex__Float16);
2144
#endif
2145
2146
    /* From complex numbers to complex numbers */
2147
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_dcomplex", native_float_complex,
2148
6
                                native_double_complex, H5T__conv_fcomplex_dcomplex);
2149
6
    status |= H5T__register_int(H5T_PERS_HARD, "fcomplex_lcomplex", native_float_complex,
2150
6
                                native_ldouble_complex, H5T__conv_fcomplex_lcomplex);
2151
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_fcomplex", native_double_complex,
2152
6
                                native_float_complex, H5T__conv_dcomplex_fcomplex);
2153
6
    status |= H5T__register_int(H5T_PERS_HARD, "dcomplex_lcomplex", native_double_complex,
2154
6
                                native_ldouble_complex, H5T__conv_dcomplex_lcomplex);
2155
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_fcomplex", native_ldouble_complex,
2156
6
                                native_float_complex, H5T__conv_lcomplex_fcomplex);
2157
6
    status |= H5T__register_int(H5T_PERS_HARD, "lcomplex_dcomplex", native_ldouble_complex,
2158
6
                                native_double_complex, H5T__conv_lcomplex_dcomplex);
2159
6
#endif
2160
2161
    /*
2162
     * The special no-op conversion is the fastest, so we list it last. The
2163
     * data types we use are not important as long as the source and
2164
     * destination are equal.
2165
     */
2166
6
    status |= H5T__register_int(H5T_PERS_HARD, "no-op", native_int, native_int, H5T__conv_noop);
2167
2168
    /* Initialize the +/- Infinity values for floating-point types */
2169
6
    status |= H5T__init_inf();
2170
2171
6
    if (status < 0)
2172
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to register conversion function(s)");
2173
2174
    /* Register datatype creation property class properties here.  See similar
2175
     * code in H5D__init_package(), etc. for example.
2176
     */
2177
2178
    /* Only register the default property list if it hasn't been created yet */
2179
6
    if (H5P_LST_DATATYPE_CREATE_ID_g == (-1)) {
2180
        /* ========== Datatype Creation Property Class Initialization ============*/
2181
0
        assert(H5P_CLS_DATATYPE_CREATE_g != NULL);
2182
2183
        /* Register the default datatype creation property list */
2184
0
        if ((H5P_LST_DATATYPE_CREATE_ID_g = H5P_create_id(H5P_CLS_DATATYPE_CREATE_g, false)) < 0)
2185
0
            HGOTO_ERROR(H5E_PLIST, H5E_CANTREGISTER, FAIL, "can't insert property into class");
2186
0
    } /* end if */
2187
2188
    /* Mark "top" of interface as initialized, too */
2189
6
    H5T_top_package_initialize_s = true;
2190
2191
6
done:
2192
    /* General cleanup */
2193
6
    if (compound != NULL)
2194
6
        (void)H5T_close_real(compound);
2195
6
    if (enum_type != NULL)
2196
6
        (void)H5T_close_real(enum_type);
2197
6
    if (vlen != NULL)
2198
6
        (void)H5T_close_real(vlen);
2199
6
    if (array != NULL)
2200
6
        (void)H5T_close_real(array);
2201
6
    if (cplx != NULL)
2202
6
        (void)H5T_close_real(cplx);
2203
2204
    /* Error cleanup */
2205
6
    if (ret_value < 0) {
2206
0
        if (dt) {
2207
            /* Check if we should call H5T_close_real or H5FL_FREE */
2208
0
            if (copied_dtype)
2209
0
                (void)H5T_close_real(dt);
2210
0
            else {
2211
0
                if (dt->shared->owned_vol_obj && H5VL_free_object(dt->shared->owned_vol_obj) < 0)
2212
0
                    HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close owned VOL object");
2213
0
                dt->shared = H5FL_FREE(H5T_shared_t, dt->shared);
2214
0
                dt         = H5FL_FREE(H5T_t, dt);
2215
0
            } /* end else */
2216
0
        }     /* end if */
2217
0
    }         /* end if */
2218
2219
6
    FUNC_LEAVE_NOAPI(ret_value)
2220
6
} /* end H5T__init_package() */
2221
2222
/*-------------------------------------------------------------------------
2223
 * Function:   H5T__unlock_cb
2224
 *
2225
 * Purpose:    Clear the immutable flag for a datatype.  This function is
2226
 *             called when the library is closing in order to unlock all
2227
 *             registered datatypes and thus make them free-able.
2228
 *
2229
 * Return:     Non-negative on success/Negative on failure
2230
 *
2231
 *-------------------------------------------------------------------------
2232
 */
2233
static int
2234
H5T__unlock_cb(void *_dt, hid_t H5_ATTR_UNUSED id, void *_udata)
2235
3.85k
{
2236
3.85k
    H5T_t *dt = (H5T_t *)_dt;
2237
3.85k
    int   *n  = (int *)_udata;
2238
2239
3.85k
    FUNC_ENTER_PACKAGE_NOERR
2240
2241
3.85k
    assert(dt);
2242
2243
3.85k
    if (dt->shared && (H5T_STATE_IMMUTABLE == dt->shared->state)) {
2244
600
        dt->shared->state = H5T_STATE_RDONLY;
2245
600
        (*n)++;
2246
600
    }
2247
2248
3.85k
    FUNC_LEAVE_NOAPI(SUCCEED)
2249
3.85k
} /* end H5T__unlock_cb() */
2250
2251
/*-------------------------------------------------------------------------
2252
 * Function:   H5T_top_term_package
2253
 *
2254
 * Purpose:    Close the "top" of the interface, releasing IDs, etc.
2255
 *
2256
 * Return:     Success:    Positive if any action might have caused a
2257
 *                            change in some other interface; zero otherwise.
2258
 *             Failure:    Negative
2259
 *
2260
 *-------------------------------------------------------------------------
2261
 */
2262
int
2263
H5T_top_term_package(void)
2264
54
{
2265
54
    int n = 0;
2266
2267
54
    FUNC_ENTER_NOAPI_NOINIT_NOERR
2268
2269
24
    if (H5T_top_package_initialize_s) {
2270
        /* Unregister all conversion functions */
2271
12
        if (H5T_g.path) {
2272
6
            H5T_conv_ctx_t conv_ctx = {0};
2273
2274
6
            conv_ctx.u.free.src_type_id = H5I_INVALID_HID;
2275
6
            conv_ctx.u.free.dst_type_id = H5I_INVALID_HID;
2276
2277
1.87k
            for (int i = 0; i < H5T_g.npaths; i++) {
2278
1.86k
                H5T_path_t *path = H5T_g.path[i];
2279
2280
1.86k
                (void)H5T__path_free(path, &conv_ctx);
2281
2282
1.86k
                H5T_g.path[i] = NULL;
2283
1.86k
            } /* end for */
2284
2285
            /* Clear conversion tables */
2286
6
            H5T_g.path   = (H5T_path_t **)H5MM_xfree(H5T_g.path);
2287
6
            H5T_g.npaths = 0;
2288
6
            H5T_g.apaths = 0;
2289
6
            H5T_g.soft   = (H5T_soft_t *)H5MM_xfree(H5T_g.soft);
2290
6
            H5T_g.nsoft  = 0;
2291
6
            H5T_g.asoft  = 0;
2292
2293
6
            n++;
2294
6
        } /* end if */
2295
2296
        /* Unlock all datatypes, then free them */
2297
        /* note that we are ignoring the return value from H5I_iterate() */
2298
        /* Also note that we are incrementing 'n' in the callback */
2299
12
        H5I_iterate(H5I_DATATYPE, H5T__unlock_cb, &n, false);
2300
2301
        /* Release all datatype IDs */
2302
12
        if (H5I_nmembers(H5I_DATATYPE) > 0) {
2303
6
            (void)H5I_clear_type(H5I_DATATYPE, false, false);
2304
6
            n++; /*H5I*/
2305
6
        }        /* end if */
2306
2307
        /* Reset all the datatype IDs */
2308
12
        if (H5T_IEEE_F32BE_g > 0) {
2309
6
            H5T_IEEE_F16BE_g = H5I_INVALID_HID;
2310
6
            H5T_IEEE_F16LE_g = H5I_INVALID_HID;
2311
6
            H5T_IEEE_F32BE_g = H5I_INVALID_HID;
2312
6
            H5T_IEEE_F32LE_g = H5I_INVALID_HID;
2313
6
            H5T_IEEE_F64BE_g = H5I_INVALID_HID;
2314
6
            H5T_IEEE_F64LE_g = H5I_INVALID_HID;
2315
2316
6
            H5T_FLOAT_BFLOAT16BE_g = H5I_INVALID_HID;
2317
6
            H5T_FLOAT_BFLOAT16LE_g = H5I_INVALID_HID;
2318
6
            H5T_FLOAT_F8E4M3_g     = H5I_INVALID_HID;
2319
6
            H5T_FLOAT_F8E5M2_g     = H5I_INVALID_HID;
2320
6
            H5T_FLOAT_F6E2M3_g     = H5I_INVALID_HID;
2321
6
            H5T_FLOAT_F6E3M2_g     = H5I_INVALID_HID;
2322
6
            H5T_FLOAT_F4E2M1_g     = H5I_INVALID_HID;
2323
2324
6
            H5T_COMPLEX_IEEE_F16BE_g = H5I_INVALID_HID;
2325
6
            H5T_COMPLEX_IEEE_F16LE_g = H5I_INVALID_HID;
2326
6
            H5T_COMPLEX_IEEE_F32BE_g = H5I_INVALID_HID;
2327
6
            H5T_COMPLEX_IEEE_F32LE_g = H5I_INVALID_HID;
2328
6
            H5T_COMPLEX_IEEE_F64BE_g = H5I_INVALID_HID;
2329
6
            H5T_COMPLEX_IEEE_F64LE_g = H5I_INVALID_HID;
2330
2331
6
            H5T_STD_I8BE_g        = H5I_INVALID_HID;
2332
6
            H5T_STD_I8LE_g        = H5I_INVALID_HID;
2333
6
            H5T_STD_I16BE_g       = H5I_INVALID_HID;
2334
6
            H5T_STD_I16LE_g       = H5I_INVALID_HID;
2335
6
            H5T_STD_I32BE_g       = H5I_INVALID_HID;
2336
6
            H5T_STD_I32LE_g       = H5I_INVALID_HID;
2337
6
            H5T_STD_I64BE_g       = H5I_INVALID_HID;
2338
6
            H5T_STD_I64LE_g       = H5I_INVALID_HID;
2339
6
            H5T_STD_U8BE_g        = H5I_INVALID_HID;
2340
6
            H5T_STD_U8LE_g        = H5I_INVALID_HID;
2341
6
            H5T_STD_U16BE_g       = H5I_INVALID_HID;
2342
6
            H5T_STD_U16LE_g       = H5I_INVALID_HID;
2343
6
            H5T_STD_U32BE_g       = H5I_INVALID_HID;
2344
6
            H5T_STD_U32LE_g       = H5I_INVALID_HID;
2345
6
            H5T_STD_U64BE_g       = H5I_INVALID_HID;
2346
6
            H5T_STD_U64LE_g       = H5I_INVALID_HID;
2347
6
            H5T_STD_B8BE_g        = H5I_INVALID_HID;
2348
6
            H5T_STD_B8LE_g        = H5I_INVALID_HID;
2349
6
            H5T_STD_B16BE_g       = H5I_INVALID_HID;
2350
6
            H5T_STD_B16LE_g       = H5I_INVALID_HID;
2351
6
            H5T_STD_B32BE_g       = H5I_INVALID_HID;
2352
6
            H5T_STD_B32LE_g       = H5I_INVALID_HID;
2353
6
            H5T_STD_B64BE_g       = H5I_INVALID_HID;
2354
6
            H5T_STD_B64LE_g       = H5I_INVALID_HID;
2355
6
            H5T_STD_REF_OBJ_g     = H5I_INVALID_HID;
2356
6
            H5T_STD_REF_DSETREG_g = H5I_INVALID_HID;
2357
6
            H5T_STD_REF_g         = H5I_INVALID_HID;
2358
2359
6
            H5T_UNIX_D32BE_g = H5I_INVALID_HID;
2360
6
            H5T_UNIX_D32LE_g = H5I_INVALID_HID;
2361
6
            H5T_UNIX_D64BE_g = H5I_INVALID_HID;
2362
6
            H5T_UNIX_D64LE_g = H5I_INVALID_HID;
2363
2364
6
            H5T_C_S1_g = H5I_INVALID_HID;
2365
2366
6
            H5T_FORTRAN_S1_g = H5I_INVALID_HID;
2367
2368
6
            H5T_NATIVE_SCHAR_g           = H5I_INVALID_HID;
2369
6
            H5T_NATIVE_UCHAR_g           = H5I_INVALID_HID;
2370
6
            H5T_NATIVE_SHORT_g           = H5I_INVALID_HID;
2371
6
            H5T_NATIVE_USHORT_g          = H5I_INVALID_HID;
2372
6
            H5T_NATIVE_INT_g             = H5I_INVALID_HID;
2373
6
            H5T_NATIVE_UINT_g            = H5I_INVALID_HID;
2374
6
            H5T_NATIVE_LONG_g            = H5I_INVALID_HID;
2375
6
            H5T_NATIVE_ULONG_g           = H5I_INVALID_HID;
2376
6
            H5T_NATIVE_LLONG_g           = H5I_INVALID_HID;
2377
6
            H5T_NATIVE_ULLONG_g          = H5I_INVALID_HID;
2378
6
            H5T_NATIVE_FLOAT16_g         = H5I_INVALID_HID;
2379
6
            H5T_NATIVE_FLOAT_g           = H5I_INVALID_HID;
2380
6
            H5T_NATIVE_DOUBLE_g          = H5I_INVALID_HID;
2381
6
            H5T_NATIVE_LDOUBLE_g         = H5I_INVALID_HID;
2382
6
            H5T_NATIVE_FLOAT_COMPLEX_g   = H5I_INVALID_HID;
2383
6
            H5T_NATIVE_DOUBLE_COMPLEX_g  = H5I_INVALID_HID;
2384
6
            H5T_NATIVE_LDOUBLE_COMPLEX_g = H5I_INVALID_HID;
2385
6
            H5T_NATIVE_B8_g              = H5I_INVALID_HID;
2386
6
            H5T_NATIVE_B16_g             = H5I_INVALID_HID;
2387
6
            H5T_NATIVE_B32_g             = H5I_INVALID_HID;
2388
6
            H5T_NATIVE_B64_g             = H5I_INVALID_HID;
2389
6
            H5T_NATIVE_OPAQUE_g          = H5I_INVALID_HID;
2390
6
            H5T_NATIVE_HADDR_g           = H5I_INVALID_HID;
2391
6
            H5T_NATIVE_HSIZE_g           = H5I_INVALID_HID;
2392
6
            H5T_NATIVE_HSSIZE_g          = H5I_INVALID_HID;
2393
6
            H5T_NATIVE_HERR_g            = H5I_INVALID_HID;
2394
6
            H5T_NATIVE_HBOOL_g           = H5I_INVALID_HID;
2395
2396
6
            H5T_NATIVE_INT8_g        = H5I_INVALID_HID;
2397
6
            H5T_NATIVE_UINT8_g       = H5I_INVALID_HID;
2398
6
            H5T_NATIVE_INT_LEAST8_g  = H5I_INVALID_HID;
2399
6
            H5T_NATIVE_UINT_LEAST8_g = H5I_INVALID_HID;
2400
6
            H5T_NATIVE_INT_FAST8_g   = H5I_INVALID_HID;
2401
6
            H5T_NATIVE_UINT_FAST8_g  = H5I_INVALID_HID;
2402
2403
6
            H5T_NATIVE_INT16_g        = H5I_INVALID_HID;
2404
6
            H5T_NATIVE_UINT16_g       = H5I_INVALID_HID;
2405
6
            H5T_NATIVE_INT_LEAST16_g  = H5I_INVALID_HID;
2406
6
            H5T_NATIVE_UINT_LEAST16_g = H5I_INVALID_HID;
2407
6
            H5T_NATIVE_INT_FAST16_g   = H5I_INVALID_HID;
2408
6
            H5T_NATIVE_UINT_FAST16_g  = H5I_INVALID_HID;
2409
2410
6
            H5T_NATIVE_INT32_g        = H5I_INVALID_HID;
2411
6
            H5T_NATIVE_UINT32_g       = H5I_INVALID_HID;
2412
6
            H5T_NATIVE_INT_LEAST32_g  = H5I_INVALID_HID;
2413
6
            H5T_NATIVE_UINT_LEAST32_g = H5I_INVALID_HID;
2414
6
            H5T_NATIVE_INT_FAST32_g   = H5I_INVALID_HID;
2415
6
            H5T_NATIVE_UINT_FAST32_g  = H5I_INVALID_HID;
2416
2417
6
            H5T_NATIVE_INT64_g        = H5I_INVALID_HID;
2418
6
            H5T_NATIVE_UINT64_g       = H5I_INVALID_HID;
2419
6
            H5T_NATIVE_INT_LEAST64_g  = H5I_INVALID_HID;
2420
6
            H5T_NATIVE_UINT_LEAST64_g = H5I_INVALID_HID;
2421
6
            H5T_NATIVE_INT_FAST64_g   = H5I_INVALID_HID;
2422
6
            H5T_NATIVE_UINT_FAST64_g  = H5I_INVALID_HID;
2423
2424
6
            n++;
2425
6
        } /* end if */
2426
2427
        /* Mark "top" of interface as closed */
2428
12
        if (0 == n)
2429
6
            H5T_top_package_initialize_s = false;
2430
12
    } /* end if */
2431
2432
24
    FUNC_LEAVE_NOAPI(n)
2433
54
} /* end H5T_top_term_package() */
2434
2435
/*-------------------------------------------------------------------------
2436
 * Function:   H5T_term_package
2437
 *
2438
 * Purpose:    Close this interface.
2439
 *
2440
 * Note:    Finishes shutting down the interface, after
2441
 *          H5T_top_term_package() is called
2442
 *
2443
 * Return:   Success:    Positive if any action might have caused a
2444
 *                change in some other interface; zero
2445
 *                otherwise.
2446
 *           Failure:    Negative
2447
 *
2448
 *-------------------------------------------------------------------------
2449
 */
2450
int
2451
H5T_term_package(void)
2452
36
{
2453
36
    int n = 0;
2454
2455
36
    FUNC_ENTER_NOAPI_NOINIT_NOERR
2456
2457
6
    if (H5_PKG_INIT_VAR) {
2458
        /* Sanity check */
2459
6
        assert(0 == H5I_nmembers(H5I_DATATYPE));
2460
6
        assert(false == H5T_top_package_initialize_s);
2461
2462
        /* Destroy the datatype object id group */
2463
6
        n += (H5I_dec_type_ref(H5I_DATATYPE) > 0);
2464
2465
        /* Mark interface as closed */
2466
6
        if (0 == n)
2467
6
            H5_PKG_INIT_VAR = false;
2468
6
    } /* end if */
2469
2470
6
    FUNC_LEAVE_NOAPI(n)
2471
36
} /* end H5T_term_package() */
2472
2473
/*-------------------------------------------------------------------------
2474
 * Function:    H5T__close_cb
2475
 *
2476
 * Purpose:     Called when the ref count reaches zero on the datatype's ID
2477
 *
2478
 * Return:      SUCCEED/FAIL
2479
 *
2480
 *-------------------------------------------------------------------------
2481
 */
2482
static herr_t
2483
H5T__close_cb(void *dt, void **request)
2484
275k
{
2485
275k
    H5T_t *dt_p      = (H5T_t *)dt;
2486
275k
    herr_t ret_value = SUCCEED; /* Return value */
2487
2488
275k
    FUNC_ENTER_PACKAGE
2489
2490
    /* Sanity check */
2491
275k
    assert(dt_p);
2492
2493
    /* If this datatype is VOL-managed (i.e.: has a VOL object),
2494
     * close it through the VOL connector.
2495
     */
2496
275k
    if (NULL != dt_p->vol_obj) {
2497
        /* Close the connector-managed datatype data */
2498
3.22k
        if (H5VL_datatype_close(dt_p->vol_obj, H5P_DATASET_XFER_DEFAULT, request) < 0)
2499
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to close datatype");
2500
2501
        /* Free the VOL object */
2502
3.22k
        if (H5VL_free_object(dt_p->vol_obj) < 0)
2503
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to free VOL object");
2504
3.22k
        dt_p->vol_obj = NULL;
2505
3.22k
    } /* end if */
2506
2507
    /* Close the datatype */
2508
275k
    if (H5T_close(dt_p) < 0)
2509
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to close datatype");
2510
2511
275k
done:
2512
275k
    FUNC_LEAVE_NOAPI(ret_value)
2513
275k
} /* end H5T__close_cb() */
2514
2515
/*-------------------------------------------------------------------------
2516
 * Function:   H5Tcreate
2517
 *
2518
 * Purpose:    Create a new type and initialize it to reasonable values.
2519
 *             The type is a member of type class TYPE and is SIZE bytes.
2520
 *
2521
 * Return:    Success:    A new type identifier.
2522
 *
2523
 *            Failure:    Negative
2524
 *
2525
 * Errors:
2526
 *        ARGS      BADVALUE    Invalid size.
2527
 *        DATATYPE  CANTINIT    Can't create type.
2528
 *        DATATYPE  CANTREGISTER    Can't register datatype ID.
2529
 *
2530
 *-------------------------------------------------------------------------
2531
 */
2532
hid_t
2533
H5Tcreate(H5T_class_t type, size_t size)
2534
0
{
2535
0
    H5T_t *dt = NULL; /* New datatype constructed */
2536
0
    hid_t  ret_value; /* Return value */
2537
2538
0
    FUNC_ENTER_API(H5I_INVALID_HID)
2539
2540
    /* check args. We support string (fixed-size or variable-length) now. */
2541
0
    if (size <= 0 && size != H5T_VARIABLE)
2542
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "size must be positive");
2543
2544
    /* create the type */
2545
0
    if (NULL == (dt = H5T__create(type, size)))
2546
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5I_INVALID_HID, "unable to create type");
2547
2548
    /* Get an ID for the datatype */
2549
0
    if ((ret_value = H5I_register(H5I_DATATYPE, dt, true)) < 0)
2550
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register datatype ID");
2551
2552
0
done:
2553
0
    FUNC_LEAVE_API(ret_value)
2554
0
} /* end H5Tcreate() */
2555
2556
/*-------------------------------------------------------------------------
2557
 * Function:    H5Tcopy
2558
 *
2559
 * Purpose:     Copies a datatype.  The resulting datatype is not locked.
2560
 *              The datatype should be closed when no longer needed by
2561
 *              calling H5Tclose().
2562
 *
2563
 * Return:      Success:    The ID of a new datatype
2564
 *
2565
 *              Failure:    H5I_INVALID_HID
2566
 *
2567
 * Note:        The returned type is always transient and unlocked. If the
2568
 *              TYPE_ID argument is a dataset instead of a datatype then
2569
 *              this function returns a transient, modifiable datatype
2570
 *              which is a copy of the dataset's datatype.
2571
 *
2572
 *-------------------------------------------------------------------------
2573
 */
2574
hid_t
2575
H5Tcopy(hid_t obj_id)
2576
57.6k
{
2577
57.6k
    H5T_t *dt        = NULL;            /* Pointer to the datatype to copy */
2578
57.6k
    H5T_t *new_dt    = NULL;            /* Pointer to the new datatype */
2579
57.6k
    hid_t  dset_tid  = H5I_INVALID_HID; /* Datatype ID from dataset */
2580
57.6k
    hid_t  ret_value = H5I_INVALID_HID; /* Return value */
2581
2582
115k
    FUNC_ENTER_API(H5I_INVALID_HID)
2583
2584
115k
    switch (H5I_get_type(obj_id)) {
2585
57.6k
        case H5I_DATATYPE:
2586
            /* The argument is a datatype handle */
2587
57.6k
            if (NULL == (dt = (H5T_t *)H5I_object(obj_id)))
2588
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "obj_id is not a datatype ID");
2589
57.6k
            break;
2590
2591
57.6k
        case H5I_DATASET: {
2592
0
            H5VL_object_t          *vol_obj;     /* Object for obj_id */
2593
0
            H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */
2594
2595
            /* The argument is a dataset handle */
2596
0
            if (NULL == (vol_obj = (H5VL_object_t *)H5I_object_verify(obj_id, H5I_DATASET)))
2597
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "type_id is not a dataset ID");
2598
2599
            /* Set up VOL callback arguments */
2600
0
            vol_cb_args.op_type               = H5VL_DATASET_GET_TYPE;
2601
0
            vol_cb_args.args.get_type.type_id = H5I_INVALID_HID;
2602
2603
            /* Get the datatype from the dataset
2604
             * NOTE: This will have to be closed after we're done with it.
2605
             */
2606
0
            if (H5VL_dataset_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
2607
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID,
2608
0
                            "unable to get datatype from the dataset");
2609
0
            dset_tid = vol_cb_args.args.get_type.type_id;
2610
2611
            /* Unwrap the type ID */
2612
0
            if (NULL == (dt = (H5T_t *)H5I_object(dset_tid)))
2613
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, H5I_INVALID_HID,
2614
0
                            "received invalid datatype from the dataset");
2615
0
        } break;
2616
2617
0
        case H5I_UNINIT:
2618
0
        case H5I_BADID:
2619
0
        case H5I_FILE:
2620
0
        case H5I_GROUP:
2621
0
        case H5I_DATASPACE:
2622
0
        case H5I_ATTR:
2623
0
        case H5I_MAP:
2624
0
        case H5I_VFL:
2625
0
        case H5I_VOL:
2626
0
        case H5I_GENPROP_CLS:
2627
0
        case H5I_GENPROP_LST:
2628
0
        case H5I_ERROR_CLASS:
2629
0
        case H5I_ERROR_MSG:
2630
0
        case H5I_ERROR_STACK:
2631
0
        case H5I_SPACE_SEL_ITER:
2632
0
        case H5I_EVENTSET:
2633
0
        case H5I_NTYPES:
2634
0
        default:
2635
0
            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a datatype or dataset");
2636
115k
    } /* end switch */
2637
2638
    /* Copy datatype */
2639
57.6k
    if (NULL == (new_dt = H5T_copy(dt, H5T_COPY_TRANSIENT)))
2640
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5I_INVALID_HID, "unable to copy");
2641
2642
    /* Get an ID for the copied datatype */
2643
57.6k
    if ((ret_value = H5I_register(H5I_DATATYPE, new_dt, true)) < 0)
2644
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register datatype atom");
2645
2646
57.6k
done:
2647
2648
    /* If we got a type ID from a passed-in dataset, we need to close that */
2649
57.6k
    if (dset_tid != H5I_INVALID_HID)
2650
0
        if (H5I_dec_app_ref(dset_tid) < 0)
2651
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_BADID, FAIL, "problem freeing temporary dataset type ID");
2652
2653
    /* Close the new datatype on errors */
2654
57.6k
    if (H5I_INVALID_HID == ret_value)
2655
0
        if (new_dt && H5T_close_real(new_dt) < 0)
2656
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, H5I_INVALID_HID, "unable to release datatype info");
2657
2658
57.6k
    FUNC_LEAVE_API(ret_value)
2659
57.6k
} /* end H5Tcopy() */
2660
2661
/*-------------------------------------------------------------------------
2662
 * Function:    H5Tclose
2663
 *
2664
 * Purpose:     Frees a datatype and all associated memory.
2665
 *
2666
 * Return:      Non-negative on success/Negative on failure
2667
 *
2668
 *-------------------------------------------------------------------------
2669
 */
2670
herr_t
2671
H5Tclose(hid_t type_id)
2672
215k
{
2673
215k
    H5T_t *dt;                  /* Pointer to datatype to close */
2674
215k
    herr_t ret_value = SUCCEED; /* Return value */
2675
2676
430k
    FUNC_ENTER_API(FAIL)
2677
2678
    /* Check args */
2679
430k
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
2680
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
2681
215k
    if (H5T_STATE_IMMUTABLE == dt->shared->state)
2682
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "immutable datatype");
2683
2684
    /* When the reference count reaches zero the resources are freed */
2685
215k
    if (H5I_dec_app_ref(type_id) < 0)
2686
0
        HGOTO_ERROR(H5E_ID, H5E_BADID, FAIL, "problem freeing id");
2687
2688
215k
done:
2689
215k
    FUNC_LEAVE_API(ret_value)
2690
215k
} /* end H5Tclose() */
2691
2692
/*-------------------------------------------------------------------------
2693
 * Function:    H5Tclose_async
2694
 *
2695
 * Purpose:     Asynchronous version of H5Tclose.
2696
 *
2697
 * Return:      Non-negative on success/Negative on failure
2698
 *
2699
 *-------------------------------------------------------------------------
2700
 */
2701
herr_t
2702
H5Tclose_async(const char *app_file, const char *app_func, unsigned app_line, hid_t type_id, hid_t es_id)
2703
0
{
2704
0
    H5T_t            *dt;                          /* Pointer to datatype to close */
2705
0
    void             *token     = NULL;            /* Request token for async operation        */
2706
0
    void            **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation        */
2707
0
    H5VL_object_t    *vol_obj   = NULL;            /* VOL object of dset_id */
2708
0
    H5VL_connector_t *connector = NULL;            /* VOL connector */
2709
0
    herr_t            ret_value = SUCCEED;         /* Return value */
2710
2711
0
    FUNC_ENTER_API(FAIL)
2712
2713
    /* Check args */
2714
0
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
2715
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
2716
0
    if (H5T_STATE_IMMUTABLE == dt->shared->state)
2717
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "immutable datatype");
2718
2719
    /* Get dataset object's connector */
2720
0
    if (NULL == (vol_obj = H5VL_vol_object(type_id)))
2721
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get VOL object for dataset");
2722
2723
    /* Prepare for possible asynchronous operation */
2724
0
    if (H5ES_NONE != es_id) {
2725
        /* Increase connector's refcount, so it doesn't get closed if closing
2726
         * the dataset closes the file */
2727
0
        connector = H5VL_OBJ_CONNECTOR(vol_obj);
2728
0
        H5VL_conn_inc_rc(connector);
2729
2730
        /* Point at token for operation to set up */
2731
0
        token_ptr = &token;
2732
0
    } /* end if */
2733
2734
    /* When the reference count reaches zero the resources are freed */
2735
0
    if (H5I_dec_app_ref_async(type_id, token_ptr) < 0)
2736
0
        HGOTO_ERROR(H5E_ID, H5E_BADID, FAIL, "problem freeing id");
2737
2738
    /* If a token was created, add the token to the event set */
2739
0
    if (NULL != token)
2740
0
        if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token,
2741
0
                        H5ARG_TRACE5(__func__, "*s*sIuii", app_file, app_func, app_line, type_id, es_id)) < 0)
2742
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "can't insert token into event set");
2743
2744
0
done:
2745
0
    if (connector && H5VL_conn_dec_rc(connector) < 0)
2746
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement ref count on connector");
2747
2748
0
    FUNC_LEAVE_API(ret_value)
2749
0
} /* end H5Tclose_async() */
2750
2751
/*-------------------------------------------------------------------------
2752
 * Function:  H5Tequal
2753
 *
2754
 * Purpose:   Determines if two datatypes are equal.
2755
 *
2756
 * Return:    Success:    true if equal, false if unequal
2757
 *
2758
 *            Failure:    Negative
2759
 *
2760
 *-------------------------------------------------------------------------
2761
 */
2762
htri_t
2763
H5Tequal(hid_t type1_id, hid_t type2_id)
2764
0
{
2765
0
    const H5T_t *dt1;       /* Pointer to first datatype */
2766
0
    const H5T_t *dt2;       /* Pointer to second datatype */
2767
0
    htri_t       ret_value; /* Return value */
2768
2769
0
    FUNC_ENTER_API(FAIL)
2770
2771
    /* check args */
2772
0
    if (NULL == (dt1 = (H5T_t *)H5I_object_verify(type1_id, H5I_DATATYPE)))
2773
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
2774
0
    if (NULL == (dt2 = (H5T_t *)H5I_object_verify(type2_id, H5I_DATATYPE)))
2775
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
2776
2777
0
    ret_value = (0 == H5T_cmp(dt1, dt2, false)) ? true : false;
2778
2779
0
done:
2780
0
    FUNC_LEAVE_API(ret_value)
2781
0
} /* end H5Tequal() */
2782
2783
/*-------------------------------------------------------------------------
2784
 * Function:    H5Tlock
2785
 *
2786
 * Purpose:    Locks a type, making it read only and non-destructable.
2787
 *        This is normally done by the library for predefined datatypes so
2788
 *        the application doesn't inadvertently change or delete a
2789
 *        predefined type.
2790
 *
2791
 *        Once a datatype is locked it can never be unlocked unless
2792
 *        the entire library is closed.
2793
 *
2794
 * Return:    Non-negative on success/Negative on failure
2795
 *
2796
 *-------------------------------------------------------------------------
2797
 */
2798
herr_t
2799
H5Tlock(hid_t type_id)
2800
0
{
2801
0
    H5T_t *dt;                  /* Datatype to operate on */
2802
0
    herr_t ret_value = SUCCEED; /* Return value */
2803
2804
0
    FUNC_ENTER_API(FAIL)
2805
2806
    /* Check args */
2807
0
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
2808
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
2809
0
    if (H5T_STATE_NAMED == dt->shared->state || H5T_STATE_OPEN == dt->shared->state)
2810
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to lock named datatype");
2811
2812
0
    if (H5T_lock(dt, true) < 0)
2813
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to lock transient datatype");
2814
2815
0
done:
2816
0
    FUNC_LEAVE_API(ret_value)
2817
0
} /* end H5Tlock() */
2818
2819
/*-------------------------------------------------------------------------
2820
 * Function:  H5Tget_class
2821
 *
2822
 * Purpose:   Returns the datatype class identifier for datatype TYPE_ID.
2823
 *
2824
 * Return:    Success:    One of the non-negative datatype class constants.
2825
 *
2826
 *            Failure:    H5T_NO_CLASS (Negative)
2827
 *
2828
 *-------------------------------------------------------------------------
2829
 */
2830
H5T_class_t
2831
H5Tget_class(hid_t type_id)
2832
158k
{
2833
158k
    H5T_t      *dt;        /* Pointer to datatype */
2834
158k
    H5T_class_t ret_value; /* Return value */
2835
2836
316k
    FUNC_ENTER_API(H5T_NO_CLASS)
2837
2838
    /* Check args */
2839
316k
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
2840
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NO_CLASS, "not a datatype");
2841
2842
    /* Set return value */
2843
158k
    ret_value = H5T_get_class(dt, false);
2844
2845
158k
done:
2846
158k
    FUNC_LEAVE_API(ret_value)
2847
158k
} /* end H5Tget_class() */
2848
2849
/*-------------------------------------------------------------------------
2850
 * Function:  H5T_get_class
2851
 *
2852
 * Purpose:   Returns the data type class identifier for a datatype ptr.
2853
 *
2854
 * Return:    Success:    One of the non-negative data type class constants.
2855
 *
2856
 *            Failure:    H5T_NO_CLASS (Negative)
2857
 *
2858
 *-------------------------------------------------------------------------
2859
 */
2860
H5T_class_t
2861
H5T_get_class(const H5T_t *dt, htri_t internal)
2862
158k
{
2863
158k
    H5T_class_t ret_value = H5T_NO_CLASS; /* Return value */
2864
2865
158k
    FUNC_ENTER_NOAPI(H5T_NO_CLASS)
2866
2867
158k
    assert(dt);
2868
2869
    /* Externally, a VL string is a string; internally, a VL string is a VL. */
2870
158k
    if (internal) {
2871
0
        ret_value = dt->shared->type;
2872
0
    }
2873
158k
    else {
2874
158k
        if (H5T_IS_VL_STRING(dt->shared))
2875
9
            ret_value = H5T_STRING;
2876
158k
        else
2877
158k
            ret_value = dt->shared->type;
2878
158k
    }
2879
2880
158k
done:
2881
158k
    FUNC_LEAVE_NOAPI(ret_value)
2882
158k
} /* end H5T_get_class() */
2883
2884
/*-------------------------------------------------------------------------
2885
 * Function:   H5Tdetect_class
2886
 *
2887
 * Purpose:    Check whether a datatype contains (or is) a certain type of
2888
 *             datatype.
2889
 *
2890
 * Return:     true (1) or false (0) on success/Negative on failure
2891
 *
2892
 *-------------------------------------------------------------------------
2893
 */
2894
htri_t
2895
H5Tdetect_class(hid_t type, H5T_class_t cls)
2896
0
{
2897
0
    H5T_t *dt;        /* Datatype to query */
2898
0
    htri_t ret_value; /* Return value */
2899
2900
0
    FUNC_ENTER_API(FAIL)
2901
2902
    /* Check args */
2903
0
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
2904
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NO_CLASS, "not a datatype");
2905
0
    if (!(cls > H5T_NO_CLASS && cls < H5T_NCLASSES))
2906
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NO_CLASS, "not a datatype class");
2907
2908
    /* Set return value */
2909
0
    if ((ret_value = H5T_detect_class(dt, cls, true)) < 0)
2910
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5T_NO_CLASS, "can't get datatype class");
2911
2912
0
done:
2913
0
    FUNC_LEAVE_API(ret_value)
2914
0
} /* end H5Tdetect_class() */
2915
2916
/*-------------------------------------------------------------------------
2917
 * Function:   H5T_detect_class
2918
 *
2919
 * Purpose:    Check whether a datatype contains (or is) a certain type of
2920
 *             datatype.
2921
 *
2922
 * Return:     true (1) or false (0) on success/Negative on failure
2923
 *
2924
 *-------------------------------------------------------------------------
2925
 */
2926
htri_t
2927
H5T_detect_class(const H5T_t *dt, H5T_class_t cls, bool from_api)
2928
37.9k
{
2929
37.9k
    unsigned i;
2930
37.9k
    htri_t   ret_value = false; /* Return value */
2931
2932
37.9k
    FUNC_ENTER_NOAPI(FAIL)
2933
2934
37.9k
    assert(dt);
2935
37.9k
    assert(cls > H5T_NO_CLASS && cls < H5T_NCLASSES);
2936
2937
    /* Consider VL string as a string for API, as a VL for internal use. */
2938
    /* (note that this check must be performed before checking if the VL
2939
     *  string belongs to the H5T_VLEN class, which would otherwise return
2940
     *  true. -QAK)
2941
     */
2942
37.9k
    if (from_api && H5T_IS_VL_STRING(dt->shared))
2943
0
        HGOTO_DONE(H5T_STRING == cls);
2944
2945
    /* Check if this type is the correct type */
2946
37.9k
    if (dt->shared->type == cls)
2947
10.7k
        HGOTO_DONE(true);
2948
2949
    /* check for types that might have the correct type as a component */
2950
27.1k
    switch (dt->shared->type) {
2951
0
        case H5T_COMPOUND:
2952
0
            for (i = 0; i < dt->shared->u.compnd.nmembs; i++) {
2953
0
                htri_t nested_ret; /* Return value from nested call */
2954
2955
                /* Check if this field's type is the correct type */
2956
0
                if (dt->shared->u.compnd.memb[i].type->shared->type == cls)
2957
0
                    HGOTO_DONE(true);
2958
2959
                /* Recurse if it's VL, compound, enum or array */
2960
0
                if (H5T_IS_COMPOSITE(dt->shared->u.compnd.memb[i].type->shared->type))
2961
0
                    if ((nested_ret = H5T_detect_class(dt->shared->u.compnd.memb[i].type, cls, from_api)) !=
2962
0
                        false)
2963
0
                        HGOTO_DONE(nested_ret);
2964
0
            } /* end for */
2965
0
            break;
2966
2967
0
        case H5T_ARRAY:
2968
0
        case H5T_VLEN:
2969
0
        case H5T_ENUM:
2970
0
            HGOTO_DONE(H5T_detect_class(dt->shared->parent, cls, from_api));
2971
0
            break;
2972
0
        case H5T_COMPLEX:
2973
0
            HGOTO_DONE(H5T_detect_class(dt->shared->parent, cls, from_api));
2974
0
            break;
2975
0
        case H5T_NO_CLASS:
2976
0
        case H5T_INTEGER:
2977
0
        case H5T_FLOAT:
2978
0
        case H5T_TIME:
2979
5.66k
        case H5T_STRING:
2980
5.66k
        case H5T_BITFIELD:
2981
5.69k
        case H5T_OPAQUE:
2982
27.1k
        case H5T_REFERENCE:
2983
27.1k
        case H5T_NCLASSES:
2984
27.1k
        default:
2985
27.1k
            break;
2986
27.1k
    } /* end if */
2987
2988
37.9k
done:
2989
37.9k
    FUNC_LEAVE_NOAPI(ret_value)
2990
37.9k
} /* end H5T_detect_class() */
2991
2992
/*-------------------------------------------------------------------------
2993
 * Function:  H5Tis_variable_str
2994
 *
2995
 * Purpose:   Check whether a datatype is a variable-length string
2996
 *
2997
 * Return:    true (1) or false (0) on success/Negative on failure
2998
 *
2999
 *-------------------------------------------------------------------------
3000
 */
3001
htri_t
3002
H5Tis_variable_str(hid_t dtype_id)
3003
57.6k
{
3004
57.6k
    H5T_t *dt;        /* Datatype to query */
3005
57.6k
    htri_t ret_value; /* Return value */
3006
3007
115k
    FUNC_ENTER_API(FAIL)
3008
3009
    /* Check args */
3010
115k
    if (NULL == (dt = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE)))
3011
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
3012
3013
    /* Set return value */
3014
57.6k
    if ((ret_value = H5T_is_variable_str(dt)) < 0)
3015
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "can't determine if datatype is VL-string");
3016
3017
57.6k
done:
3018
57.6k
    FUNC_LEAVE_API(ret_value)
3019
57.6k
} /* end H5Tis_variable_str() */
3020
3021
/*-------------------------------------------------------------------------
3022
 * Function:  H5T_is_variable_str
3023
 *
3024
 * Purpose:   Check whether a datatype is a variable-length string
3025
 *
3026
 * Return:    true (1) or false (0) on success/Negative on failure
3027
 *
3028
 *-------------------------------------------------------------------------
3029
 */
3030
htri_t
3031
H5T_is_variable_str(const H5T_t *dt)
3032
57.6k
{
3033
57.6k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
3034
3035
57.6k
    FUNC_LEAVE_NOAPI(H5T_IS_VL_STRING(dt->shared))
3036
57.6k
} /* end H5T_is_variable_str() */
3037
3038
/*-------------------------------------------------------------------------
3039
 * Function:  H5Tget_size
3040
 *
3041
 * Purpose:   Determines the total size of a datatype in bytes.
3042
 *
3043
 * Return:    Success:    Size of the datatype in bytes.     The size of
3044
 *                datatype is the size of an instance of that
3045
 *                datatype.
3046
 *
3047
 *            Failure:    0 (valid datatypes are never zero size)
3048
 *
3049
 *-------------------------------------------------------------------------
3050
 */
3051
size_t
3052
H5Tget_size(hid_t type_id)
3053
99.1k
{
3054
99.1k
    H5T_t *dt;        /* Datatype to query */
3055
99.1k
    size_t ret_value; /* Return value */
3056
3057
198k
    FUNC_ENTER_API(0)
3058
3059
    /* Check args */
3060
198k
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
3061
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a datatype");
3062
3063
    /* size */
3064
99.1k
    ret_value = H5T_GET_SIZE(dt);
3065
3066
99.1k
done:
3067
99.1k
    FUNC_LEAVE_API(ret_value)
3068
99.1k
} /* end H5Tget_size() */
3069
3070
/*-------------------------------------------------------------------------
3071
 * Function:    H5Tset_size
3072
 *
3073
 * Purpose:    Sets the total size in bytes for a datatype (this operation
3074
 *        is not permitted on reference datatypes).  If the size is
3075
 *        decreased so that the significant bits of the datatype
3076
 *        extend beyond the edge of the new size, then the `offset'
3077
 *        property is decreased toward zero.  If the `offset' becomes
3078
 *        zero and the significant bits of the datatype still hang
3079
 *        over the edge of the new size, then the number of significant
3080
 *        bits is decreased.
3081
 *
3082
 *        Adjusting the size of an H5T_STRING automatically sets the
3083
 *        precision to 8*size.
3084
 *
3085
 *        All datatypes have a positive size.
3086
 *
3087
 * Return:    Non-negative on success/Negative on failure
3088
 *
3089
 *-------------------------------------------------------------------------
3090
 */
3091
herr_t
3092
H5Tset_size(hid_t type_id, size_t size)
3093
57.6k
{
3094
57.6k
    H5T_t *dt;                  /* Datatype to modify */
3095
57.6k
    herr_t ret_value = SUCCEED; /* Return value */
3096
3097
115k
    FUNC_ENTER_API(FAIL)
3098
3099
    /* Check args */
3100
115k
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
3101
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
3102
57.6k
    if (H5T_STATE_TRANSIENT != dt->shared->state)
3103
0
        HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only");
3104
57.6k
    if (size <= 0 && size != H5T_VARIABLE)
3105
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size must be positive");
3106
57.6k
    if (size == H5T_VARIABLE && !H5T_IS_STRING(dt->shared))
3107
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "only strings may be variable length");
3108
57.6k
    if (H5T_ENUM == dt->shared->type && dt->shared->u.enumer.nmembs > 0)
3109
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined");
3110
57.6k
    if (H5T_ARRAY == dt->shared->type || H5T_REFERENCE == dt->shared->type || H5T_COMPLEX == dt->shared->type)
3111
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for this datatype");
3112
57.6k
    if (H5T_VLEN == dt->shared->type && H5T_VLEN_STRING != dt->shared->u.vlen.type)
3113
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for this datatype");
3114
3115
    /* Modify the datatype */
3116
57.6k
    if (H5T__set_size(dt, size) < 0)
3117
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set size for datatype");
3118
3119
57.6k
done:
3120
57.6k
    FUNC_LEAVE_API(ret_value)
3121
57.6k
} /* end H5Tset_size() */
3122
3123
/*-------------------------------------------------------------------------
3124
 * Function:  H5Tget_super
3125
 *
3126
 * Purpose:   Returns the type from which TYPE is derived. In the case of
3127
 *            an enumeration type the return value is an integer type.
3128
 *
3129
 * Return:    Success:    Type ID for base datatype.
3130
 *
3131
 *            Failure:    negative
3132
 *
3133
 *-------------------------------------------------------------------------
3134
 */
3135
hid_t
3136
H5Tget_super(hid_t type)
3137
5.65k
{
3138
5.65k
    H5T_t *dt;                          /* Datatype to query */
3139
5.65k
    H5T_t *super     = NULL;            /* Supertype */
3140
5.65k
    hid_t  ret_value = H5I_INVALID_HID; /* Return value */
3141
3142
11.3k
    FUNC_ENTER_API(H5I_INVALID_HID)
3143
3144
11.3k
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
3145
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a datatype");
3146
5.65k
    if (NULL == (super = H5T_get_super(dt)))
3147
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5I_INVALID_HID, "not a datatype");
3148
5.65k
    if ((ret_value = H5I_register(H5I_DATATYPE, super, true)) < 0)
3149
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register parent datatype");
3150
3151
5.65k
done:
3152
5.65k
    if (H5I_INVALID_HID == ret_value)
3153
0
        if (super && H5T_close_real(super) < 0)
3154
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, H5I_INVALID_HID,
3155
5.65k
                        "unable to release super datatype info")
3156
3157
5.65k
    FUNC_LEAVE_API(ret_value)
3158
5.65k
} /* end H5Tget_super() */
3159
3160
/*-------------------------------------------------------------------------
3161
 * Function:  H5T_get_super
3162
 *
3163
 * Purpose:   Private function for H5Tget_super.  Returns the type from
3164
 *            which TYPE is derived. In the case of an enumeration type
3165
 *            the return value is an integer type.
3166
 *
3167
 * Return:    Success:    Data type for base data type.
3168
 *            Failure:        NULL
3169
 *
3170
 *-------------------------------------------------------------------------
3171
 */
3172
H5T_t *
3173
H5T_get_super(const H5T_t *dt)
3174
5.65k
{
3175
5.65k
    H5T_t *ret_value = NULL;
3176
3177
5.65k
    FUNC_ENTER_NOAPI(NULL)
3178
3179
5.65k
    assert(dt);
3180
3181
5.65k
    if (!dt->shared->parent)
3182
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "not a derived data type");
3183
5.65k
    if (NULL == (ret_value = H5T_copy(dt->shared->parent, H5T_COPY_ALL)))
3184
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy parent data type");
3185
3186
5.65k
done:
3187
5.65k
    FUNC_LEAVE_NOAPI(ret_value)
3188
5.65k
} /* end H5T_get_super() */
3189
3190
/*-------------------------------------------------------------------------
3191
 * Function:    H5T__register_int
3192
 *
3193
 * Purpose:    Register a library internal datatype conversion routine.
3194
 *
3195
 * Return:    Non-negative on success/Negative on failure
3196
 *
3197
 *-------------------------------------------------------------------------
3198
 */
3199
static herr_t
3200
H5T__register_int(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_lib_conv_t func)
3201
1.64k
{
3202
1.64k
    H5T_conv_func_t conv_func;           /* Conversion function wrapper */
3203
1.64k
    herr_t          ret_value = SUCCEED; /* Return value */
3204
3205
1.64k
    FUNC_ENTER_PACKAGE
3206
3207
    /* Check args */
3208
1.64k
    assert(H5T_PERS_HARD == pers || H5T_PERS_SOFT == pers);
3209
1.64k
    assert(name && *name);
3210
1.64k
    assert(src);
3211
1.64k
    assert(dst);
3212
1.64k
    assert(func);
3213
3214
    /* Set up conversion function wrapper */
3215
1.64k
    conv_func.is_app     = false;
3216
1.64k
    conv_func.u.lib_func = func;
3217
3218
    /* Register conversion */
3219
1.64k
    if (H5T__register(pers, name, src, dst, &conv_func) < 0)
3220
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,
3221
1.64k
                    "unable to register internal datatype conversion routine");
3222
3223
1.64k
done:
3224
1.64k
    FUNC_LEAVE_NOAPI(ret_value)
3225
1.64k
} /* end H5T__register_int() */
3226
3227
/*-------------------------------------------------------------------------
3228
 * Function:    H5T__register
3229
 *
3230
 * Purpose:    Register a hard or soft conversion function for a data type
3231
 *        conversion path.  The path is specified by the source and
3232
 *        destination data types SRC and DST (for soft functions only the
3233
 *        class of these types is important). If FUNC is a hard function
3234
 *        then it replaces any previous path; if it's a soft function then
3235
 *        it replaces all existing paths to which it applies and is used
3236
 *        for any new path to which it applies as long as that path doesn't
3237
 *        have a hard function.
3238
 *
3239
 * Return:    Non-negative on success/Negative on failure
3240
 *
3241
 *-------------------------------------------------------------------------
3242
 */
3243
static herr_t
3244
H5T__register(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_conv_func_t *conv)
3245
1.64k
{
3246
1.64k
    H5T_path_t *old_path = NULL;             /*existing conversion path   */
3247
1.64k
    H5T_path_t *new_path = NULL;             /*new conversion path        */
3248
1.64k
    H5T_cdata_t cdata;                       /*temporary conversion data  */
3249
1.64k
    H5T_t      *tmp_stype = NULL;            /*temporary source datatype */
3250
1.64k
    H5T_t      *tmp_dtype = NULL;            /*temporary destination datatype */
3251
1.64k
    hid_t       tmp_sid   = H5I_INVALID_HID; /*temporary datatype ID */
3252
1.64k
    hid_t       tmp_did   = H5I_INVALID_HID; /*temporary datatype ID */
3253
1.64k
    int         i;                           /*counter                    */
3254
1.64k
    herr_t      ret_value = SUCCEED;         /*return value               */
3255
3256
1.64k
    FUNC_ENTER_PACKAGE
3257
3258
    /* Check args */
3259
1.64k
    assert(src);
3260
1.64k
    assert(dst);
3261
1.64k
    assert(conv);
3262
1.64k
    assert(H5T_PERS_HARD == pers || H5T_PERS_SOFT == pers);
3263
1.64k
    assert(name && *name);
3264
3265
1.64k
    if (H5T_PERS_HARD == pers) {
3266
        /* Only bother to register the path if it's not a no-op path (for this machine) */
3267
1.44k
        if (H5T_cmp(src, dst, false)) {
3268
            /* Locate or create a new conversion path */
3269
1.41k
            if (NULL == (new_path = H5T__path_find_real(src, dst, name, conv)))
3270
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to locate/allocate conversion path");
3271
3272
            /* Notify all other functions to recalculate private data since some
3273
             * functions might cache a list of conversion functions.  For
3274
             * instance, the compound type converter caches a list of conversion
3275
             * functions for the members, so adding a new function should cause
3276
             * the list to be recalculated to use the new function.
3277
             */
3278
128k
            for (i = 0; i < H5T_g.npaths; i++)
3279
127k
                if (new_path != H5T_g.path[i])
3280
126k
                    H5T_g.path[i]->cdata.recalc = true;
3281
1.41k
        } /* end if */
3282
1.44k
    }     /* end if */
3283
198
    else {
3284
198
        H5T_conv_ctx_t conv_ctx = {0};
3285
3286
        /*
3287
         * Get the datatype conversion exception callback structure.
3288
         * Note that we have to first check if an API context has been
3289
         * pushed, since we could have arrived here during library
3290
         * initialization of the H5T package.
3291
         */
3292
198
        if (!conv->is_app && H5CX_pushed() && (H5CX_get_dt_conv_cb(&conv_ctx.u.init.cb_struct) < 0))
3293
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get conversion exception callback");
3294
3295
        /* Add function to end of soft list */
3296
198
        if ((size_t)H5T_g.nsoft >= H5T_g.asoft) {
3297
12
            size_t      na = MAX(32, 2 * H5T_g.asoft);
3298
12
            H5T_soft_t *x;
3299
3300
12
            if (NULL == (x = (H5T_soft_t *)H5MM_realloc(H5T_g.soft, na * sizeof(H5T_soft_t))))
3301
0
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
3302
12
            H5T_g.asoft = na;
3303
12
            H5T_g.soft  = x;
3304
12
        } /* end if */
3305
198
        strncpy(H5T_g.soft[H5T_g.nsoft].name, name, (size_t)H5T_NAMELEN - 1);
3306
198
        H5T_g.soft[H5T_g.nsoft].name[H5T_NAMELEN - 1] = '\0';
3307
198
        H5T_g.soft[H5T_g.nsoft].src                   = src->shared->type;
3308
198
        H5T_g.soft[H5T_g.nsoft].dst                   = dst->shared->type;
3309
198
        H5T_g.soft[H5T_g.nsoft].conv                  = *conv;
3310
198
        H5T_g.nsoft++;
3311
3312
        /*
3313
         * Any existing path (except the no-op path) to which this new soft
3314
         * conversion function applies should be replaced by a new path that
3315
         * uses this function.
3316
         */
3317
198
        for (i = 1; i < H5T_g.npaths; i++) {
3318
0
            old_path = H5T_g.path[i];
3319
0
            assert(old_path);
3320
3321
            /* Does the new soft conversion function apply to this path? */
3322
0
            if (old_path->is_hard || old_path->src->shared->type != src->shared->type ||
3323
0
                old_path->dst->shared->type != dst->shared->type)
3324
0
                continue;
3325
3326
0
            memset(&cdata, 0, sizeof cdata);
3327
0
            cdata.command = H5T_CONV_INIT;
3328
0
            if (conv->is_app) {
3329
0
                if (NULL == (tmp_stype = H5T_copy(old_path->src, H5T_COPY_ALL)))
3330
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy src datatype");
3331
0
                if (NULL == (tmp_dtype = H5T_copy(old_path->dst, H5T_COPY_ALL)))
3332
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy dst datatype");
3333
3334
0
                if ((tmp_sid = H5I_register(H5I_DATATYPE, tmp_stype, false)) < 0)
3335
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
3336
0
                                "unable to register ID for source datatype");
3337
0
                if ((tmp_did = H5I_register(H5I_DATATYPE, tmp_dtype, false)) < 0)
3338
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
3339
0
                                "unable to register ID for destination datatype");
3340
3341
                /* Prepare & restore library for user callback */
3342
0
                H5_BEFORE_USER_CB(FAIL)
3343
0
                    {
3344
0
                        ret_value = (conv->u.app_func)(tmp_sid, tmp_did, &cdata, 0, 0, 0, NULL, NULL,
3345
0
                                                       H5CX_get_dxpl());
3346
0
                    }
3347
0
                H5_AFTER_USER_CB(FAIL)
3348
0
                if (ret_value < 0) {
3349
0
                    if (H5I_dec_ref(tmp_sid) < 0)
3350
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL,
3351
0
                                    "unable to decrement reference count on temporary ID");
3352
0
                    if (H5I_dec_ref(tmp_did) < 0)
3353
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL,
3354
0
                                    "unable to decrement reference count on temporary ID");
3355
0
                    tmp_sid = tmp_did = H5I_INVALID_HID;
3356
0
                    tmp_stype = tmp_dtype = NULL;
3357
0
                    if (H5E_clear_stack() < 0)
3358
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to clear current error stack");
3359
0
                    continue;
3360
0
                } /* end if */
3361
0
            }     /* end if */
3362
0
            else if ((conv->u.lib_func)(old_path->src, old_path->dst, &cdata, &conv_ctx, 0, 0, 0, NULL,
3363
0
                                        NULL) < 0) {
3364
0
                if (H5E_clear_stack() < 0)
3365
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to clear current error stack");
3366
0
                continue;
3367
0
            } /* end if */
3368
3369
            /* Create a new conversion path */
3370
0
            if (NULL == (new_path = H5FL_CALLOC(H5T_path_t)))
3371
0
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
3372
0
            strncpy(new_path->name, name, (size_t)H5T_NAMELEN - 1);
3373
0
            new_path->name[H5T_NAMELEN - 1] = '\0';
3374
0
            if (NULL == (new_path->src = H5T_copy(old_path->src, H5T_COPY_ALL)) ||
3375
0
                NULL == (new_path->dst = H5T_copy(old_path->dst, H5T_COPY_ALL)))
3376
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy data types");
3377
0
            new_path->conv    = *conv;
3378
0
            new_path->is_hard = false;
3379
0
            new_path->cdata   = cdata;
3380
3381
            /* Replace previous path */
3382
0
            H5T_g.path[i] = new_path;
3383
0
            new_path      = NULL; /*so we don't free it on error*/
3384
3385
            /* Free old path */
3386
0
            conv_ctx.u.free.src_type_id = tmp_sid;
3387
0
            conv_ctx.u.free.dst_type_id = tmp_did;
3388
0
            if (H5T__path_free(old_path, &conv_ctx) < 0)
3389
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free datatype conversion path");
3390
3391
            /* Release temporary atoms */
3392
0
            if (tmp_sid >= 0) {
3393
0
                if (H5I_dec_ref(tmp_sid) < 0)
3394
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
3395
0
                tmp_sid   = H5I_INVALID_HID;
3396
0
                tmp_stype = NULL;
3397
0
            }
3398
0
            if (tmp_did >= 0) {
3399
0
                if (H5I_dec_ref(tmp_did) < 0)
3400
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
3401
0
                tmp_did   = H5I_INVALID_HID;
3402
0
                tmp_dtype = NULL;
3403
0
            }
3404
3405
            /* We don't care about any failures during the freeing process */
3406
0
            if (H5E_clear_stack() < 0)
3407
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to clear current error stack");
3408
0
        } /* end for */
3409
198
    }     /* end else */
3410
3411
1.64k
done:
3412
1.64k
    if (ret_value < 0) {
3413
0
        if (new_path) {
3414
0
            if (new_path->src && (H5T_close_real(new_path->src) < 0))
3415
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close datatype");
3416
0
            if (new_path->dst && (H5T_close_real(new_path->dst) < 0))
3417
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close datatype");
3418
0
            new_path = H5FL_FREE(H5T_path_t, new_path);
3419
0
        } /* end if */
3420
0
    }     /* end if */
3421
3422
1.64k
    if (tmp_sid >= 0) {
3423
0
        if (H5I_dec_ref(tmp_sid) < 0)
3424
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
3425
0
    }
3426
1.64k
    else if (tmp_stype) {
3427
0
        if (H5T_close(tmp_stype) < 0)
3428
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "can't close temporary datatype");
3429
0
    }
3430
1.64k
    if (tmp_did >= 0) {
3431
0
        if (H5I_dec_ref(tmp_did) < 0)
3432
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
3433
0
    }
3434
1.64k
    else if (tmp_dtype) {
3435
0
        if (H5T_close(tmp_dtype) < 0)
3436
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "can't close temporary datatype");
3437
0
    }
3438
3439
1.64k
    FUNC_LEAVE_NOAPI(ret_value)
3440
1.64k
} /* end H5T__register() */
3441
3442
/*-------------------------------------------------------------------------
3443
 * Function:    H5Tregister
3444
 *
3445
 * Purpose:    Register a hard or soft conversion function for a data type
3446
 *        conversion path.  The path is specified by the source and
3447
 *        destination data types SRC_ID and DST_ID (for soft functions
3448
 *        only the class of these types is important). If FUNC is a
3449
 *        hard function then it replaces any previous path; if it's a
3450
 *        soft function then it replaces all existing paths to which it
3451
 *        applies and is used for any new path to which it applies as
3452
 *        long as that path doesn't have a hard function.
3453
 *
3454
 * Return:    Non-negative on success/Negative on failure
3455
 *
3456
 *-------------------------------------------------------------------------
3457
 */
3458
herr_t
3459
H5Tregister(H5T_pers_t pers, const char *name, hid_t src_id, hid_t dst_id, H5T_conv_t func)
3460
0
{
3461
0
    H5T_t          *src;                 /*source data type descriptor    */
3462
0
    H5T_t          *dst;                 /*destination data type desc     */
3463
0
    H5T_conv_func_t conv_func;           /* Conversion function wrapper */
3464
0
    herr_t          ret_value = SUCCEED; /*return value                   */
3465
3466
0
    FUNC_ENTER_API(FAIL)
3467
3468
    /* Check args */
3469
0
    if (H5T_PERS_HARD != pers && H5T_PERS_SOFT != pers)
3470
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid function persistence");
3471
0
    if (!name || !*name)
3472
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "conversion must have a name for debugging");
3473
0
    if (NULL == (src = (H5T_t *)H5I_object_verify(src_id, H5I_DATATYPE)))
3474
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
3475
0
    if (NULL == (dst = (H5T_t *)H5I_object_verify(dst_id, H5I_DATATYPE)))
3476
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
3477
0
    if (!func)
3478
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no conversion function specified");
3479
3480
    /* Set up conversion function wrapper */
3481
0
    conv_func.is_app     = true;
3482
0
    conv_func.u.app_func = func;
3483
3484
    /* Go register the function */
3485
0
    if (H5T__register(pers, name, src, dst, &conv_func) < 0)
3486
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register conversion function");
3487
3488
0
done:
3489
0
    FUNC_LEAVE_API(ret_value)
3490
0
} /* end H5Tregister() */
3491
3492
/*-------------------------------------------------------------------------
3493
 * Function:   H5T_unregister
3494
 *
3495
 * Purpose:    Removes conversion paths that match the specified criteria.
3496
 *        All arguments are optional. Missing arguments are wild cards.
3497
 *        The special no-op path cannot be removed.
3498
 *
3499
 * Return:    Success:    non-negative
3500
 *            Failure:    negative
3501
 *
3502
 *-------------------------------------------------------------------------
3503
 */
3504
herr_t
3505
H5T_unregister(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5VL_object_t *owned_vol_obj,
3506
               H5T_conv_t func)
3507
3.75k
{
3508
3.75k
    H5T_conv_ctx_t conv_ctx  = {0};  /* Conversion context object   */
3509
3.75k
    H5T_path_t    *path      = NULL; /* Conversion path             */
3510
3.75k
    H5T_soft_t    *soft      = NULL; /* Soft conversion information */
3511
3.75k
    herr_t         ret_value = SUCCEED;
3512
3513
3.75k
    FUNC_ENTER_NOAPI(FAIL)
3514
3515
3.75k
    conv_ctx.u.free.src_type_id = H5I_INVALID_HID;
3516
3.75k
    conv_ctx.u.free.dst_type_id = H5I_INVALID_HID;
3517
3518
    /*
3519
     * Remove matching entries from the soft list if:
3520
     *
3521
     *  - The caller didn't specify a particular type (soft or hard)
3522
     *    of conversion path to match against or specified that soft
3523
     *    conversion paths should be matched against
3524
     *
3525
     *  AND
3526
     *
3527
     *  - The caller didn't provide the `owned_vol_obj` parameter;
3528
     *    if this parameter is provided, we want to leave the soft
3529
     *    list untouched and only remove cached conversion paths
3530
     *    below where the file VOL object associated with the path's
3531
     *    source or destination types matches the given VOL object.
3532
     */
3533
3.75k
    if ((H5T_PERS_DONTCARE == pers || H5T_PERS_SOFT == pers) && !owned_vol_obj) {
3534
0
        for (int i = H5T_g.nsoft - 1; i >= 0; --i) {
3535
0
            soft = H5T_g.soft + i;
3536
0
            assert(soft);
3537
0
            if (name && *name && strcmp(name, soft->name) != 0)
3538
0
                continue;
3539
0
            if (src && src->shared->type != soft->src)
3540
0
                continue;
3541
0
            if (dst && dst->shared->type != soft->dst)
3542
0
                continue;
3543
0
            if (func && func != soft->conv.u.app_func)
3544
0
                continue;
3545
3546
0
            memmove(H5T_g.soft + i, H5T_g.soft + i + 1, (size_t)(H5T_g.nsoft - (i + 1)) * sizeof(H5T_soft_t));
3547
0
            --H5T_g.nsoft;
3548
0
        }
3549
0
    }
3550
3551
    /* Remove matching conversion paths, except no-op path */
3552
1.34M
    for (int i = H5T_g.npaths - 1; i > 0; --i) {
3553
1.34M
        bool nomatch;
3554
3555
1.34M
        path = H5T_g.path[i];
3556
1.34M
        assert(path);
3557
3558
1.34M
        nomatch = !H5T_path_match(path, pers, name, src, dst, owned_vol_obj, func);
3559
3560
        /* Not a match */
3561
1.34M
        if (nomatch) {
3562
            /*
3563
             * Notify all other functions to recalculate private data since some
3564
             * functions might cache a list of conversion functions.  For
3565
             * instance, the compound type converter caches a list of conversion
3566
             * functions for the members, so removing a function should cause
3567
             * the list to be recalculated to avoid the removed function.
3568
             */
3569
1.33M
            path->cdata.recalc = true;
3570
1.33M
        }
3571
3.28k
        else {
3572
            /* Remove from table */
3573
3.28k
            memmove(H5T_g.path + i, H5T_g.path + i + 1,
3574
3.28k
                    (size_t)(H5T_g.npaths - (i + 1)) * sizeof(H5T_path_t *));
3575
3.28k
            --H5T_g.npaths;
3576
3577
3.28k
            if (H5T__path_free(path, &conv_ctx) < 0)
3578
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free datatype conversion path");
3579
3.28k
        }
3580
1.34M
    }
3581
3582
3.75k
done:
3583
3.75k
    FUNC_LEAVE_NOAPI(ret_value)
3584
3.75k
} /* end H5T_unregister() */
3585
3586
/*-------------------------------------------------------------------------
3587
 * Function:  H5Tunregister
3588
 *
3589
 * Purpose:   Removes conversion paths that match the specified criteria.
3590
 *        All arguments are optional. Missing arguments are wild cards.
3591
 *        The special no-op path cannot be removed.
3592
 *
3593
 * Return:    Success:    non-negative
3594
 *
3595
 *            Failure:    negative
3596
 *
3597
 *-------------------------------------------------------------------------
3598
 */
3599
herr_t
3600
H5Tunregister(H5T_pers_t pers, const char *name, hid_t src_id, hid_t dst_id, H5T_conv_t func)
3601
0
{
3602
0
    H5T_t *src = NULL, *dst = NULL; /* Datatype descriptors */
3603
0
    herr_t ret_value = SUCCEED;     /* Return value */
3604
3605
0
    FUNC_ENTER_API(FAIL)
3606
3607
    /* Check arguments */
3608
0
    if (src_id > 0 && (NULL == (src = (H5T_t *)H5I_object_verify(src_id, H5I_DATATYPE))))
3609
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "src is not a data type");
3610
0
    if (dst_id > 0 && (NULL == (dst = (H5T_t *)H5I_object_verify(dst_id, H5I_DATATYPE))))
3611
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dst is not a data type");
3612
3613
0
    if (H5T_unregister(pers, name, src, dst, NULL, func) < 0)
3614
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDELETE, FAIL, "internal unregister function failed");
3615
3616
0
done:
3617
0
    FUNC_LEAVE_API(ret_value)
3618
0
} /* end H5Tunregister() */
3619
3620
/*-------------------------------------------------------------------------
3621
 * Function:  H5Tfind
3622
 *
3623
 * Purpose:   Finds a conversion function that can handle a conversion from
3624
 *        type SRC_ID to type DST_ID.  The PCDATA argument is a pointer
3625
 *        to a pointer to type conversion data which was created and
3626
 *        initialized by the type conversion function of this path
3627
 *        when the conversion function was installed on the path.
3628
 *
3629
 * Return:    Success:    A pointer to a suitable conversion function.
3630
 *
3631
 *            Failure:    NULL
3632
 *
3633
 *-------------------------------------------------------------------------
3634
 */
3635
H5T_conv_t
3636
H5Tfind(hid_t src_id, hid_t dst_id, H5T_cdata_t **pcdata /*out*/)
3637
0
{
3638
0
    H5T_t      *src, *dst;
3639
0
    H5T_path_t *path;
3640
0
    H5T_conv_t  ret_value; /* Return value */
3641
3642
0
    FUNC_ENTER_API(NULL)
3643
3644
    /* Check args */
3645
0
    if (NULL == (src = (H5T_t *)H5I_object_verify(src_id, H5I_DATATYPE)) ||
3646
0
        NULL == (dst = (H5T_t *)H5I_object_verify(dst_id, H5I_DATATYPE)))
3647
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type");
3648
0
    if (!pcdata)
3649
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "no address to receive cdata pointer");
3650
3651
    /* Find it */
3652
0
    if (NULL == (path = H5T_path_find(src, dst)))
3653
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "conversion function not found");
3654
3655
0
    if (pcdata)
3656
0
        *pcdata = &(path->cdata);
3657
3658
    /* Set return value */
3659
0
    ret_value = path->conv.u.app_func;
3660
3661
0
done:
3662
0
    FUNC_LEAVE_API(ret_value)
3663
0
} /* end H5Tfind() */
3664
3665
/*-------------------------------------------------------------------------
3666
 * Function:  H5Tcompiler_conv
3667
 *
3668
 * Purpose:   Finds out whether the library's conversion function from
3669
 *            type src_id to type dst_id is a compiler (hard) conversion.
3670
 *            A hard conversion uses compiler's casting; a soft conversion
3671
 *            uses the library's own conversion function.
3672
 *
3673
 * Return:    true:           hard conversion.
3674
 *            false:          soft conversion.
3675
 *            FAIL:           failed.
3676
 *
3677
 *-------------------------------------------------------------------------
3678
 */
3679
htri_t
3680
H5Tcompiler_conv(hid_t src_id, hid_t dst_id)
3681
0
{
3682
0
    H5T_t *src, *dst;
3683
0
    htri_t ret_value; /* Return value */
3684
3685
0
    FUNC_ENTER_API(FAIL)
3686
3687
    /* Check args */
3688
0
    if (NULL == (src = (H5T_t *)H5I_object_verify(src_id, H5I_DATATYPE)) ||
3689
0
        NULL == (dst = (H5T_t *)H5I_object_verify(dst_id, H5I_DATATYPE)))
3690
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
3691
3692
    /* Find it */
3693
0
    if ((ret_value = H5T__compiler_conv(src, dst)) < 0)
3694
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, "conversion function not found");
3695
3696
0
done:
3697
0
    FUNC_LEAVE_API(ret_value)
3698
0
} /* end H5Tcompiler_conv() */
3699
3700
/*-------------------------------------------------------------------------
3701
 * Function:  H5Tconvert
3702
 *
3703
 * Purpose:   Convert NELMTS elements from type SRC_ID to type DST_ID.  The
3704
 *        source elements are packed in BUF and on return the
3705
 *        destination will be packed in BUF.  That is, the conversion
3706
 *        is performed in place.  The optional background buffer is an
3707
 *        array of NELMTS values of destination type which are merged
3708
 *        with the converted values to fill in cracks (for instance,
3709
 *        BACKGROUND might be an array of structs with the `a' and `b'
3710
 *        fields already initialized and the conversion of BUF supplies
3711
 *        the `c' and `d' field values).  The PLIST_ID a dataset transfer
3712
 *        property list which is passed to the conversion functions.  (It's
3713
 *        currently only used to pass along the VL datatype custom allocation
3714
 *        information -QAK 7/1/99)
3715
 *
3716
 * Return:    Non-negative on success/Negative on failure
3717
 *
3718
 *-------------------------------------------------------------------------
3719
 */
3720
herr_t
3721
H5Tconvert(hid_t src_id, hid_t dst_id, size_t nelmts, void *buf, void *background, hid_t dxpl_id)
3722
0
{
3723
0
    H5T_path_t *tpath;               /* type conversion info    */
3724
0
    H5T_t      *src, *dst;           /* unregistered types      */
3725
0
    herr_t      ret_value = SUCCEED; /* Return value            */
3726
3727
0
    FUNC_ENTER_API(FAIL)
3728
3729
    /* Check args */
3730
0
    if (NULL == (src = (H5T_t *)H5I_object_verify(src_id, H5I_DATATYPE)) ||
3731
0
        NULL == (dst = (H5T_t *)H5I_object_verify(dst_id, H5I_DATATYPE)))
3732
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
3733
0
    if (H5P_DEFAULT == dxpl_id)
3734
0
        dxpl_id = H5P_DATASET_XFER_DEFAULT;
3735
0
    else if (true != H5P_isa_class(dxpl_id, H5P_DATASET_XFER))
3736
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not dataset transfer property list");
3737
3738
    /* Set DXPL for operation */
3739
0
    H5CX_set_dxpl(dxpl_id);
3740
3741
    /* Find the conversion function */
3742
0
    if (NULL == (tpath = H5T_path_find(src, dst)))
3743
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert between src and dst data types");
3744
3745
0
    if (H5T_convert(tpath, src, dst, nelmts, 0, 0, buf, background) < 0)
3746
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "data type conversion failed");
3747
3748
0
done:
3749
0
    FUNC_LEAVE_API(ret_value)
3750
0
} /* end H5Tconvert() */
3751
3752
/*-------------------------------------------------------------------------
3753
 * Function:    H5Treclaim
3754
 *
3755
 * Purpose: Frees the buffers allocated for storing variable-length data
3756
 *      in memory.  Only frees the VL data in the selection defined in the
3757
 *      dataspace.  The dataset transfer property list is required to find the
3758
 *      correct allocation/free methods for the VL data in the buffer.
3759
 *
3760
 * Return:  Non-negative on success, negative on failure
3761
 *
3762
 *-------------------------------------------------------------------------
3763
 */
3764
herr_t
3765
H5Treclaim(hid_t type_id, hid_t space_id, hid_t dxpl_id, void *buf)
3766
3.98k
{
3767
3.98k
    const H5T_t *type;
3768
3.98k
    H5S_t       *space;     /* Dataspace for iteration */
3769
3.98k
    herr_t       ret_value; /* Return value */
3770
3771
7.97k
    FUNC_ENTER_API(FAIL)
3772
3773
    /* Check args */
3774
7.97k
    if (buf == NULL)
3775
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "'buf' pointer is NULL");
3776
3.98k
    if (NULL == (type = (const H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
3777
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid datatype");
3778
3.98k
    if (NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE)))
3779
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataspace");
3780
3.98k
    if (!(H5S_has_extent(space)))
3781
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dataspace does not have extent set");
3782
3783
    /* Get the default dataset transfer property list if the user didn't provide one */
3784
3.98k
    if (H5P_DEFAULT == dxpl_id)
3785
3.98k
        dxpl_id = H5P_DATASET_XFER_DEFAULT;
3786
0
    else if (true != H5P_isa_class(dxpl_id, H5P_DATASET_XFER))
3787
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms");
3788
3789
    /* Set DXPL for operation */
3790
3.98k
    H5CX_set_dxpl(dxpl_id);
3791
3792
    /* Call internal routine */
3793
3.98k
    ret_value = H5T_reclaim(type, space, buf);
3794
3795
3.98k
done:
3796
3.98k
    FUNC_LEAVE_API(ret_value)
3797
3.98k
} /* end H5Treclaim() */
3798
3799
/*-------------------------------------------------------------------------
3800
 * Function:  H5Tencode
3801
 *
3802
 * Purpose:   Given an datatype ID, converts the object description into
3803
 *            binary in a buffer.
3804
 *
3805
 * Return:    Success:    non-negative
3806
 *
3807
 *            Failure:    negative
3808
 *
3809
 *-------------------------------------------------------------------------
3810
 */
3811
herr_t
3812
H5Tencode(hid_t obj_id, void *buf, size_t *nalloc)
3813
0
{
3814
0
    H5T_t *dtype;
3815
0
    herr_t ret_value = SUCCEED;
3816
3817
0
    FUNC_ENTER_API(FAIL)
3818
3819
    /* Check argument and retrieve object */
3820
0
    if (NULL == (dtype = (H5T_t *)H5I_object_verify(obj_id, H5I_DATATYPE)))
3821
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
3822
0
    if (nalloc == NULL)
3823
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "NULL pointer for buffer size");
3824
3825
    /* Go encode the datatype */
3826
0
    if (H5T_encode(dtype, (unsigned char *)buf, nalloc) < 0)
3827
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode datatype");
3828
3829
0
done:
3830
0
    FUNC_LEAVE_API(ret_value)
3831
0
} /* end H5Tencode() */
3832
3833
/*-------------------------------------------------------------------------
3834
 * Function:  H5Tdecode2
3835
 *
3836
 * Purpose:   Decode a binary object description and return a new object
3837
 *            handle.
3838
 *
3839
 * Return:    Success:    datatype ID(non-negative)
3840
 *
3841
 *            Failure:    negative
3842
 *
3843
 *-------------------------------------------------------------------------
3844
 */
3845
hid_t
3846
H5Tdecode2(const void *buf, size_t buf_size)
3847
0
{
3848
0
    H5T_t *dt;
3849
0
    hid_t  ret_value; /* Return value */
3850
3851
0
    FUNC_ENTER_API(H5I_INVALID_HID)
3852
3853
    /* Check args */
3854
0
    if (buf == NULL)
3855
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "empty buffer");
3856
3857
    /* Create datatype by decoding buffer */
3858
0
    if (NULL == (dt = H5T_decode(buf_size, buf)))
3859
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, H5I_INVALID_HID, "can't decode object");
3860
3861
    /* Register the type and return the ID */
3862
0
    if ((ret_value = H5I_register(H5I_DATATYPE, dt, true)) < 0)
3863
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register data type");
3864
3865
0
done:
3866
0
    FUNC_LEAVE_API(ret_value)
3867
0
} /* end H5Tdecode2() */
3868
3869
/*-------------------------------------------------------------------------
3870
 * API functions are above; library-private functions are below...
3871
 *-------------------------------------------------------------------------
3872
 */
3873
3874
/*-------------------------------------------------------------------------
3875
 * Function:  H5T_encode
3876
 *
3877
 * Purpose:   Private function for H5Tencode.  Converts an object
3878
 *            description into binary in a buffer.
3879
 *
3880
 * Return:    Success:    non-negative
3881
 *
3882
 *            Failure:    negative
3883
 *
3884
 *-------------------------------------------------------------------------
3885
 */
3886
herr_t
3887
H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc)
3888
6.44k
{
3889
6.44k
    size_t buf_size;         /* Encoded size of datatype */
3890
6.44k
    H5F_t *f         = NULL; /* Fake file structure*/
3891
6.44k
    herr_t ret_value = SUCCEED;
3892
3893
6.44k
    FUNC_ENTER_NOAPI_NOINIT
3894
3895
    /* Allocate "fake" file structure */
3896
6.44k
    if (NULL == (f = H5F_fake_alloc((uint8_t)0)))
3897
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "can't allocate fake file struct");
3898
3899
    /* Find out the size of buffer needed */
3900
6.44k
    if ((buf_size = H5O_msg_raw_size(f, H5O_DTYPE_ID, true, obj)) == 0)
3901
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADSIZE, FAIL, "can't find datatype size");
3902
3903
    /* Don't encode if buffer size isn't big enough or buffer is empty */
3904
6.44k
    if (!buf || *nalloc < (buf_size + 1 + 1))
3905
3.22k
        *nalloc = buf_size + 1 + 1;
3906
3.22k
    else {
3907
        /* Encode the type of the information */
3908
3.22k
        *buf++ = H5O_DTYPE_ID;
3909
3910
        /* Encode the version of the dataspace information */
3911
3.22k
        *buf++ = H5T_ENCODE_VERSION;
3912
3913
        /* Encode into user's buffer */
3914
3.22k
        if (H5O_msg_encode(f, H5O_DTYPE_ID, true, buf, obj) < 0)
3915
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode object");
3916
3.22k
    } /* end else */
3917
3918
6.44k
done:
3919
    /* Release fake file structure */
3920
6.44k
    if (f && H5F_fake_free(f) < 0)
3921
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, FAIL, "unable to release fake file struct");
3922
3923
6.44k
    FUNC_LEAVE_NOAPI(ret_value)
3924
6.44k
} /* end H5T_encode() */
3925
3926
/*-------------------------------------------------------------------------
3927
 * Function:  H5T_decode
3928
 *
3929
 * Purpose:   Private function for H5Tdecode.  Reconstructs a binary
3930
 *            description of datatype and returns a new object handle.
3931
 *
3932
 * Return:    Success:    Pointer to the new type.
3933
 *
3934
 *            Failure:    NULL
3935
 *
3936
 *-------------------------------------------------------------------------
3937
 */
3938
H5T_t *
3939
H5T_decode(size_t buf_size, const unsigned char *buf)
3940
3.22k
{
3941
3.22k
    H5F_t *f         = NULL; /* Fake file structure*/
3942
3.22k
    H5T_t *ret_value = NULL; /* Return value */
3943
3944
3.22k
    FUNC_ENTER_NOAPI_NOINIT
3945
3946
    /* Allocate "fake" file structure */
3947
3.22k
    if (NULL == (f = H5F_fake_alloc((uint8_t)0)))
3948
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "can't allocate fake file struct");
3949
3950
3.22k
    if (buf_size != SIZE_MAX && H5_IS_BUFFER_OVERFLOW(buf, 1, buf + buf_size - 1))
3951
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message");
3952
3953
    /* Decode the type of the information */
3954
3.22k
    if (*buf++ != H5O_DTYPE_ID)
3955
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "not an encoded datatype");
3956
3957
3.22k
    if (buf_size != SIZE_MAX && H5_IS_BUFFER_OVERFLOW(buf, 1, buf + buf_size - 1))
3958
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message");
3959
3960
    /* Decode the version of the datatype information */
3961
3.22k
    if (*buf++ != H5T_ENCODE_VERSION)
3962
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_VERSION, NULL, "unknown version of encoded datatype");
3963
3964
    /* Decode the serialized datatype message */
3965
3.22k
    if (NULL == (ret_value = (H5T_t *)H5O_msg_decode(f, NULL, H5O_DTYPE_ID, buf_size, buf)))
3966
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode object");
3967
3968
    /* Mark datatype as being in memory now */
3969
3.22k
    if (H5T_set_loc(ret_value, NULL, H5T_LOC_MEMORY) < 0)
3970
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location");
3971
3972
    /* No VOL object */
3973
3.22k
    ret_value->vol_obj = NULL;
3974
3.22k
done:
3975
    /* Release fake file structure */
3976
3.22k
    if (f && H5F_fake_free(f) < 0)
3977
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, NULL, "unable to release fake file struct");
3978
3979
3.22k
    FUNC_LEAVE_NOAPI(ret_value)
3980
3.22k
} /* end H5T_decode() */
3981
3982
/*-------------------------------------------------------------------------
3983
 * Function:  H5T__create
3984
 *
3985
 * Purpose:   Creates a new data type and initializes it to reasonable
3986
 *            values.     The new data type is SIZE bytes and an instance of
3987
 *            the class TYPE.
3988
 *
3989
 * Return:    Success:    Pointer to the new type.
3990
 *
3991
 *            Failure:    NULL
3992
 *
3993
 *-------------------------------------------------------------------------
3994
 */
3995
H5T_t *
3996
H5T__create(H5T_class_t type, size_t size)
3997
12
{
3998
12
    H5T_t *dt        = NULL;
3999
12
    H5T_t *ret_value = NULL;
4000
4001
12
    FUNC_ENTER_PACKAGE
4002
4003
12
    switch (type) {
4004
0
        case H5T_INTEGER:
4005
0
        case H5T_FLOAT:
4006
0
        case H5T_TIME:
4007
0
        case H5T_STRING: {
4008
0
            H5T_t *origin_dt = NULL;
4009
4010
0
            if (NULL == (origin_dt = (H5T_t *)H5I_object(H5T_C_S1)))
4011
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, NULL, "can't get structure for string type");
4012
4013
            /* Copy the default string datatype */
4014
0
            if (NULL == (dt = H5T_copy(origin_dt, H5T_COPY_TRANSIENT)))
4015
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy");
4016
0
            dt->shared->type = type;
4017
4018
            /* Modify the datatype */
4019
0
            if (H5T__set_size(dt, size) < 0)
4020
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to set size for string type");
4021
0
        } break;
4022
4023
0
        case H5T_BITFIELD:
4024
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "type class is not appropriate - use H5Tcopy()");
4025
4026
0
        case H5T_OPAQUE:
4027
6
        case H5T_COMPOUND:
4028
6
            if (NULL == (dt = H5T__alloc()))
4029
0
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
4030
6
            dt->shared->type = type;
4031
4032
6
            if (type == H5T_COMPOUND) {
4033
6
                dt->shared->u.compnd.packed    = false; /* Start out unpacked */
4034
6
                dt->shared->u.compnd.memb_size = 0;
4035
6
            } /* end if */
4036
0
            else if (type == H5T_OPAQUE)
4037
                /* Initialize the tag in case it's not set later.  A null tag will
4038
                 * cause problems for later operations. */
4039
0
                dt->shared->u.opaque.tag = H5MM_strdup("");
4040
6
            break;
4041
4042
6
        case H5T_ENUM: {
4043
6
            hid_t  subtype;
4044
6
            H5T_t *sub_t_obj;
4045
4046
6
            if (sizeof(char) == size)
4047
6
                subtype = H5T_NATIVE_SCHAR_g;
4048
0
            else if (sizeof(short) == size)
4049
0
                subtype = H5T_NATIVE_SHORT_g;
4050
0
            else if (sizeof(int) == size)
4051
0
                subtype = H5T_NATIVE_INT_g;
4052
0
            else if (sizeof(long) == size)
4053
0
                subtype = H5T_NATIVE_LONG_g;
4054
#if H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG
4055
            else if (sizeof(long long) == size)
4056
                subtype = H5T_NATIVE_LLONG_g;
4057
#endif /* H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG */
4058
0
            else
4059
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no applicable native integer type");
4060
6
            if (NULL == (dt = H5T__alloc()))
4061
0
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
4062
6
            dt->shared->type = type;
4063
6
            if (NULL == (sub_t_obj = (H5T_t *)H5I_object(subtype)))
4064
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, NULL, "unable to get datatype object");
4065
6
            if (NULL == (dt->shared->parent = H5T_copy(sub_t_obj, H5T_COPY_ALL)))
4066
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "unable to copy base datatype");
4067
6
        } break;
4068
4069
6
        case H5T_VLEN: /* Variable length datatype */
4070
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "base type required - use H5Tvlen_create()");
4071
4072
0
        case H5T_ARRAY: /* Array datatype */
4073
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "base type required - use H5Tarray_create2()");
4074
4075
0
        case H5T_COMPLEX: /* Complex number datatype */
4076
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "base type required - use H5Tcomplex_create()");
4077
4078
0
        case H5T_NO_CLASS:
4079
0
        case H5T_REFERENCE:
4080
0
        case H5T_NCLASSES:
4081
0
        default:
4082
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "unknown data type class");
4083
12
    } /* end switch */
4084
4085
    /* Set the size except VL string */
4086
12
    if (H5T_STRING != type || H5T_VARIABLE != size)
4087
12
        dt->shared->size = size;
4088
4089
    /* No VOL object */
4090
12
    dt->vol_obj = NULL;
4091
4092
    /* Set return value */
4093
12
    ret_value = dt;
4094
4095
12
done:
4096
12
    if (NULL == ret_value) {
4097
0
        if (dt) {
4098
0
            if (dt->shared->owned_vol_obj && H5VL_free_object(dt->shared->owned_vol_obj) < 0)
4099
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close owned VOL object");
4100
0
            dt->shared = H5FL_FREE(H5T_shared_t, dt->shared);
4101
0
            dt         = H5FL_FREE(H5T_t, dt);
4102
0
        }
4103
0
    }
4104
4105
12
    FUNC_LEAVE_NOAPI(ret_value)
4106
12
} /* end H5T__create() */
4107
4108
/*-------------------------------------------------------------------------
4109
 * Function:  H5T__initiate_copy
4110
 *
4111
 * Purpose:   Allocates datatype structures, copies core fields, and initializes
4112
 *            VOL fields.
4113
 *
4114
 * Return:    Success:    Pointer to a new copy of the OLD_DT argument.
4115
 *            Failure:    NULL
4116
 *
4117
 * Note:      Common code for both H5T_copy and H5T_copy_reopen, as part of
4118
 *            the const-correct datatype copying routines.
4119
 *
4120
 *-------------------------------------------------------------------------
4121
 */
4122
static H5T_t *
4123
H5T__initiate_copy(const H5T_t *old_dt)
4124
325k
{
4125
325k
    H5T_t *new_dt    = NULL; /* Copy of datatype */
4126
325k
    H5T_t *ret_value = NULL; /* Return value */
4127
4128
325k
    FUNC_ENTER_PACKAGE
4129
4130
    /* Allocate space */
4131
325k
    if (NULL == (new_dt = H5FL_MALLOC(H5T_t)))
4132
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "H5T_t memory allocation failed");
4133
325k
    if (NULL == (new_dt->shared = H5FL_MALLOC(H5T_shared_t)))
4134
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "H5T_shared_t memory allocation failed");
4135
4136
    /* Copy shared information */
4137
325k
    *(new_dt->shared) = *(old_dt->shared);
4138
4139
    /* Increment ref count on owned VOL object */
4140
325k
    if (new_dt->shared->owned_vol_obj)
4141
35.1k
        (void)H5VL_object_inc_rc(new_dt->shared->owned_vol_obj);
4142
4143
    /* Reset vol_obj field */
4144
325k
    new_dt->vol_obj = NULL;
4145
4146
    /* Set return value */
4147
325k
    ret_value = new_dt;
4148
4149
325k
done:
4150
325k
    if (ret_value == NULL)
4151
0
        if (new_dt) {
4152
0
            if (new_dt->shared) {
4153
0
                if (new_dt->shared->owned_vol_obj && H5VL_free_object(new_dt->shared->owned_vol_obj) < 0)
4154
0
                    HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close owned VOL object");
4155
0
                new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared);
4156
0
            } /* end if */
4157
0
            new_dt = H5FL_FREE(H5T_t, new_dt);
4158
0
        } /* end if */
4159
4160
325k
    FUNC_LEAVE_NOAPI(ret_value)
4161
325k
} /* end H5T__initiate_copy() */
4162
4163
/*-------------------------------------------------------------------------
4164
 * Function:  H5T__copy_transient
4165
 *
4166
 * Purpose:   Part of recursive framework for const-correct datatype copying.
4167
 *
4168
 * Return:    Success:    Pointer to a new copy of the OLD_DT argument.
4169
 *            Failure:    NULL
4170
 *
4171
 *-------------------------------------------------------------------------
4172
 */
4173
static H5T_t *
4174
H5T__copy_transient(H5T_t *old_dt)
4175
0
{
4176
0
    H5T_t *ret_value = NULL; /* Return value */
4177
4178
0
    FUNC_ENTER_PACKAGE
4179
4180
    /* Copy datatype, with correct method */
4181
0
    if (NULL == (ret_value = H5T_copy(old_dt, H5T_COPY_TRANSIENT)))
4182
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't make 'transient' copy of datatype");
4183
4184
0
done:
4185
0
    FUNC_LEAVE_NOAPI(ret_value)
4186
0
} /* end H5T__copy_transient() */
4187
4188
/*-------------------------------------------------------------------------
4189
 * Function:  H5T__copy_all
4190
 *
4191
 * Purpose:   Part of recursive framework for const-correct datatype copying.
4192
 *
4193
 * Return:    Success:    Pointer to a new copy of the OLD_DT argument.
4194
 *            Failure:    NULL
4195
 *
4196
 *-------------------------------------------------------------------------
4197
 */
4198
static H5T_t *
4199
H5T__copy_all(H5T_t *old_dt)
4200
3.73k
{
4201
3.73k
    H5T_t *ret_value = NULL; /* Return value */
4202
4203
3.73k
    FUNC_ENTER_PACKAGE
4204
4205
    /* Copy datatype, with correct method */
4206
3.73k
    if (NULL == (ret_value = H5T_copy(old_dt, H5T_COPY_ALL)))
4207
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't make 'all' copy of datatype");
4208
4209
3.73k
done:
4210
3.73k
    FUNC_LEAVE_NOAPI(ret_value)
4211
3.73k
} /* end H5T__copy_transient() */
4212
4213
/*-------------------------------------------------------------------------
4214
 * Function:  H5T__complete_copy
4215
 *
4216
 * Purpose:   Completes copying datatype fields, as part of the recursive
4217
 *            const-correct datatype copy routines.
4218
 *
4219
 * Return:    Success:    non-negative
4220
 *            Failure:    negative
4221
 *
4222
 * Note:      Common code for both H5T_copy and H5T_copy_reopen.
4223
 *
4224
 *-------------------------------------------------------------------------
4225
 */
4226
static herr_t
4227
H5T__complete_copy(H5T_t *new_dt, const H5T_t *old_dt, H5T_shared_t *reopened_fo, bool set_memory_type,
4228
                   H5T_copy_func_t copyfn)
4229
325k
{
4230
325k
    H5T_t   *tmp = NULL;          /* Temporary copy of compound field's datatype */
4231
325k
    char    *s;                   /* Temporary copy of compound field name / enum value name */
4232
325k
    unsigned i;                   /* Local index variable */
4233
325k
    herr_t   ret_value = SUCCEED; /* Return value */
4234
4235
325k
    FUNC_ENTER_PACKAGE
4236
4237
    /* Update fields in the new struct, if we aren't sharing an already opened
4238
     * committed datatype */
4239
325k
    if (!reopened_fo) {
4240
        /* Copy parent information */
4241
325k
        if (old_dt->shared->parent)
4242
15.0k
            if (NULL == (new_dt->shared->parent = (*copyfn)(old_dt->shared->parent)))
4243
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy datatype's parent type");
4244
4245
325k
        switch (new_dt->shared->type) {
4246
0
            case H5T_COMPOUND: {
4247
0
                ssize_t accum_change = 0; /* Amount of change in the offset of the fields */
4248
4249
                /*
4250
                 * Copy all member fields to new type, then overwrite the
4251
                 * name and type fields of each new member with copied values.
4252
                 * That is, H5T_copy() is a deep copy.
4253
                 */
4254
                /* Only malloc if space has been allocated for members - NAF */
4255
0
                if (new_dt->shared->u.compnd.nalloc > 0) {
4256
0
                    if (NULL == (new_dt->shared->u.compnd.memb =
4257
0
                                     H5MM_malloc(new_dt->shared->u.compnd.nalloc * sizeof(H5T_cmemb_t))))
4258
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "memory allocation failed");
4259
4260
0
                    H5MM_memcpy(new_dt->shared->u.compnd.memb, old_dt->shared->u.compnd.memb,
4261
0
                                new_dt->shared->u.compnd.nmembs * sizeof(H5T_cmemb_t));
4262
0
                } /* end if */
4263
4264
0
                for (i = 0; i < new_dt->shared->u.compnd.nmembs; i++) {
4265
0
                    unsigned j;
4266
0
                    int      old_match;
4267
4268
0
                    if (NULL == (s = H5MM_xstrdup(new_dt->shared->u.compnd.memb[i].name)))
4269
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL,
4270
0
                                    "can't copy string for compound field's name");
4271
0
                    new_dt->shared->u.compnd.memb[i].name = s;
4272
0
                    if (NULL == (tmp = (*copyfn)(old_dt->shared->u.compnd.memb[i].type)))
4273
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy compound field's datatype");
4274
0
                    new_dt->shared->u.compnd.memb[i].type = tmp;
4275
0
                    assert(tmp != NULL);
4276
4277
                    /* Range check against compound member's offset */
4278
0
                    if ((accum_change < 0) &&
4279
0
                        ((ssize_t)new_dt->shared->u.compnd.memb[i].offset < accum_change))
4280
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "invalid field size in datatype");
4281
4282
                    /* Apply the accumulated size change to the offset of the field */
4283
0
                    new_dt->shared->u.compnd.memb[i].offset += (size_t)accum_change;
4284
4285
0
                    if (old_dt->shared->u.compnd.sorted != H5T_SORT_VALUE) {
4286
0
                        for (old_match = -1, j = 0; j < old_dt->shared->u.compnd.nmembs; j++) {
4287
0
                            if (!strcmp(new_dt->shared->u.compnd.memb[i].name,
4288
0
                                        old_dt->shared->u.compnd.memb[j].name)) {
4289
0
                                old_match = (int)j;
4290
0
                                break;
4291
0
                            } /* end if */
4292
0
                        }     /* end for */
4293
4294
                        /* check if we couldn't find a match */
4295
0
                        if (old_match < 0)
4296
0
                            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "fields in datatype corrupted");
4297
0
                    } /* end if */
4298
0
                    else
4299
0
                        old_match = (int)i;
4300
4301
                    /* If the field changed size, add that change to the accumulated size change */
4302
0
                    if (new_dt->shared->u.compnd.memb[i].type->shared->size !=
4303
0
                        old_dt->shared->u.compnd.memb[old_match].type->shared->size) {
4304
                        /* Adjust the size of the member */
4305
0
                        new_dt->shared->u.compnd.memb[i].size =
4306
0
                            (old_dt->shared->u.compnd.memb[old_match].size * tmp->shared->size) /
4307
0
                            old_dt->shared->u.compnd.memb[old_match].type->shared->size;
4308
4309
0
                        accum_change +=
4310
0
                            (ssize_t)(new_dt->shared->u.compnd.memb[i].type->shared->size -
4311
0
                                      old_dt->shared->u.compnd.memb[old_match].type->shared->size);
4312
0
                    } /* end if */
4313
0
                }     /* end for */
4314
4315
                /* Range check against datatype size */
4316
0
                if ((accum_change < 0) && ((ssize_t)new_dt->shared->size < accum_change))
4317
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "invalid field size in datatype");
4318
4319
                /* Apply the accumulated size change to the size of the compound struct */
4320
0
                new_dt->shared->size += (size_t)accum_change;
4321
0
            } break;
4322
4323
0
            case H5T_ENUM:
4324
                /*
4325
                 * Copy all member fields to new type, then overwrite the name fields
4326
                 * of each new member with copied values. That is, H5T_copy() is a
4327
                 * deep copy.
4328
                 */
4329
0
                if (old_dt->shared->u.enumer.nalloc > 0) {
4330
0
                    if (NULL == (new_dt->shared->u.enumer.name =
4331
0
                                     H5MM_malloc(new_dt->shared->u.enumer.nalloc * sizeof(char *))))
4332
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL,
4333
0
                                    "enam name array memory allocation failed");
4334
0
                    if (NULL == (new_dt->shared->u.enumer.value =
4335
0
                                     H5MM_malloc(new_dt->shared->u.enumer.nalloc * new_dt->shared->size)))
4336
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL,
4337
0
                                    "enam value array memory allocation failed");
4338
0
                    H5MM_memcpy(new_dt->shared->u.enumer.value, old_dt->shared->u.enumer.value,
4339
0
                                new_dt->shared->u.enumer.nmembs * new_dt->shared->size);
4340
0
                    for (i = 0; i < new_dt->shared->u.enumer.nmembs; i++) {
4341
0
                        if (NULL == (s = H5MM_xstrdup(old_dt->shared->u.enumer.name[i])))
4342
0
                            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL,
4343
0
                                        "can't copy string for enum value's name");
4344
0
                        new_dt->shared->u.enumer.name[i] = s;
4345
0
                    }
4346
0
                }
4347
0
                else {
4348
                    /* Empty enum */
4349
0
                    memset(&new_dt->shared->u.enumer, 0, sizeof(H5T_enum_t));
4350
0
                }
4351
0
                break;
4352
4353
14.6k
            case H5T_VLEN:
4354
56.0k
            case H5T_REFERENCE:
4355
56.0k
                if (set_memory_type)
4356
                    /* H5T_copy converts any type into a memory type */
4357
42.2k
                    if (H5T_set_loc(new_dt, NULL, H5T_LOC_MEMORY) < 0)
4358
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location");
4359
56.0k
                break;
4360
4361
56.0k
            case H5T_OPAQUE:
4362
                /*
4363
                 * Copy the tag name.
4364
                 */
4365
452
                new_dt->shared->u.opaque.tag = H5MM_xstrdup(new_dt->shared->u.opaque.tag);
4366
452
                break;
4367
4368
0
            case H5T_ARRAY:
4369
                /* Re-compute the array's size, in case it's base type changed size */
4370
0
                new_dt->shared->size = new_dt->shared->u.array.nelem * new_dt->shared->parent->shared->size;
4371
0
                break;
4372
4373
0
            case H5T_NO_CLASS:
4374
80.0k
            case H5T_INTEGER:
4375
132k
            case H5T_FLOAT:
4376
132k
            case H5T_TIME:
4377
268k
            case H5T_STRING:
4378
269k
            case H5T_BITFIELD:
4379
269k
            case H5T_COMPLEX:
4380
269k
            case H5T_NCLASSES:
4381
269k
            default:
4382
269k
                break;
4383
325k
        } /* end switch */
4384
325k
    }     /* end if */
4385
4386
    /* Set the cached location & name path if the original type was a named
4387
     * type and the new type is also named.
4388
     */
4389
325k
    if (H5O_loc_reset(&new_dt->oloc) < 0)
4390
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to initialize location");
4391
325k
    if (H5G_name_reset(&new_dt->path) < 0)
4392
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to reset path");
4393
4394
325k
    if (new_dt->shared->state == H5T_STATE_NAMED || new_dt->shared->state == H5T_STATE_OPEN) {
4395
0
        if (H5O_loc_copy_deep(&(new_dt->oloc), &(old_dt->oloc)) < 0)
4396
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy object location");
4397
0
        if (H5G_name_copy(&(new_dt->path), &(old_dt->path), H5_COPY_DEEP) < 0)
4398
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy path");
4399
0
    } /* end if */
4400
4401
    /* Copy shared location information if the new type is named or if it is
4402
     * shared in the heap.
4403
     */
4404
325k
    if ((old_dt->sh_loc.type == H5O_SHARE_TYPE_SOHM || old_dt->sh_loc.type == H5O_SHARE_TYPE_HERE) ||
4405
325k
        new_dt->shared->state == H5T_STATE_NAMED || new_dt->shared->state == H5T_STATE_OPEN) {
4406
451
        if (H5O_set_shared(&(new_dt->sh_loc), &(old_dt->sh_loc)) < 0)
4407
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy shared information");
4408
451
    } /* end if */
4409
325k
    else
4410
        /* Reset shared component info */
4411
325k
        H5O_msg_reset_share(H5O_DTYPE_ID, new_dt);
4412
4413
325k
done:
4414
325k
    FUNC_LEAVE_NOAPI(ret_value)
4415
325k
} /* end H5T__complete_copy() */
4416
4417
/*-------------------------------------------------------------------------
4418
 * Function:  H5T_copy
4419
 *
4420
 * Purpose:   Copies datatype OLD_DT.     The resulting data type is not
4421
 *            locked and is a transient type.
4422
 *
4423
 * Return:    Success:    Pointer to a new copy of the OLD_DT argument.
4424
 *            Failure:    NULL
4425
 *
4426
 *-------------------------------------------------------------------------
4427
 */
4428
H5T_t *
4429
H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
4430
162k
{
4431
162k
    H5T_t          *new_dt = NULL;    /* New datatype */
4432
162k
    H5T_copy_func_t copyfn;           /* Pointer to correct copy routine */
4433
162k
    H5T_t          *ret_value = NULL; /* Return value */
4434
4435
162k
    FUNC_ENTER_NOAPI(NULL)
4436
4437
    /* check args */
4438
162k
    assert(old_dt);
4439
4440
    /* Allocate and copy core datatype information */
4441
162k
    if (NULL == (new_dt = H5T__initiate_copy(old_dt)))
4442
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy core datatype info");
4443
4444
    /* Check what sort of copy we are making */
4445
162k
    switch (method) {
4446
84.6k
        case H5T_COPY_TRANSIENT:
4447
            /*
4448
             * Return an unlocked transient type.
4449
             */
4450
84.6k
            new_dt->shared->state = H5T_STATE_TRANSIENT;
4451
84.6k
            copyfn                = H5T__copy_transient;
4452
84.6k
            break;
4453
4454
78.0k
        case H5T_COPY_ALL:
4455
            /*
4456
             * Return a transient type (locked or unlocked) or an unopened named
4457
             * type.  Immutable transient types are degraded to read-only.
4458
             */
4459
78.0k
            if (H5T_STATE_OPEN == old_dt->shared->state)
4460
0
                new_dt->shared->state = H5T_STATE_NAMED;
4461
78.0k
            else if (H5T_STATE_IMMUTABLE == old_dt->shared->state)
4462
2.83k
                new_dt->shared->state = H5T_STATE_RDONLY;
4463
78.0k
            copyfn = H5T__copy_all;
4464
78.0k
            break;
4465
4466
0
        default:
4467
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, NULL, "invalid copy method type");
4468
162k
    } /* end switch */
4469
4470
    /* Finish making the copy of the datatype */
4471
162k
    if (H5T__complete_copy(new_dt, old_dt, NULL, (method == H5T_COPY_TRANSIENT), copyfn) < 0)
4472
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "can't complete datatype initialization");
4473
4474
    /* Set return value */
4475
162k
    ret_value = new_dt;
4476
4477
162k
done:
4478
162k
    if (ret_value == NULL)
4479
0
        if (new_dt) {
4480
0
            assert(new_dt->shared);
4481
0
            if (new_dt->shared->owned_vol_obj && H5VL_free_object(new_dt->shared->owned_vol_obj) < 0)
4482
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close owned VOL object");
4483
0
            new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared);
4484
0
            new_dt         = H5FL_FREE(H5T_t, new_dt);
4485
0
        } /* end if */
4486
4487
162k
    FUNC_LEAVE_NOAPI(ret_value)
4488
162k
} /* end H5T_copy() */
4489
4490
/*-------------------------------------------------------------------------
4491
 * Function:  H5T_copy_reopen
4492
 *
4493
 * Purpose:   Copy a datatype, possibly reopening a named datatype, as part
4494
 *            the const-correct datatype copying routines.
4495
 *
4496
 * Return:    Success:    Pointer to a new copy of the OLD_DT argument.
4497
 *            Failure:    NULL
4498
 *
4499
 *-------------------------------------------------------------------------
4500
 */
4501
H5T_t *
4502
H5T_copy_reopen(H5T_t *old_dt)
4503
163k
{
4504
163k
    H5T_t        *new_dt      = NULL; /* New datatype */
4505
163k
    H5T_shared_t *reopened_fo = NULL; /* Pointer to reopened existing named datatype */
4506
163k
    H5T_t        *ret_value   = NULL; /* Return value */
4507
4508
163k
    FUNC_ENTER_NOAPI(NULL)
4509
4510
    /* check args */
4511
163k
    assert(old_dt);
4512
4513
    /* Allocate and copy core datatype information */
4514
163k
    if (NULL == (new_dt = H5T__initiate_copy(old_dt)))
4515
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy core datatype info");
4516
4517
    /*
4518
     * Return a transient type (locked or unlocked) or an opened named
4519
     * type.  Immutable transient types are degraded to read-only.
4520
     */
4521
163k
    if (old_dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED) {
4522
        /* Check if the object is already open */
4523
0
        if (NULL ==
4524
0
            (reopened_fo = (H5T_shared_t *)H5FO_opened(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr))) {
4525
            /* Clear any errors from H5FO_opened() */
4526
0
            H5E_clear_stack();
4527
4528
            /* Open named datatype again */
4529
0
            if (H5O_open(&old_dt->oloc) < 0)
4530
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to reopen named data type");
4531
4532
            /* Insert opened named datatype into opened object list for the file */
4533
0
            if (H5FO_insert(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr, new_dt->shared, false) < 0)
4534
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, NULL,
4535
0
                            "can't insert datatype into list of open objects");
4536
4537
            /* Increment object count for the object in the top file */
4538
0
            if (H5FO_top_incr(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) < 0)
4539
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, NULL, "can't increment object count");
4540
4541
0
            new_dt->shared->fo_count = 1;
4542
0
        } /* end if */
4543
0
        else {
4544
            /* The object is already open.  Free the H5T_shared_t struct
4545
             * we had been using and use the one that already exists.
4546
             * Not terribly efficient. */
4547
0
            if (new_dt->shared->owned_vol_obj && H5VL_free_object(new_dt->shared->owned_vol_obj) < 0)
4548
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close owned VOL object");
4549
0
            new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared);
4550
0
            new_dt->shared = reopened_fo;
4551
4552
0
            reopened_fo->fo_count++;
4553
4554
            /* Check if the object has been opened through the top file yet */
4555
0
            if (H5FO_top_count(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) == 0) {
4556
                /* Open the object through this top file */
4557
0
                if (H5O_open(&old_dt->oloc) < 0)
4558
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to open object header");
4559
0
            } /* end if */
4560
4561
            /* Increment object count for the object in the top file */
4562
0
            if (H5FO_top_incr(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) < 0)
4563
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, NULL, "can't increment object count");
4564
0
        } /* end else */
4565
4566
        /* Set state for new datatype */
4567
0
        new_dt->shared->state = H5T_STATE_OPEN;
4568
0
    } /* end if */
4569
163k
    else
4570
        /* Downgrade immutable datatypes to read-only */
4571
163k
        if (H5T_STATE_IMMUTABLE == old_dt->shared->state)
4572
0
            new_dt->shared->state = H5T_STATE_RDONLY;
4573
4574
    /* Finish making the copy of the datatype */
4575
163k
    if (H5T__complete_copy(new_dt, old_dt, reopened_fo, true, H5T_copy_reopen) < 0)
4576
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "can't complete datatype initialization");
4577
4578
    /* Set return value */
4579
163k
    ret_value = new_dt;
4580
4581
163k
done:
4582
163k
    if (ret_value == NULL)
4583
0
        if (new_dt) {
4584
0
            assert(new_dt->shared);
4585
0
            if (new_dt->shared->owned_vol_obj && H5VL_free_object(new_dt->shared->owned_vol_obj) < 0)
4586
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close owned VOL object");
4587
0
            new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared);
4588
0
            new_dt         = H5FL_FREE(H5T_t, new_dt);
4589
0
        } /* end if */
4590
4591
163k
    FUNC_LEAVE_NOAPI(ret_value)
4592
163k
} /* end H5T_copy_reopen() */
4593
4594
/*-------------------------------------------------------------------------
4595
 * Function:  H5T_lock
4596
 *
4597
 * Purpose:   Lock a transient data type making it read-only.  If IMMUTABLE
4598
 *        is set then the type cannot be closed except when the library
4599
 *        itself closes.
4600
 *
4601
 *        This function is a no-op if the type is not transient or if
4602
 *        the type is already read-only or immutable.
4603
 *
4604
 * Return:    Non-negative on success/Negative on failure
4605
 *
4606
 *-------------------------------------------------------------------------
4607
 */
4608
herr_t
4609
H5T_lock(H5T_t *dt, bool immutable)
4610
151k
{
4611
151k
    herr_t ret_value = SUCCEED; /* Return value */
4612
4613
151k
    FUNC_ENTER_NOAPI(FAIL)
4614
4615
151k
    assert(dt);
4616
4617
151k
    switch (dt->shared->state) {
4618
151k
        case H5T_STATE_TRANSIENT:
4619
151k
            dt->shared->state = immutable ? H5T_STATE_IMMUTABLE : H5T_STATE_RDONLY;
4620
151k
            break;
4621
0
        case H5T_STATE_RDONLY:
4622
0
            if (immutable)
4623
0
                dt->shared->state = H5T_STATE_IMMUTABLE;
4624
0
            break;
4625
0
        case H5T_STATE_IMMUTABLE:
4626
0
        case H5T_STATE_NAMED:
4627
0
        case H5T_STATE_OPEN:
4628
            /*void*/
4629
0
            break;
4630
0
        default:
4631
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "invalid datatype state");
4632
151k
    }
4633
4634
151k
done:
4635
151k
    FUNC_LEAVE_NOAPI(ret_value)
4636
151k
}
4637
4638
/*-------------------------------------------------------------------------
4639
 * Function:  H5T__alloc
4640
 *
4641
 * Purpose:   Allocates a new H5T_t structure, initializing it correctly.
4642
 *
4643
 * Return:    Pointer to new H5T_t on success/NULL on failure
4644
 *
4645
 *-------------------------------------------------------------------------
4646
 */
4647
H5T_t *
4648
H5T__alloc(void)
4649
134k
{
4650
134k
    H5T_t *dt        = NULL; /* Pointer to datatype allocated */
4651
134k
    H5T_t *ret_value = NULL; /* Return value */
4652
4653
134k
    FUNC_ENTER_PACKAGE
4654
4655
    /* Allocate & initialize datatype wrapper info */
4656
134k
    if (NULL == (dt = H5FL_CALLOC(H5T_t)))
4657
0
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
4658
134k
    H5O_loc_reset(&(dt->oloc));
4659
134k
    H5G_name_reset(&(dt->path));
4660
134k
    H5O_msg_reset_share(H5O_DTYPE_ID, dt);
4661
4662
    /* Allocate & initialize shared datatype structure */
4663
134k
    if (NULL == (dt->shared = H5FL_CALLOC(H5T_shared_t)))
4664
0
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
4665
134k
    dt->shared->version = H5O_DTYPE_VERSION_1;
4666
4667
    /* No VOL object initially */
4668
134k
    dt->vol_obj = NULL;
4669
4670
    /* Assign return value */
4671
134k
    ret_value = dt;
4672
4673
134k
done:
4674
134k
    if (ret_value == NULL)
4675
0
        if (dt) {
4676
0
            if (dt->shared) {
4677
0
                assert(!dt->shared->owned_vol_obj);
4678
0
                dt->shared = H5FL_FREE(H5T_shared_t, dt->shared);
4679
0
            } /* end if */
4680
0
            dt = H5FL_FREE(H5T_t, dt);
4681
0
        } /* end if */
4682
4683
134k
    FUNC_LEAVE_NOAPI(ret_value)
4684
134k
} /* end H5T__alloc() */
4685
4686
/*-------------------------------------------------------------------------
4687
 * Function:  H5T__free
4688
 *
4689
 * Purpose:   Frees all memory associated with a datatype, but does not
4690
 *            free the H5T_t or H5T_shared_t structures (which should
4691
 *            be done in H5T_close / H5T_close_real).
4692
 *
4693
 * Return:    Non-negative on success/Negative on failure
4694
 *
4695
 *-------------------------------------------------------------------------
4696
 */
4697
herr_t
4698
H5T__free(H5T_t *dt)
4699
508k
{
4700
508k
    unsigned i;
4701
508k
    herr_t   ret_value = SUCCEED; /* Return value */
4702
4703
508k
    FUNC_ENTER_PACKAGE
4704
4705
508k
    assert(dt && dt->shared);
4706
4707
    /* Free the ID to name info */
4708
508k
    H5G_name_free(&(dt->path));
4709
4710
    /* Don't free locked datatypes */
4711
508k
    if (H5T_STATE_IMMUTABLE == dt->shared->state)
4712
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close immutable datatype");
4713
4714
    /* Close the datatype */
4715
508k
    switch (dt->shared->type) {
4716
182
        case H5T_COMPOUND:
4717
189
            for (i = 0; i < dt->shared->u.compnd.nmembs; i++) {
4718
7
                dt->shared->u.compnd.memb[i].name = (char *)H5MM_xfree(dt->shared->u.compnd.memb[i].name);
4719
7
                if (H5T_close_real(dt->shared->u.compnd.memb[i].type) < 0)
4720
                    /* Push errors, but keep going */
4721
0
                    HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL,
4722
7
                                "unable to close datatype for compound member");
4723
7
            }
4724
182
            dt->shared->u.compnd.memb   = (H5T_cmemb_t *)H5MM_xfree(dt->shared->u.compnd.memb);
4725
182
            dt->shared->u.compnd.nmembs = 0;
4726
182
            break;
4727
4728
65
        case H5T_ENUM:
4729
65
            for (i = 0; i < dt->shared->u.enumer.nmembs; i++)
4730
0
                dt->shared->u.enumer.name[i] = (char *)H5MM_xfree(dt->shared->u.enumer.name[i]);
4731
65
            dt->shared->u.enumer.name   = (char **)H5MM_xfree(dt->shared->u.enumer.name);
4732
65
            dt->shared->u.enumer.value  = (uint8_t *)H5MM_xfree(dt->shared->u.enumer.value);
4733
65
            dt->shared->u.enumer.nmembs = 0;
4734
65
            break;
4735
4736
667
        case H5T_OPAQUE:
4737
667
            dt->shared->u.opaque.tag = (char *)H5MM_xfree(dt->shared->u.opaque.tag);
4738
667
            break;
4739
4740
47.7k
        case H5T_NO_CLASS:
4741
163k
        case H5T_INTEGER:
4742
232k
        case H5T_FLOAT:
4743
232k
        case H5T_TIME:
4744
440k
        case H5T_STRING:
4745
441k
        case H5T_BITFIELD:
4746
486k
        case H5T_REFERENCE:
4747
506k
        case H5T_VLEN:
4748
506k
        case H5T_ARRAY:
4749
507k
        case H5T_COMPLEX:
4750
507k
        case H5T_NCLASSES:
4751
507k
        default:
4752
507k
            break;
4753
508k
    } /* end switch */
4754
508k
    dt->shared->type = H5T_NO_CLASS;
4755
4756
    /* Close the parent */
4757
508k
    assert(dt->shared->parent != dt);
4758
508k
    if (dt->shared->parent && H5T_close_real(dt->shared->parent) < 0)
4759
        /* Push errors, but keep going */
4760
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close parent data type");
4761
508k
    dt->shared->parent = NULL;
4762
4763
    /* Close the owned VOL object */
4764
508k
    if (dt->shared->owned_vol_obj && H5VL_free_object(dt->shared->owned_vol_obj) < 0)
4765
        /* Push errors, but keep going */
4766
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close owned VOL object");
4767
508k
    dt->shared->owned_vol_obj = NULL;
4768
4769
508k
done:
4770
508k
    FUNC_LEAVE_NOAPI(ret_value)
4771
508k
} /* end H5T__free() */
4772
4773
/*-------------------------------------------------------------------------
4774
 * Function:  H5T_close_real
4775
 *
4776
 * Purpose:   Frees a datatype and all associated memory.
4777
 *
4778
 * Note:      Does _not_ deal with open named datatypes, etc. so this
4779
 *            should never see a type managed by a VOL connector.
4780
 *
4781
 * Return:    Non-negative on success/Negative on failure
4782
 *
4783
 *-------------------------------------------------------------------------
4784
 */
4785
herr_t
4786
H5T_close_real(H5T_t *dt)
4787
463k
{
4788
463k
    herr_t ret_value = SUCCEED; /* Return value */
4789
4790
463k
    FUNC_ENTER_NOAPI(FAIL)
4791
4792
    /* Sanity check */
4793
463k
    assert(dt);
4794
4795
    /* Clean up resources, depending on shared state */
4796
463k
    if (dt->shared && (dt->shared->state != H5T_STATE_OPEN)) {
4797
460k
        if (H5T__free(dt) < 0)
4798
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free datatype");
4799
4800
460k
        assert(!dt->shared->owned_vol_obj);
4801
460k
        dt->shared = H5FL_FREE(H5T_shared_t, dt->shared);
4802
460k
    } /* end if */
4803
2.90k
    else
4804
        /* Free the group hier. path since we're not calling H5T__free() */
4805
2.90k
        H5G_name_free(&(dt->path));
4806
4807
    /* Free the 'top' datatype struct */
4808
463k
    dt = H5FL_FREE(H5T_t, dt);
4809
4810
463k
done:
4811
463k
    FUNC_LEAVE_NOAPI(ret_value)
4812
463k
} /* end H5T_close_real() */
4813
4814
/*-------------------------------------------------------------------------
4815
 * Function:    H5T_close
4816
 *
4817
 * Purpose:     Frees a data type and all associated memory.  Deals with
4818
 *              open named datatypes appropriately.
4819
 *
4820
 * Return:      Non-negative on success/Negative on failure
4821
 *
4822
 *-------------------------------------------------------------------------
4823
 */
4824
herr_t
4825
H5T_close(H5T_t *dt)
4826
289k
{
4827
289k
    herr_t ret_value = SUCCEED; /* Return value */
4828
4829
289k
    FUNC_ENTER_NOAPI(FAIL)
4830
4831
    /* Sanity check */
4832
289k
    assert(dt);
4833
4834
    /* Named datatype cleanups */
4835
289k
    if (dt->shared && (dt->shared->state == H5T_STATE_OPEN)) {
4836
        /* Decrement refcount count on open named datatype */
4837
3.22k
        dt->shared->fo_count--;
4838
4839
        /* Sanity checks */
4840
3.22k
        assert(dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED);
4841
3.22k
        assert(H5_addr_defined(dt->sh_loc.u.loc.oh_addr));
4842
3.22k
        assert(H5_addr_defined(dt->oloc.addr));
4843
4844
        /* If a named type is being closed then close the object header and
4845
         * remove from the list of open objects in the file.
4846
         */
4847
4848
        /* Decrement the ref. count for this object in the top file */
4849
3.22k
        if (H5FO_top_decr(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) < 0)
4850
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, FAIL, "can't decrement count for object");
4851
4852
        /* Close things down if this is the last reference to the open named datatype */
4853
3.22k
        if (0 == dt->shared->fo_count) {
4854
315
            bool corked; /* Whether the named datatype is corked or not */
4855
4856
            /* Uncork cache entries with object address tag for named datatype */
4857
315
            if (H5AC_cork(dt->oloc.file, dt->oloc.addr, H5AC__GET_CORKED, &corked) < 0)
4858
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve an object's cork status");
4859
315
            if (corked)
4860
0
                if (H5AC_cork(dt->oloc.file, dt->oloc.addr, H5AC__UNCORK, NULL) < 0)
4861
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTUNCORK, FAIL, "unable to uncork an object");
4862
4863
            /* Remove the datatype from the list of opened objects in the file */
4864
315
            if (H5FO_delete(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) < 0)
4865
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, FAIL,
4866
315
                            "can't remove datatype from list of open objects");
4867
315
            if (H5O_close(&dt->oloc, NULL) < 0)
4868
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to close data type object header");
4869
4870
            /* Mark named datatype closed now */
4871
315
            dt->shared->state = H5T_STATE_NAMED;
4872
315
        } /* end if */
4873
2.90k
        else {
4874
            /* Check reference count for this object in the top file */
4875
2.90k
            if (H5FO_top_count(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) == 0) {
4876
                /* Close object location for named datatype */
4877
0
                if (H5O_close(&dt->oloc, NULL) < 0)
4878
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to close");
4879
0
            } /* end if */
4880
2.90k
            else
4881
                /* Free object location (i.e. "unhold" the file if appropriate) */
4882
2.90k
                if (H5O_loc_free(&(dt->oloc)) < 0)
4883
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, FAIL, "problem attempting to free location");
4884
2.90k
        } /* end else */
4885
3.22k
    }     /* end if */
4886
4887
    /* Clean up resources */
4888
289k
    if (H5T_close_real(dt) < 0)
4889
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, FAIL, "unable to free datatype");
4890
4891
289k
done:
4892
289k
    FUNC_LEAVE_NOAPI(ret_value)
4893
289k
} /* end H5T_close() */
4894
4895
/*-------------------------------------------------------------------------
4896
 * Function:    H5T__set_size
4897
 *
4898
 * Purpose:    Sets the total size in bytes for a data type (this operation
4899
 *        is not permitted on reference data types).  If the size is
4900
 *        decreased so that the significant bits of the data type
4901
 *        extend beyond the edge of the new size, then the `offset'
4902
 *        property is decreased toward zero.  If the `offset' becomes
4903
 *        zero and the significant bits of the data type still hang
4904
 *        over the edge of the new size, then the number of significant
4905
 *        bits is decreased.
4906
 *
4907
 *        Adjusting the size of an H5T_STRING automatically sets the
4908
 *        precision to 8*size.
4909
 *
4910
 *        All data types have a positive size.
4911
 *
4912
 * Return:    Success:    non-negative
4913
 *
4914
 *            Failure:    negative
4915
 *
4916
 *-------------------------------------------------------------------------
4917
 */
4918
static herr_t
4919
H5T__set_size(H5T_t *dt, size_t size)
4920
57.6k
{
4921
57.6k
    size_t prec, offset;
4922
57.6k
    herr_t ret_value = SUCCEED; /* Return value */
4923
4924
57.6k
    FUNC_ENTER_PACKAGE
4925
4926
    /* Check args */
4927
57.6k
    assert(dt);
4928
57.6k
    assert(dt->shared);
4929
57.6k
    assert(size != 0);
4930
57.6k
    assert(H5T_ARRAY != dt->shared->type);
4931
57.6k
    assert(H5T_REFERENCE != dt->shared->type);
4932
57.6k
    assert(H5T_COMPLEX != dt->shared->type);
4933
57.6k
    assert(H5T_VLEN != dt->shared->type || H5T_VLEN_STRING == dt->shared->u.vlen.type);
4934
57.6k
    assert(!(H5T_ENUM == dt->shared->type && 0 == dt->shared->u.enumer.nmembs));
4935
4936
57.6k
    if (dt->shared->parent) {
4937
0
        if (H5T__set_size(dt->shared->parent, size) < 0)
4938
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set size for parent data type");
4939
0
    }
4940
57.6k
    else {
4941
57.6k
        if (H5T_IS_ATOMIC(dt->shared)) {
4942
57.6k
            offset = dt->shared->u.atomic.offset;
4943
57.6k
            prec   = dt->shared->u.atomic.prec;
4944
4945
            /* Decrement the offset and precision if necessary */
4946
57.6k
            if (prec > 8 * size)
4947
0
                offset = 0;
4948
57.6k
            else if (offset + prec > 8 * size)
4949
0
                offset = 8 * size - prec;
4950
57.6k
            if (prec > 8 * size)
4951
0
                prec = 8 * size;
4952
57.6k
        }
4953
0
        else
4954
0
            prec = offset = 0;
4955
4956
57.6k
        switch (dt->shared->type) {
4957
0
            case H5T_INTEGER:
4958
0
            case H5T_TIME:
4959
0
            case H5T_BITFIELD:
4960
0
            case H5T_OPAQUE:
4961
                /* nothing to check */
4962
0
                break;
4963
4964
0
            case H5T_COMPOUND:
4965
                /* If decreasing size, check the last member isn't being cut. */
4966
0
                if (size < dt->shared->size) {
4967
0
                    int      num_membs = 0;
4968
0
                    unsigned i, max_index            = 0;
4969
0
                    size_t   memb_offset, max_offset = 0;
4970
0
                    size_t   max_size;
4971
4972
0
                    if ((num_membs = H5T_get_nmembers(dt)) < 0)
4973
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to get number of members");
4974
4975
0
                    if (num_membs) {
4976
0
                        for (i = 0; i < (unsigned)num_membs; i++) {
4977
0
                            memb_offset = H5T_get_member_offset(dt, i);
4978
0
                            if (memb_offset > max_offset) {
4979
0
                                max_offset = memb_offset;
4980
0
                                max_index  = i;
4981
0
                            } /* end if */
4982
0
                        }     /* end for */
4983
4984
0
                        max_size = H5T__get_member_size(dt, max_index);
4985
4986
0
                        if (size < (max_offset + max_size))
4987
0
                            HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
4988
0
                                        "size shrinking will cut off last member ");
4989
0
                    } /* end if */
4990
4991
                    /* Compound must not have been packed previously */
4992
                    /* We will check if resizing changed the packed state of
4993
                     * this type at the end of this function */
4994
0
                    assert(!dt->shared->u.compnd.packed);
4995
0
                } /* end if */
4996
4997
0
                break;
4998
4999
57.6k
            case H5T_STRING:
5000
                /* Convert string to variable-length datatype */
5001
57.6k
                if (size == H5T_VARIABLE) {
5002
0
                    H5T_t     *base = NULL; /* base data type */
5003
0
                    H5T_cset_t tmp_cset;    /* Temp. cset info */
5004
0
                    H5T_str_t  tmp_strpad;  /* Temp. strpad info */
5005
5006
                    /* Get a copy of unsigned char type as the base/parent type */
5007
0
                    if (NULL == (base = (H5T_t *)H5I_object(H5T_NATIVE_UCHAR)))
5008
0
                        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid base datatype");
5009
0
                    if (NULL == (dt->shared->parent = H5T_copy(base, H5T_COPY_ALL)))
5010
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy base datatype");
5011
5012
                    /* change this datatype into a VL string */
5013
0
                    dt->shared->type = H5T_VLEN;
5014
5015
                    /*
5016
                     * Force conversions (i.e. memory to memory conversions
5017
                     * should duplicate data, not point to the same VL strings)
5018
                     */
5019
0
                    dt->shared->force_conv = true;
5020
5021
                    /* Before we mess with the info in the union, extract the
5022
                     * values we need */
5023
0
                    tmp_cset   = dt->shared->u.atomic.u.s.cset;
5024
0
                    tmp_strpad = dt->shared->u.atomic.u.s.pad;
5025
5026
                    /* This is a string, not a sequence */
5027
0
                    dt->shared->u.vlen.type = H5T_VLEN_STRING;
5028
5029
                    /* Set character set and padding information */
5030
0
                    dt->shared->u.vlen.cset = tmp_cset;
5031
0
                    dt->shared->u.vlen.pad  = tmp_strpad;
5032
5033
                    /* Set up VL information */
5034
0
                    if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0)
5035
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location");
5036
0
                } /* end if */
5037
57.6k
                else {
5038
57.6k
                    prec   = 8 * size;
5039
57.6k
                    offset = 0;
5040
57.6k
                } /* end else */
5041
57.6k
                break;
5042
5043
57.6k
            case H5T_FLOAT:
5044
                /*
5045
                 * The sign, mantissa, and exponent fields should be adjusted
5046
                 * first when decreasing the size of a floating point type.
5047
                 */
5048
0
                if (dt->shared->u.atomic.u.f.sign >= prec + offset ||
5049
0
                    dt->shared->u.atomic.u.f.epos + dt->shared->u.atomic.u.f.esize > prec + offset ||
5050
0
                    dt->shared->u.atomic.u.f.mpos + dt->shared->u.atomic.u.f.msize > prec + offset) {
5051
0
                    HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
5052
0
                                "adjust sign, mantissa, and exponent fields first");
5053
0
                }
5054
0
                break;
5055
5056
0
            case H5T_ENUM:
5057
0
            case H5T_VLEN:
5058
0
            case H5T_ARRAY:
5059
0
            case H5T_REFERENCE:
5060
0
            case H5T_COMPLEX:
5061
0
                assert("can't happen" && 0);
5062
0
                break;
5063
5064
0
            case H5T_NO_CLASS:
5065
0
            case H5T_NCLASSES:
5066
0
                assert("invalid type" && 0);
5067
0
                break;
5068
5069
0
            default:
5070
0
                assert("not implemented yet" && 0);
5071
0
                break;
5072
57.6k
        } /* end switch */
5073
5074
        /* Commit (if we didn't convert this type to a VL string) */
5075
57.6k
        if (dt->shared->type != H5T_VLEN) {
5076
57.6k
            dt->shared->size = size;
5077
57.6k
            if (H5T_IS_ATOMIC(dt->shared)) {
5078
57.6k
                dt->shared->u.atomic.offset = offset;
5079
57.6k
                dt->shared->u.atomic.prec   = prec;
5080
57.6k
            }
5081
57.6k
        } /* end if */
5082
5083
        /* Check if the new compound type is packed */
5084
57.6k
        if (dt->shared->type == H5T_COMPOUND)
5085
0
            H5T__update_packed(dt);
5086
57.6k
    } /* end else */
5087
5088
57.6k
done:
5089
57.6k
    FUNC_LEAVE_NOAPI(ret_value)
5090
57.6k
} /* end H5T__set_size() */
5091
5092
/*-------------------------------------------------------------------------
5093
 * Function:  H5T_get_size
5094
 *
5095
 * Purpose:   Determines the total size of a data type in bytes.
5096
 *
5097
 * Return:    Success:    Size of the data type in bytes.     The size of
5098
 *                the data type is the size of an instance of
5099
 *                that data type.
5100
 *
5101
 *            Failure:    0 (valid data types are never zero size)
5102
 *
5103
 *-------------------------------------------------------------------------
5104
 */
5105
size_t
5106
H5T_get_size(const H5T_t *dt)
5107
415k
{
5108
    /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
5109
415k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
5110
5111
    /* check args */
5112
415k
    assert(dt);
5113
415k
    assert(dt->shared);
5114
5115
415k
    FUNC_LEAVE_NOAPI(dt->shared->size)
5116
415k
} /* end H5T_get_size() */
5117
5118
/*-------------------------------------------------------------------------
5119
 * Function:  H5T_cmp
5120
 *
5121
 * Purpose:   Compares two data types.
5122
 *
5123
 * Return:    Success:    0 if DT1 and DT2 are equal.
5124
 *                       <0 if DT1 is less than DT2.
5125
 *                       >0 if DT1 is greater than DT2.
5126
 *
5127
 *            Failure:    0, never fails
5128
 *
5129
 *-------------------------------------------------------------------------
5130
 */
5131
int
5132
H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, bool superset)
5133
936k
{
5134
936k
    unsigned *idx1 = NULL, *idx2 = NULL;
5135
936k
    size_t    base_size;
5136
936k
    bool      swapped;
5137
936k
    unsigned  u;
5138
936k
    int       tmp;
5139
936k
    int       ret_value = 0;
5140
5141
936k
    FUNC_ENTER_NOAPI(0)
5142
5143
    /* Sanity check */
5144
936k
    assert(dt1);
5145
936k
    assert(dt2);
5146
5147
    /* the easy case */
5148
936k
    if (dt1 == dt2)
5149
6
        HGOTO_DONE(0);
5150
5151
936k
    assert(dt1->shared);
5152
936k
    assert(dt2->shared);
5153
5154
    /* compare */
5155
936k
    if (dt1->shared->type < dt2->shared->type)
5156
204k
        HGOTO_DONE(-1);
5157
731k
    if (dt1->shared->type > dt2->shared->type)
5158
189k
        HGOTO_DONE(1);
5159
5160
542k
    if (dt1->shared->size < dt2->shared->size)
5161
102k
        HGOTO_DONE(-1);
5162
439k
    if (dt1->shared->size > dt2->shared->size)
5163
65.7k
        HGOTO_DONE(1);
5164
5165
374k
    if (dt1->shared->parent && !dt2->shared->parent)
5166
0
        HGOTO_DONE(-1);
5167
374k
    if (!dt1->shared->parent && dt2->shared->parent)
5168
0
        HGOTO_DONE(1);
5169
374k
    if (dt1->shared->parent) {
5170
24.1k
        tmp = H5T_cmp(dt1->shared->parent, dt2->shared->parent, superset);
5171
24.1k
        if (tmp < 0)
5172
1.27k
            HGOTO_DONE(-1);
5173
22.8k
        if (tmp > 0)
5174
303
            HGOTO_DONE(1);
5175
22.8k
    } /* end if */
5176
5177
372k
    switch (dt1->shared->type) {
5178
0
        case H5T_COMPOUND:
5179
            /*
5180
             * Compound data types...
5181
             */
5182
0
            if (dt1->shared->u.compnd.nmembs == 0 && dt2->shared->u.compnd.nmembs == 0)
5183
0
                HGOTO_DONE(0);
5184
0
            if (dt1->shared->u.compnd.nmembs < dt2->shared->u.compnd.nmembs)
5185
0
                HGOTO_DONE(-1);
5186
0
            if (dt1->shared->u.compnd.nmembs > dt2->shared->u.compnd.nmembs)
5187
0
                HGOTO_DONE(1);
5188
5189
            /* Build an index for each type so the names are sorted */
5190
0
            if (NULL == (idx1 = (unsigned *)H5MM_malloc(dt1->shared->u.compnd.nmembs * sizeof(unsigned))) ||
5191
0
                NULL == (idx2 = (unsigned *)H5MM_malloc(dt2->shared->u.compnd.nmembs * sizeof(unsigned))))
5192
0
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed");
5193
0
            for (u = 0; u < dt1->shared->u.compnd.nmembs; u++)
5194
0
                idx1[u] = idx2[u] = u;
5195
0
            if (dt1->shared->u.enumer.nmembs > 1) {
5196
0
                int i;
5197
5198
0
                for (i = (int)dt1->shared->u.compnd.nmembs - 1, swapped = true; swapped && i >= 0; --i) {
5199
0
                    int j;
5200
5201
0
                    for (j = 0, swapped = false; j < i; j++)
5202
0
                        if (strcmp(dt1->shared->u.compnd.memb[idx1[j]].name,
5203
0
                                   dt1->shared->u.compnd.memb[idx1[j + 1]].name) > 0) {
5204
0
                            unsigned tmp_idx = idx1[j];
5205
0
                            idx1[j]          = idx1[j + 1];
5206
0
                            idx1[j + 1]      = tmp_idx;
5207
0
                            swapped          = true;
5208
0
                        }
5209
0
                }
5210
0
                for (i = (int)dt2->shared->u.compnd.nmembs - 1, swapped = true; swapped && i >= 0; --i) {
5211
0
                    int j;
5212
5213
0
                    for (j = 0, swapped = false; j < i; j++)
5214
0
                        if (strcmp(dt2->shared->u.compnd.memb[idx2[j]].name,
5215
0
                                   dt2->shared->u.compnd.memb[idx2[j + 1]].name) > 0) {
5216
0
                            unsigned tmp_idx = idx2[j];
5217
0
                            idx2[j]          = idx2[j + 1];
5218
0
                            idx2[j + 1]      = tmp_idx;
5219
0
                            swapped          = true;
5220
0
                        }
5221
0
                }
5222
0
            } /* end if */
5223
5224
#ifdef H5T_DEBUG
5225
            /* I don't quite trust the code above yet :-)  --RPM */
5226
            if (dt1->shared->u.compnd.nmembs > 0) {
5227
                for (u = 0; u < dt1->shared->u.compnd.nmembs - 1; u++) {
5228
                    assert(strcmp(dt1->shared->u.compnd.memb[idx1[u]].name,
5229
                                  dt1->shared->u.compnd.memb[idx1[u + 1]].name));
5230
                    assert(strcmp(dt2->shared->u.compnd.memb[idx2[u]].name,
5231
                                  dt2->shared->u.compnd.memb[idx2[u + 1]].name));
5232
                }
5233
            }
5234
#endif
5235
5236
            /* Compare the members */
5237
0
            for (u = 0; u < dt1->shared->u.compnd.nmembs; u++) {
5238
0
                tmp = strcmp(dt1->shared->u.compnd.memb[idx1[u]].name,
5239
0
                             dt2->shared->u.compnd.memb[idx2[u]].name);
5240
0
                if (tmp < 0)
5241
0
                    HGOTO_DONE(-1);
5242
0
                if (tmp > 0)
5243
0
                    HGOTO_DONE(1);
5244
5245
0
                if (dt1->shared->u.compnd.memb[idx1[u]].offset < dt2->shared->u.compnd.memb[idx2[u]].offset)
5246
0
                    HGOTO_DONE(-1);
5247
0
                if (dt1->shared->u.compnd.memb[idx1[u]].offset > dt2->shared->u.compnd.memb[idx2[u]].offset)
5248
0
                    HGOTO_DONE(1);
5249
5250
0
                if (dt1->shared->u.compnd.memb[idx1[u]].size < dt2->shared->u.compnd.memb[idx2[u]].size)
5251
0
                    HGOTO_DONE(-1);
5252
0
                if (dt1->shared->u.compnd.memb[idx1[u]].size > dt2->shared->u.compnd.memb[idx2[u]].size)
5253
0
                    HGOTO_DONE(1);
5254
5255
0
                tmp = H5T_cmp(dt1->shared->u.compnd.memb[idx1[u]].type,
5256
0
                              dt2->shared->u.compnd.memb[idx2[u]].type, superset);
5257
0
                if (tmp < 0)
5258
0
                    HGOTO_DONE(-1);
5259
0
                if (tmp > 0)
5260
0
                    HGOTO_DONE(1);
5261
0
            }
5262
0
            break;
5263
5264
0
        case H5T_ENUM:
5265
            /*
5266
             * Enumeration data types...
5267
             */
5268
0
            if (dt1->shared->u.enumer.nmembs == 0 && dt2->shared->u.enumer.nmembs == 0)
5269
0
                HGOTO_DONE(0);
5270
5271
            /* If we are doing a "superset" comparison, dt2 is allowed to have
5272
             * more members than dt1
5273
             */
5274
0
            if (superset) {
5275
0
                if (dt1->shared->u.enumer.nmembs > dt2->shared->u.enumer.nmembs)
5276
0
                    HGOTO_DONE(1);
5277
0
            } /* end if */
5278
0
            else {
5279
0
                if (dt1->shared->u.enumer.nmembs < dt2->shared->u.enumer.nmembs)
5280
0
                    HGOTO_DONE(-1);
5281
0
                if (dt1->shared->u.enumer.nmembs > dt2->shared->u.enumer.nmembs)
5282
0
                    HGOTO_DONE(1);
5283
0
            } /* end else */
5284
5285
            /* Build an index for each type so the names are sorted */
5286
0
            if (NULL == (idx1 = (unsigned *)H5MM_malloc(dt1->shared->u.enumer.nmembs * sizeof(unsigned))) ||
5287
0
                NULL == (idx2 = (unsigned *)H5MM_malloc(dt2->shared->u.enumer.nmembs * sizeof(unsigned))))
5288
0
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed");
5289
0
            for (u = 0; u < dt1->shared->u.enumer.nmembs; u++)
5290
0
                idx1[u] = u;
5291
0
            if (dt1->shared->u.enumer.nmembs > 1) {
5292
0
                int i;
5293
0
                for (i = (int)dt1->shared->u.enumer.nmembs - 1, swapped = true; swapped && i >= 0; --i) {
5294
0
                    int j;
5295
5296
0
                    for (j = 0, swapped = false; j < i; j++)
5297
0
                        if (strcmp(dt1->shared->u.enumer.name[idx1[j]],
5298
0
                                   dt1->shared->u.enumer.name[idx1[j + 1]]) > 0) {
5299
0
                            unsigned tmp_idx = idx1[j];
5300
0
                            idx1[j]          = idx1[j + 1];
5301
0
                            idx1[j + 1]      = tmp_idx;
5302
0
                            swapped          = true;
5303
0
                        }
5304
0
                }
5305
0
            }
5306
0
            for (u = 0; u < dt2->shared->u.enumer.nmembs; u++)
5307
0
                idx2[u] = u;
5308
0
            if (dt2->shared->u.enumer.nmembs > 1) {
5309
0
                int i;
5310
5311
0
                for (i = (int)dt2->shared->u.enumer.nmembs - 1, swapped = true; swapped && i >= 0; --i) {
5312
0
                    int j;
5313
5314
0
                    for (j = 0, swapped = false; j < i; j++)
5315
0
                        if (strcmp(dt2->shared->u.enumer.name[idx2[j]],
5316
0
                                   dt2->shared->u.enumer.name[idx2[j + 1]]) > 0) {
5317
0
                            unsigned tmp_idx = idx2[j];
5318
0
                            idx2[j]          = idx2[j + 1];
5319
0
                            idx2[j + 1]      = tmp_idx;
5320
0
                            swapped          = true;
5321
0
                        }
5322
0
                }
5323
0
            }
5324
5325
#ifdef H5T_DEBUG
5326
            /* I don't quite trust the code above yet :-)  --RPM */
5327
            if (dt1->shared->u.enumer.nmembs > 0) {
5328
                for (u = 0; u < dt1->shared->u.enumer.nmembs - 1; u++) {
5329
                    assert(
5330
                        strcmp(dt1->shared->u.enumer.name[idx1[u]], dt1->shared->u.enumer.name[idx1[u + 1]]));
5331
                    assert(
5332
                        strcmp(dt2->shared->u.enumer.name[idx2[u]], dt2->shared->u.enumer.name[idx2[u + 1]]));
5333
                }
5334
            }
5335
#endif
5336
5337
            /* Compare the members */
5338
0
            base_size = dt1->shared->parent->shared->size;
5339
0
            for (u = 0; u < dt1->shared->u.enumer.nmembs; u++) {
5340
0
                unsigned idx = 0;
5341
5342
0
                if (superset) {
5343
0
                    unsigned lt  = 0, rt; /* Final, left & right key indices */
5344
0
                    int      cmp = 1;     /* Key comparison value */
5345
5346
                    /* If a superset is allowed, dt2 may have more members
5347
                     * than dt1, so binary search for matching member name in
5348
                     * dt2
5349
                     */
5350
0
                    rt = dt2->shared->u.enumer.nmembs;
5351
5352
0
                    while (lt < rt && cmp) {
5353
0
                        idx = (lt + rt) / 2;
5354
5355
                        /* compare */
5356
0
                        if ((cmp = strcmp(dt1->shared->u.enumer.name[idx1[u]],
5357
0
                                          dt2->shared->u.enumer.name[idx2[idx]])) < 0)
5358
0
                            rt = idx;
5359
0
                        else
5360
0
                            lt = idx + 1;
5361
0
                    }
5362
                    /* Leave, if we couldn't find match */
5363
0
                    if (cmp)
5364
0
                        HGOTO_DONE(-1);
5365
0
                } /* end if */
5366
0
                else {
5367
                    /* Check for exact member name match when not doing
5368
                     * "superset" comparison
5369
                     */
5370
0
                    tmp = strcmp(dt1->shared->u.enumer.name[idx1[u]], dt2->shared->u.enumer.name[idx2[u]]);
5371
0
                    if (tmp < 0)
5372
0
                        HGOTO_DONE(-1);
5373
0
                    if (tmp > 0)
5374
0
                        HGOTO_DONE(1);
5375
5376
                    /* Set index value appropriately */
5377
0
                    idx = u;
5378
0
                } /* end else */
5379
5380
0
                tmp = memcmp((uint8_t *)dt1->shared->u.enumer.value + idx1[u] * base_size,
5381
0
                             (uint8_t *)dt2->shared->u.enumer.value + idx2[idx] * base_size, base_size);
5382
0
                if (tmp < 0)
5383
0
                    HGOTO_DONE(-1);
5384
0
                if (tmp > 0)
5385
0
                    HGOTO_DONE(1);
5386
0
            }
5387
0
            break;
5388
5389
21.8k
        case H5T_VLEN:
5390
21.8k
            assert(dt1->shared->u.vlen.type > H5T_VLEN_BADTYPE &&
5391
21.8k
                   dt1->shared->u.vlen.type < H5T_VLEN_MAXTYPE);
5392
21.8k
            assert(dt2->shared->u.vlen.type > H5T_VLEN_BADTYPE &&
5393
21.8k
                   dt2->shared->u.vlen.type < H5T_VLEN_MAXTYPE);
5394
21.8k
            assert(dt1->shared->u.vlen.loc >= H5T_LOC_BADLOC && dt1->shared->u.vlen.loc < H5T_LOC_MAXLOC);
5395
21.8k
            assert(dt2->shared->u.vlen.loc >= H5T_LOC_BADLOC && dt2->shared->u.vlen.loc < H5T_LOC_MAXLOC);
5396
5397
            /* Arbitrarily sort sequence VL datatypes before string VL datatypes */
5398
21.8k
            if (dt1->shared->u.vlen.type == H5T_VLEN_SEQUENCE &&
5399
21.8k
                dt2->shared->u.vlen.type == H5T_VLEN_STRING) {
5400
0
                HGOTO_DONE(-1);
5401
0
            }
5402
21.8k
            else if (dt1->shared->u.vlen.type == H5T_VLEN_STRING &&
5403
0
                     dt2->shared->u.vlen.type == H5T_VLEN_SEQUENCE) {
5404
0
                HGOTO_DONE(1);
5405
0
            }
5406
            /* Arbitrarily sort VL datatypes in memory before disk */
5407
21.8k
            if (dt1->shared->u.vlen.loc == H5T_LOC_MEMORY && dt2->shared->u.vlen.loc == H5T_LOC_DISK) {
5408
0
                HGOTO_DONE(-1);
5409
0
            }
5410
21.8k
            else if (dt1->shared->u.vlen.loc == H5T_LOC_DISK && dt2->shared->u.vlen.loc == H5T_LOC_MEMORY) {
5411
0
                HGOTO_DONE(1);
5412
0
            }
5413
21.8k
            else if (dt1->shared->u.vlen.loc == H5T_LOC_BADLOC && dt2->shared->u.vlen.loc != H5T_LOC_BADLOC) {
5414
0
                HGOTO_DONE(1);
5415
0
            }
5416
5417
            /* Don't allow VL types in different files to compare as equal */
5418
21.8k
            if (dt1->shared->u.vlen.file < dt2->shared->u.vlen.file)
5419
5.77k
                HGOTO_DONE(-1);
5420
16.1k
            if (dt1->shared->u.vlen.file > dt2->shared->u.vlen.file)
5421
8.07k
                HGOTO_DONE(1);
5422
8.03k
            break;
5423
5424
8.03k
        case H5T_OPAQUE:
5425
42
            if (dt1->shared->u.opaque.tag && dt2->shared->u.opaque.tag)
5426
42
                HGOTO_DONE(strcmp(dt1->shared->u.opaque.tag, dt2->shared->u.opaque.tag));
5427
0
            break;
5428
5429
0
        case H5T_ARRAY:
5430
0
            if (dt1->shared->u.array.ndims < dt2->shared->u.array.ndims)
5431
0
                HGOTO_DONE(-1);
5432
0
            if (dt1->shared->u.array.ndims > dt2->shared->u.array.ndims)
5433
0
                HGOTO_DONE(1);
5434
5435
0
            for (u = 0; u < dt1->shared->u.array.ndims; u++) {
5436
0
                if (dt1->shared->u.array.dim[u] < dt2->shared->u.array.dim[u])
5437
0
                    HGOTO_DONE(-1);
5438
0
                if (dt1->shared->u.array.dim[u] > dt2->shared->u.array.dim[u])
5439
0
                    HGOTO_DONE(1);
5440
0
            }
5441
5442
0
            tmp = H5T_cmp(dt1->shared->parent, dt2->shared->parent, superset);
5443
0
            if (tmp < 0)
5444
0
                HGOTO_DONE(-1);
5445
0
            if (tmp > 0)
5446
0
                HGOTO_DONE(1);
5447
0
            break;
5448
5449
696
        case H5T_COMPLEX:
5450
            /* Make sure the complex number datatypes are both in the same form */
5451
696
            tmp = (dt1->shared->u.cplx.form > dt2->shared->u.cplx.form) -
5452
696
                  (dt1->shared->u.cplx.form < dt2->shared->u.cplx.form);
5453
696
            if (tmp < 0)
5454
0
                HGOTO_DONE(-1);
5455
696
            if (tmp > 0)
5456
0
                HGOTO_DONE(1);
5457
5458
696
            tmp = H5T_cmp(dt1->shared->parent, dt2->shared->parent, superset);
5459
696
            if (tmp < 0)
5460
0
                HGOTO_DONE(-1);
5461
696
            if (tmp > 0)
5462
0
                HGOTO_DONE(1);
5463
5464
696
            break;
5465
5466
696
        case H5T_NO_CLASS:
5467
72.4k
        case H5T_INTEGER:
5468
92.2k
        case H5T_FLOAT:
5469
92.2k
        case H5T_TIME:
5470
247k
        case H5T_STRING:
5471
247k
        case H5T_BITFIELD:
5472
349k
        case H5T_REFERENCE:
5473
349k
        case H5T_NCLASSES:
5474
349k
        default:
5475
            /*
5476
             * Atomic datatypes...
5477
             */
5478
349k
            if (dt1->shared->u.atomic.order < dt2->shared->u.atomic.order)
5479
1.71k
                HGOTO_DONE(-1);
5480
348k
            if (dt1->shared->u.atomic.order > dt2->shared->u.atomic.order)
5481
1.59k
                HGOTO_DONE(1);
5482
5483
346k
            if (dt1->shared->u.atomic.prec < dt2->shared->u.atomic.prec)
5484
775
                HGOTO_DONE(-1);
5485
345k
            if (dt1->shared->u.atomic.prec > dt2->shared->u.atomic.prec)
5486
383
                HGOTO_DONE(1);
5487
5488
345k
            if (dt1->shared->u.atomic.offset < dt2->shared->u.atomic.offset)
5489
229
                HGOTO_DONE(-1);
5490
345k
            if (dt1->shared->u.atomic.offset > dt2->shared->u.atomic.offset)
5491
272
                HGOTO_DONE(1);
5492
5493
345k
            if (dt1->shared->u.atomic.lsb_pad < dt2->shared->u.atomic.lsb_pad)
5494
335
                HGOTO_DONE(-1);
5495
344k
            if (dt1->shared->u.atomic.lsb_pad > dt2->shared->u.atomic.lsb_pad)
5496
806
                HGOTO_DONE(1);
5497
5498
343k
            if (dt1->shared->u.atomic.msb_pad < dt2->shared->u.atomic.msb_pad)
5499
175
                HGOTO_DONE(-1);
5500
343k
            if (dt1->shared->u.atomic.msb_pad > dt2->shared->u.atomic.msb_pad)
5501
181
                HGOTO_DONE(1);
5502
5503
343k
            switch (dt1->shared->type) {
5504
68.2k
                case H5T_INTEGER:
5505
68.2k
                    if (dt1->shared->u.atomic.u.i.sign < dt2->shared->u.atomic.u.i.sign)
5506
8.46k
                        HGOTO_DONE(-1);
5507
59.7k
                    if (dt1->shared->u.atomic.u.i.sign > dt2->shared->u.atomic.u.i.sign)
5508
2.88k
                        HGOTO_DONE(1);
5509
56.9k
                    break;
5510
5511
56.9k
                case H5T_FLOAT:
5512
17.5k
                    if (dt1->shared->u.atomic.u.f.sign < dt2->shared->u.atomic.u.f.sign)
5513
31
                        HGOTO_DONE(-1);
5514
17.4k
                    if (dt1->shared->u.atomic.u.f.sign > dt2->shared->u.atomic.u.f.sign)
5515
73
                        HGOTO_DONE(1);
5516
5517
17.4k
                    if (dt1->shared->u.atomic.u.f.epos < dt2->shared->u.atomic.u.f.epos)
5518
621
                        HGOTO_DONE(-1);
5519
16.7k
                    if (dt1->shared->u.atomic.u.f.epos > dt2->shared->u.atomic.u.f.epos)
5520
236
                        HGOTO_DONE(1);
5521
5522
16.5k
                    if (dt1->shared->u.atomic.u.f.esize < dt2->shared->u.atomic.u.f.esize)
5523
688
                        HGOTO_DONE(-1);
5524
15.8k
                    if (dt1->shared->u.atomic.u.f.esize > dt2->shared->u.atomic.u.f.esize)
5525
167
                        HGOTO_DONE(1);
5526
5527
15.7k
                    if (dt1->shared->u.atomic.u.f.ebias < dt2->shared->u.atomic.u.f.ebias)
5528
564
                        HGOTO_DONE(-1);
5529
15.1k
                    if (dt1->shared->u.atomic.u.f.ebias > dt2->shared->u.atomic.u.f.ebias)
5530
486
                        HGOTO_DONE(1);
5531
5532
14.6k
                    if (dt1->shared->u.atomic.u.f.mpos < dt2->shared->u.atomic.u.f.mpos)
5533
74
                        HGOTO_DONE(-1);
5534
14.5k
                    if (dt1->shared->u.atomic.u.f.mpos > dt2->shared->u.atomic.u.f.mpos)
5535
26
                        HGOTO_DONE(1);
5536
5537
14.5k
                    if (dt1->shared->u.atomic.u.f.msize < dt2->shared->u.atomic.u.f.msize)
5538
130
                        HGOTO_DONE(-1);
5539
14.4k
                    if (dt1->shared->u.atomic.u.f.msize > dt2->shared->u.atomic.u.f.msize)
5540
159
                        HGOTO_DONE(1);
5541
5542
14.2k
                    if (dt1->shared->u.atomic.u.f.norm < dt2->shared->u.atomic.u.f.norm)
5543
67
                        HGOTO_DONE(-1);
5544
14.1k
                    if (dt1->shared->u.atomic.u.f.norm > dt2->shared->u.atomic.u.f.norm)
5545
111
                        HGOTO_DONE(1);
5546
5547
14.0k
                    if (dt1->shared->u.atomic.u.f.pad < dt2->shared->u.atomic.u.f.pad)
5548
22
                        HGOTO_DONE(-1);
5549
14.0k
                    if (dt1->shared->u.atomic.u.f.pad > dt2->shared->u.atomic.u.f.pad)
5550
39
                        HGOTO_DONE(1);
5551
5552
14.0k
                    break;
5553
5554
14.0k
                case H5T_TIME: /* order and precision are checked above */
5555
                    /*void */
5556
0
                    break;
5557
5558
155k
                case H5T_STRING:
5559
155k
                    if (dt1->shared->u.atomic.u.s.cset < dt2->shared->u.atomic.u.s.cset)
5560
679
                        HGOTO_DONE(-1);
5561
154k
                    if (dt1->shared->u.atomic.u.s.cset > dt2->shared->u.atomic.u.s.cset)
5562
270
                        HGOTO_DONE(1);
5563
5564
154k
                    if (dt1->shared->u.atomic.u.s.pad < dt2->shared->u.atomic.u.s.pad)
5565
12.1k
                        HGOTO_DONE(-1);
5566
142k
                    if (dt1->shared->u.atomic.u.s.pad > dt2->shared->u.atomic.u.s.pad)
5567
145
                        HGOTO_DONE(1);
5568
5569
142k
                    break;
5570
5571
142k
                case H5T_BITFIELD:
5572
                    /*void */
5573
5
                    break;
5574
5575
102k
                case H5T_REFERENCE:
5576
102k
                    if (dt1->shared->u.atomic.u.r.rtype < dt2->shared->u.atomic.u.r.rtype)
5577
0
                        HGOTO_DONE(-1);
5578
102k
                    if (dt1->shared->u.atomic.u.r.rtype > dt2->shared->u.atomic.u.r.rtype)
5579
0
                        HGOTO_DONE(1);
5580
102k
                    if (dt1->shared->u.atomic.u.r.loc < dt2->shared->u.atomic.u.r.loc)
5581
0
                        HGOTO_DONE(-1);
5582
102k
                    if (dt1->shared->u.atomic.u.r.loc > dt2->shared->u.atomic.u.r.loc)
5583
0
                        HGOTO_DONE(1);
5584
102k
                    if (dt1->shared->u.atomic.u.r.file < dt2->shared->u.atomic.u.r.file)
5585
33.8k
                        HGOTO_DONE(-1);
5586
68.3k
                    if (dt1->shared->u.atomic.u.r.file > dt2->shared->u.atomic.u.r.file)
5587
34.9k
                        HGOTO_DONE(1);
5588
33.3k
                    break;
5589
5590
33.3k
                case H5T_NO_CLASS:
5591
0
                case H5T_OPAQUE:
5592
0
                case H5T_COMPOUND:
5593
0
                case H5T_ENUM:
5594
0
                case H5T_VLEN:
5595
0
                case H5T_ARRAY:
5596
0
                case H5T_COMPLEX:
5597
0
                case H5T_NCLASSES:
5598
0
                default:
5599
0
                    assert("not implemented yet" && 0);
5600
0
                    break;
5601
343k
            }
5602
246k
            break;
5603
372k
    } /* end switch */
5604
5605
936k
done:
5606
936k
    if (NULL != idx1)
5607
0
        H5MM_xfree(idx1);
5608
936k
    if (NULL != idx2)
5609
0
        H5MM_xfree(idx2);
5610
5611
936k
    FUNC_LEAVE_NOAPI(ret_value)
5612
936k
} /* end H5T_cmp() */
5613
5614
/*-------------------------------------------------------------------------
5615
 * Function:    H5T__path_table_search
5616
 *
5617
 * Purpose:     Searches the global datatype conversion path table for a
5618
 *              conversion path between two datatypes.
5619
 *
5620
 *              Sets `idx` to be the index of the last table entry compared
5621
 *              (which will be the index of the matching conversion path on
5622
 *              success). If no matching path is found, the value for `idx`
5623
 *              will be the index into the path table where a new path
5624
 *              entry with source and destination datatypes matching src
5625
 *              and dst should be inserted. In this case, the caller should
5626
 *              be sure to increment the index value by 1 if the value of
5627
 *              the last comparison is > 0.
5628
 *
5629
 *              If `last_cmp` is non-NULL, the value of the last comparison
5630
 *              (-1, 0, or 1) is returned through it.
5631
 *
5632
 * Return:    Success:    true (conversion path found, index in *idx)
5633
 *            Failure:    false (no conversion path between types)
5634
 *
5635
 *-------------------------------------------------------------------------
5636
 */
5637
static bool
5638
H5T__path_table_search(const H5T_t *src, const H5T_t *dst, int *idx, int *last_cmp)
5639
94.3k
{
5640
94.3k
    int  lt, rt, md;        /* Left, middle, and right edges */
5641
94.3k
    int  cmp;               /* Comparison result  */
5642
94.3k
    bool ret_value = false; /* Return value */
5643
5644
94.3k
    FUNC_ENTER_PACKAGE_NOERR
5645
5646
    /* Sanity check */
5647
94.3k
    assert(0 != H5T_g.npaths);
5648
94.3k
    assert(src);
5649
94.3k
    assert(src->shared);
5650
94.3k
    assert(dst);
5651
94.3k
    assert(dst->shared);
5652
94.3k
    assert(idx);
5653
5654
    /* Find the conversion path in the table, using a binary search */
5655
    /* NOTE: Doesn't match against entry 0, which is the no-op path */
5656
94.3k
    lt = md = 1;
5657
94.3k
    rt      = H5T_g.npaths;
5658
94.3k
    cmp     = -1;
5659
5660
784k
    while (cmp && lt < rt) {
5661
689k
        md = (lt + rt) / 2;
5662
689k
        assert(H5T_g.path[md]);
5663
689k
        cmp = H5T_cmp(src, H5T_g.path[md]->src, false);
5664
689k
        if (0 == cmp)
5665
107k
            cmp = H5T_cmp(dst, H5T_g.path[md]->dst, false);
5666
689k
        if (cmp < 0)
5667
312k
            rt = md;
5668
377k
        else if (cmp > 0)
5669
291k
            lt = md + 1;
5670
86.6k
        else
5671
            /* Match found */
5672
86.6k
            ret_value = true;
5673
689k
    }
5674
5675
    /* Set middle index & comparison values */
5676
94.3k
    *idx = md;
5677
94.3k
    if (last_cmp)
5678
89.2k
        *last_cmp = cmp;
5679
5680
94.3k
    FUNC_LEAVE_NOAPI(ret_value)
5681
94.3k
} /* end H5T__path_table_search() */
5682
5683
/*-------------------------------------------------------------------------
5684
 * Function:    H5T_path_find
5685
 *
5686
 * Purpose:    Library-internal wrapper to find the path which converts
5687
 *             type SRC to type DST.
5688
 *
5689
 *             If SRC and DST are both null pointers then the special no-op
5690
 *             conversion path is used.
5691
 *
5692
 * Return:    Success:    Pointer to the path, valid until the path
5693
 *                        database is modified.
5694
 *
5695
 *            Failure:    NULL if the path does not exist and no
5696
 *                        function can be found to apply to the new path.
5697
 *
5698
 *-------------------------------------------------------------------------
5699
 */
5700
H5T_path_t *
5701
H5T_path_find(const H5T_t *src, const H5T_t *dst)
5702
125k
{
5703
125k
    H5T_conv_func_t conv_func;        /* Conversion function wrapper */
5704
125k
    H5T_path_t     *ret_value = NULL; /* Return value */
5705
5706
125k
    FUNC_ENTER_NOAPI(NULL)
5707
5708
    /* Sanity check */
5709
125k
    assert(src);
5710
125k
    assert(src->shared);
5711
125k
    assert(dst);
5712
125k
    assert(dst->shared);
5713
5714
    /* Set up conversion function wrapper */
5715
125k
    conv_func.is_app     = false;
5716
125k
    conv_func.u.lib_func = NULL;
5717
5718
    /* Call the internal routine, with additional parameters */
5719
125k
    if (NULL == (ret_value = H5T__path_find_real(src, dst, NULL, &conv_func)))
5720
346
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, NULL, "can't find datatype conversion path");
5721
5722
125k
done:
5723
125k
    FUNC_LEAVE_NOAPI(ret_value)
5724
125k
} /* end H5T_path_find() */
5725
5726
/*-------------------------------------------------------------------------
5727
 * Function:    H5T__path_find_real
5728
 *
5729
 * Purpose:    Finds the path which converts type SRC to type DST, creating
5730
 *             a new path if necessary.
5731
 *
5732
 *             If `conv->u.app_func`/`conv->u.lib_func` is non-NULL then it
5733
 *             is set as the hard conversion function for that path
5734
 *             regardless of whether the path previously existed. Changing
5735
 *             the conversion function of a path causes statistics to be
5736
 *             reset to zero after printing them. `name` is used only when
5737
 *             creating a new path and is just for debugging.
5738
 *
5739
 *             If no "force conversion" flags are set for either the source
5740
 *             or destination datatype and the two datatypes compare equal
5741
 *             to each other, then the special no-op conversion path is
5742
 *             used. This path is always stored as the first path in the
5743
 *             path table.
5744
 *
5745
 * Return:    Success:    Pointer to the path, valid until the path
5746
 *                        database is modified.
5747
 *
5748
 *            Failure:    NULL if the path does not exist and no
5749
 *                        function can be found to apply to the new path.
5750
 *
5751
 *-------------------------------------------------------------------------
5752
 */
5753
static H5T_path_t *
5754
H5T__path_find_real(const H5T_t *src, const H5T_t *dst, const char *name, H5T_conv_func_t *conv)
5755
127k
{
5756
127k
    H5T_conv_ctx_t tmp_ctx      = {0};   /* Temporary conversion context object */
5757
127k
    H5T_path_t    *matched_path = NULL;  /* Path existing in the table */
5758
127k
    H5T_path_t    *path         = NULL;  /* Pointer to current path */
5759
127k
    bool           noop_conv    = false; /* Whether this is a no-op conversion */
5760
127k
    bool           new_path     = false; /* Whether we're creating a new path */
5761
127k
    bool new_api_func = false; /* If the caller is an API function specifying a new conversion function */
5762
127k
    bool new_lib_func = false; /* If the caller is a private function specifying a new conversion function */
5763
127k
    int  old_npaths;           /* Previous number of paths in table */
5764
127k
    int  last_cmp         = 0; /* Value of last comparison during binary search */
5765
127k
    int  path_idx         = 0; /* Index into path table for path */
5766
127k
    H5T_path_t *ret_value = NULL; /* Return value */
5767
5768
127k
    FUNC_ENTER_PACKAGE
5769
5770
    /* Sanity check */
5771
127k
    assert(src);
5772
127k
    assert(src->shared);
5773
127k
    assert(dst);
5774
127k
    assert(dst->shared);
5775
5776
    /*
5777
     * Get the datatype conversion exception callback structure.
5778
     * Note that we have to first check if an API context has been
5779
     * pushed, since we could have arrived here during library
5780
     * initialization of the H5T package.
5781
     */
5782
127k
    if (H5CX_pushed() && (H5CX_get_dt_conv_cb(&tmp_ctx.u.init.cb_struct) < 0))
5783
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, NULL, "unable to get conversion exception callback");
5784
5785
    /* Make sure the path table is initialized */
5786
127k
    if ((0 == H5T_g.npaths) && (H5T__init_path_table() < 0))
5787
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to initialize type conversion path table");
5788
5789
    /* Find the conversion path. If no "force conversion" flags are
5790
     * set and the source and destination types are equal, then use
5791
     * the no-op conversion path. Otherwise, do a binary search over
5792
     * the remaining entries.
5793
     */
5794
127k
    noop_conv =
5795
127k
        src->shared->force_conv == false && dst->shared->force_conv == false && 0 == H5T_cmp(src, dst, true);
5796
127k
    if (noop_conv)
5797
38.1k
        matched_path = H5T_g.path[0];
5798
89.2k
    else {
5799
        /* Search the table of conversion paths */
5800
89.2k
        if (H5T__path_table_search(src, dst, &path_idx, &last_cmp))
5801
83.7k
            matched_path = H5T_g.path[path_idx];
5802
89.2k
    }
5803
5804
    /* Keep a record of the number of paths in the table, in case one of the
5805
     * initialization calls below (hard or soft) causes more entries to be
5806
     * added to the table - QAK, 1/26/02
5807
     */
5808
127k
    old_npaths = H5T_g.npaths;
5809
5810
    /* Set a few convenience variables */
5811
127k
    new_api_func = (matched_path && !noop_conv && conv->is_app && conv->u.app_func);
5812
127k
    new_lib_func = (matched_path && !noop_conv && !conv->is_app && conv->u.lib_func);
5813
5814
    /* If we didn't find the path, if the caller is an API function specifying
5815
     * a new hard conversion function, or if the caller is a private function
5816
     * specifying a new hard conversion and the path is a soft conversion, then
5817
     * create a new path and add the new function to the path.
5818
     */
5819
127k
    new_path = !matched_path || new_api_func || (new_lib_func && !matched_path->is_hard);
5820
5821
127k
    if (new_path) {
5822
5.49k
        if (NULL == (path = H5FL_CALLOC(H5T_path_t)))
5823
0
            HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for type conversion path");
5824
5.49k
        if (name && *name) {
5825
1.09k
            strncpy(path->name, name, (size_t)H5T_NAMELEN - 1);
5826
1.09k
            path->name[H5T_NAMELEN - 1] = '\0';
5827
1.09k
        } /* end if */
5828
4.40k
        else
5829
4.40k
            snprintf(path->name, sizeof(path->name), "NONAME");
5830
5.49k
        if (NULL == (path->src = H5T_copy(src, H5T_COPY_ALL)))
5831
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy datatype for conversion path");
5832
5.49k
        if (NULL == (path->dst = H5T_copy(dst, H5T_COPY_ALL)))
5833
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy datatype for conversion path");
5834
5.49k
    } /* end if */
5835
121k
    else
5836
121k
        path = matched_path;
5837
5838
    /* Initialize the path if it's a new path */
5839
127k
    if (new_path && H5T__path_find_init_new_path(path, src, dst, conv, &tmp_ctx) < 0)
5840
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to initialize new conversion path");
5841
5842
    /* Fail if the path still doesn't have a conversion function at this point */
5843
127k
    if (!path->conv.u.app_func)
5844
346
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no appropriate function for conversion path");
5845
5846
    /* Check if paths were inserted into the table through a recursive call
5847
     * and re-compute the correct location for this path if so. - QAK, 1/26/02
5848
     */
5849
127k
    if (old_npaths != H5T_g.npaths)
5850
0
        if (H5T__path_table_search(src, dst, &path_idx, &last_cmp))
5851
0
            matched_path = H5T_g.path[path_idx];
5852
5853
    /* Replace an existing table entry or add a new entry */
5854
127k
    if (matched_path && new_path) {
5855
0
        assert(matched_path == H5T_g.path[path_idx]);
5856
5857
0
        tmp_ctx.u.free.src_type_id = H5I_INVALID_HID;
5858
0
        tmp_ctx.u.free.dst_type_id = H5I_INVALID_HID;
5859
0
        if (H5T__path_free(matched_path, &tmp_ctx) < 0)
5860
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, NULL, "unable to free datatype conversion path");
5861
5862
0
        H5T_g.path[path_idx] = path;
5863
0
    }
5864
127k
    else if (new_path) {
5865
        /* Make space in the table for the new path if necessary */
5866
5.15k
        if ((size_t)H5T_g.npaths >= H5T_g.apaths) {
5867
10
            size_t       na = MAX(H5T_DEF_CONV_TABLE_SLOTS, 2 * H5T_g.apaths);
5868
10
            H5T_path_t **x;
5869
5870
10
            if (NULL == (x = H5MM_realloc(H5T_g.path, na * sizeof(H5T_path_t *))))
5871
0
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
5872
10
            H5T_g.apaths = na;
5873
10
            H5T_g.path   = x;
5874
10
        }
5875
5876
        /* Adjust final location in table for new path if the last comparison
5877
         * of paths during binary search was > 0, then shift down all path
5878
         * entries in the table starting at that location to make room for
5879
         * the new path
5880
         */
5881
5.15k
        assert(last_cmp != 0);
5882
5.15k
        if (last_cmp > 0)
5883
3.29k
            path_idx++;
5884
5.15k
        memmove(H5T_g.path + path_idx + 1, H5T_g.path + path_idx,
5885
5.15k
                (size_t)(H5T_g.npaths - path_idx) * sizeof(H5T_path_t *));
5886
5887
5.15k
        H5T_g.npaths++;
5888
5.15k
        H5T_g.path[path_idx] = path;
5889
5.15k
    }
5890
5891
127k
    ret_value = path;
5892
5893
127k
done:
5894
127k
    if (!ret_value && path && new_path) {
5895
346
        if (path->src && (H5T_close_real(path->src) < 0))
5896
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close datatype");
5897
346
        if (path->dst && (H5T_close_real(path->dst) < 0))
5898
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close datatype");
5899
346
        path = H5FL_FREE(H5T_path_t, path);
5900
346
    }
5901
5902
127k
    FUNC_LEAVE_NOAPI(ret_value)
5903
127k
} /* end H5T__path_find_real() */
5904
5905
/*-------------------------------------------------------------------------
5906
 * Function:  H5T__init_path_table
5907
 *
5908
 * Purpose:   Helper function to allocate and initialize the table holding
5909
 *            pointers to datatype conversion paths. Sets the no-op
5910
 *            conversion path as the first entry in the table.
5911
 *
5912
 * Return:    Non-negative on success/Negative on failure
5913
 *
5914
 *-------------------------------------------------------------------------
5915
 */
5916
static herr_t
5917
H5T__init_path_table(void)
5918
6
{
5919
6
    herr_t ret_value = SUCCEED;
5920
5921
6
    FUNC_ENTER_PACKAGE
5922
5923
    /* Sanity check */
5924
6
    if (0 != H5T_g.npaths)
5925
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_ALREADYINIT, FAIL,
5926
6
                    "datatype conversion path table is already initialized");
5927
5928
6
    if (NULL == (H5T_g.path = H5MM_calloc(H5T_DEF_CONV_TABLE_SLOTS * sizeof(H5T_path_t *))))
5929
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL,
5930
6
                    "memory allocation failed for type conversion path table");
5931
6
    H5T_g.apaths = H5T_DEF_CONV_TABLE_SLOTS;
5932
5933
    /*
5934
     * Allocate a path for the no-op conversion function
5935
     * and set it as the first entry in the table
5936
     */
5937
6
    if (NULL == (H5T_g.path[0] = H5FL_CALLOC(H5T_path_t)))
5938
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "memory allocation failed for no-op conversion path");
5939
5940
    /* Initialize the no-op path */
5941
6
    snprintf(H5T_g.path[0]->name, sizeof(H5T_g.path[0]->name), "no-op");
5942
6
    H5T_g.path[0]->conv.is_app     = false;
5943
6
    H5T_g.path[0]->conv.u.lib_func = H5T__conv_noop;
5944
6
    H5T_g.path[0]->cdata.command   = H5T_CONV_INIT;
5945
5946
6
    if (H5T__conv_noop(NULL, NULL, &(H5T_g.path[0]->cdata), NULL, 0, 0, 0, NULL, NULL) < 0) {
5947
#ifdef H5T_DEBUG
5948
        if (H5DEBUG(T))
5949
            fprintf(H5DEBUG(T), "H5T: unable to initialize no-op conversion function (ignored)\n");
5950
#endif
5951
        /* Ignore any errors from the conversion function */
5952
0
        if (H5E_clear_stack() < 0)
5953
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to clear current error stack");
5954
0
    } /* end if */
5955
5956
6
    H5T_g.path[0]->is_noop = true;
5957
5958
    /* Set # of initial paths in the table */
5959
6
    H5T_g.npaths = 1;
5960
5961
6
done:
5962
6
    if (ret_value < 0) {
5963
0
        if (H5T_g.path)
5964
0
            H5FL_FREE(H5T_path_t, H5T_g.path[0]);
5965
0
        H5MM_free(H5T_g.path);
5966
0
    }
5967
5968
6
    FUNC_LEAVE_NOAPI(ret_value)
5969
6
} /* end H5T__init_path_table() */
5970
5971
/*-------------------------------------------------------------------------
5972
 * Function:  H5T__path_find_init_new_path
5973
 *
5974
 * Purpose:   Helper function to initialize a new conversion path that's
5975
 *            being added to the path conversion table.
5976
 *
5977
 * Return:    Non-negative on success/Negative on failure
5978
 *
5979
 *-------------------------------------------------------------------------
5980
 */
5981
static herr_t
5982
H5T__path_find_init_new_path(H5T_path_t *path, const H5T_t *src, const H5T_t *dst, H5T_conv_func_t *conv,
5983
                             H5T_conv_ctx_t *conv_ctx)
5984
5.49k
{
5985
5.49k
    H5T_t *tmp_stype = NULL;            /* temporary source datatype */
5986
5.49k
    H5T_t *tmp_dtype = NULL;            /* temporary destination datatype */
5987
5.49k
    hid_t  src_id    = H5I_INVALID_HID; /* source datatype identifier */
5988
5.49k
    hid_t  dst_id    = H5I_INVALID_HID; /* destination datatype identifier */
5989
5.49k
    herr_t status    = SUCCEED;
5990
5.49k
    herr_t ret_value = SUCCEED;
5991
5992
5.49k
    FUNC_ENTER_PACKAGE
5993
5994
5.49k
    assert(path);
5995
5.49k
    assert(conv);
5996
5.49k
    assert(conv_ctx);
5997
5.49k
    assert(NULL == path->conv.u.app_func);
5998
5999
    /* If a hard conversion function was specified, initialize that
6000
     * function and finish setting up the new path.
6001
     */
6002
5.49k
    if (conv->u.app_func) {
6003
1.09k
        path->cdata.command = H5T_CONV_INIT;
6004
1.09k
        if (conv->is_app) {
6005
            /* Copy the conversion path's source and destination datatypes and
6006
             * register an ID for them so we can pass these to the application
6007
             * conversion function
6008
             */
6009
0
            if (path->src && (NULL == (tmp_stype = H5T_copy(path->src, H5T_COPY_ALL))))
6010
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy source datatype");
6011
0
            if (path->dst && (NULL == (tmp_dtype = H5T_copy(path->dst, H5T_COPY_ALL))))
6012
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy destination datatype");
6013
6014
0
            if (tmp_stype && ((src_id = H5I_register(H5I_DATATYPE, tmp_stype, false)) < 0))
6015
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
6016
0
                            "unable to register ID for source datatype");
6017
0
            if (tmp_dtype && ((dst_id = H5I_register(H5I_DATATYPE, tmp_dtype, false)) < 0))
6018
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
6019
0
                            "unable to register ID for destination datatype");
6020
6021
            /* Prepare & restore library for user callback */
6022
0
            H5_BEFORE_USER_CB(FAIL)
6023
0
                {
6024
0
                    status = (conv->u.app_func)(src_id, dst_id, &(path->cdata), 0, 0, 0, NULL, NULL,
6025
0
                                                H5CX_get_dxpl());
6026
0
                }
6027
0
            H5_AFTER_USER_CB(FAIL)
6028
0
        }
6029
1.09k
        else
6030
1.09k
            status = (conv->u.lib_func)(path->src, path->dst, &(path->cdata), conv_ctx, 0, 0, 0, NULL, NULL);
6031
6032
1.09k
        if (status < 0)
6033
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion function");
6034
6035
1.09k
        if (src_id >= 0) {
6036
0
            if (H5I_dec_ref(src_id) < 0)
6037
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
6038
0
            src_id    = H5I_INVALID_HID;
6039
0
            tmp_stype = NULL;
6040
0
        }
6041
1.09k
        if (dst_id >= 0) {
6042
0
            if (H5I_dec_ref(dst_id) < 0)
6043
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
6044
0
            dst_id    = H5I_INVALID_HID;
6045
0
            tmp_dtype = NULL;
6046
0
        }
6047
6048
1.09k
        path->conv    = *conv;
6049
1.09k
        path->is_hard = true;
6050
1.09k
    }
6051
6052
    /*
6053
     * Otherwise, scan the soft list for an applicable function
6054
     * and add it to the path.
6055
     */
6056
5.49k
    assert(path->conv.u.app_func || (src && dst));
6057
63.1k
    for (int i = H5T_g.nsoft - 1; i >= 0 && !path->conv.u.app_func; --i) {
6058
57.6k
        bool path_init_error = false;
6059
6060
57.6k
        if (src->shared->type != H5T_g.soft[i].src || dst->shared->type != H5T_g.soft[i].dst)
6061
46.8k
            continue;
6062
6063
10.8k
        path->cdata.command = H5T_CONV_INIT;
6064
10.8k
        if (H5T_g.soft[i].conv.is_app) {
6065
            /* Copy the conversion path's source and destination datatypes and
6066
             * register an ID for them so we can pass these to the application
6067
             * conversion function
6068
             */
6069
0
            if (NULL == (tmp_stype = H5T_copy(path->src, H5T_COPY_ALL)))
6070
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy source datatype");
6071
0
            if (NULL == (tmp_dtype = H5T_copy(path->dst, H5T_COPY_ALL)))
6072
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy destination datatype");
6073
6074
0
            if ((src_id = H5I_register(H5I_DATATYPE, tmp_stype, false)) < 0)
6075
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
6076
0
                            "unable to register ID for source datatype");
6077
0
            if ((dst_id = H5I_register(H5I_DATATYPE, tmp_dtype, false)) < 0)
6078
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
6079
0
                            "unable to register ID for destination datatype");
6080
6081
            /* Prepare & restore library for user callback */
6082
0
            H5_BEFORE_USER_CB(FAIL)
6083
0
                {
6084
0
                    status = (H5T_g.soft[i].conv.u.app_func)(src_id, dst_id, &(path->cdata), 0, 0, 0, NULL,
6085
0
                                                             NULL, H5CX_get_dxpl());
6086
0
                }
6087
0
            H5_AFTER_USER_CB(FAIL)
6088
0
        }
6089
10.8k
        else
6090
10.8k
            status = (H5T_g.soft[i].conv.u.lib_func)(path->src, path->dst, &(path->cdata), conv_ctx, 0, 0, 0,
6091
10.8k
                                                     NULL, NULL);
6092
6093
10.8k
        if (status < 0) {
6094
6.77k
            memset(&(path->cdata), 0, sizeof(H5T_cdata_t));
6095
            /* ignore the error */
6096
6.77k
            if (H5E_clear_stack() < 0)
6097
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to clear current error stack");
6098
6.77k
            path_init_error = true;
6099
6.77k
        }
6100
6101
        /* Finish operation, if no error */
6102
10.8k
        if (!path_init_error) {
6103
4.05k
            strncpy(path->name, H5T_g.soft[i].name, (size_t)H5T_NAMELEN);
6104
4.05k
            path->name[H5T_NAMELEN - 1] = '\0';
6105
4.05k
            path->conv                  = H5T_g.soft[i].conv;
6106
4.05k
            path->is_hard               = false;
6107
4.05k
        }
6108
6109
10.8k
        if (src_id >= 0) {
6110
0
            if (H5I_dec_ref(src_id) < 0)
6111
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
6112
0
            src_id    = H5I_INVALID_HID;
6113
0
            tmp_stype = NULL;
6114
0
        }
6115
10.8k
        if (dst_id >= 0) {
6116
0
            if (H5I_dec_ref(dst_id) < 0)
6117
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
6118
0
            dst_id    = H5I_INVALID_HID;
6119
0
            tmp_dtype = NULL;
6120
0
        }
6121
10.8k
    }
6122
6123
5.49k
done:
6124
5.49k
    if (src_id >= 0) {
6125
0
        if (H5I_dec_ref(src_id) < 0)
6126
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
6127
0
    }
6128
5.49k
    else if (tmp_stype) {
6129
0
        if (H5T_close(tmp_stype) < 0)
6130
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "can't close temporary datatype");
6131
0
    }
6132
5.49k
    if (dst_id >= 0) {
6133
0
        if (H5I_dec_ref(dst_id) < 0)
6134
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement reference on temporary ID");
6135
0
    }
6136
5.49k
    else if (tmp_dtype) {
6137
0
        if (H5T_close(tmp_dtype) < 0)
6138
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "can't close temporary datatype");
6139
0
    }
6140
6141
5.49k
    FUNC_LEAVE_NOAPI(ret_value)
6142
5.49k
}
6143
6144
/*-------------------------------------------------------------------------
6145
 * Function:  H5T__path_free
6146
 *
6147
 * Purpose:   Helper function to free a datatype conversion path. This
6148
 *            function assumes that the 'free' member of the passed in
6149
 *            'conv_ctx' has been initialized.
6150
 *
6151
 * Return:    Non-negative on success/Negative on failure
6152
 *
6153
 *-------------------------------------------------------------------------
6154
 */
6155
static herr_t
6156
H5T__path_free(H5T_path_t *path, H5T_conv_ctx_t *conv_ctx)
6157
5.15k
{
6158
5.15k
    herr_t status    = SUCCEED;
6159
5.15k
    int    nprint    = 0;
6160
5.15k
    herr_t ret_value = SUCCEED;
6161
6162
5.15k
    FUNC_ENTER_PACKAGE
6163
6164
5.15k
    assert(path);
6165
5.15k
    assert(conv_ctx);
6166
6167
5.15k
    if (path->conv.u.app_func) {
6168
5.15k
        H5T__print_path_stats(path, &nprint);
6169
6170
5.15k
        path->cdata.command = H5T_CONV_FREE;
6171
6172
5.15k
        if (path->conv.is_app) {
6173
            /* Prepare & restore library for user callback */
6174
0
            H5_BEFORE_USER_CB_NOERR(FAIL)
6175
0
                {
6176
0
                    status =
6177
0
                        (path->conv.u.app_func)(conv_ctx->u.free.src_type_id, conv_ctx->u.free.dst_type_id,
6178
0
                                                &(path->cdata), 0, 0, 0, NULL, NULL, H5CX_get_dxpl());
6179
0
                }
6180
0
            H5_AFTER_USER_CB_NOERR(FAIL)
6181
0
        }
6182
5.15k
        else
6183
5.15k
            status =
6184
5.15k
                (path->conv.u.lib_func)(path->src, path->dst, &(path->cdata), conv_ctx, 0, 0, 0, NULL, NULL);
6185
6186
5.15k
        if (status < 0) {
6187
            /* Ignore any error from shutting down the path */
6188
0
            if (H5E_clear_stack() < 0)
6189
                /* Push error, but keep going */
6190
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to clear current error stack");
6191
6192
#ifdef H5T_DEBUG
6193
            if (H5DEBUG(T)) {
6194
                fprintf(H5DEBUG(T), "H5T: conversion function 0x%016zx free failed for %s (ignored)\n",
6195
                        path->conv.is_app ? (size_t)path->conv.u.app_func : (size_t)path->conv.u.lib_func,
6196
                        path->name);
6197
            }
6198
#endif
6199
0
        }
6200
5.15k
    }
6201
6202
5.15k
    if (path->src && (H5T_close_real(path->src) < 0))
6203
        /* Push error, but keep going */
6204
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close source datatype");
6205
5.15k
    if (path->dst && (H5T_close_real(path->dst) < 0))
6206
        /* Push error, but keep going */
6207
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close destination datatype");
6208
6209
5.15k
    path = H5FL_FREE(H5T_path_t, path);
6210
6211
5.15k
    FUNC_LEAVE_NOAPI(ret_value)
6212
5.15k
}
6213
6214
/*-------------------------------------------------------------------------
6215
 * Function:  H5T_path_match
6216
 *
6217
 * Purpose:   Helper function to determine whether a datatype conversion
6218
 *            path object matches against a given set of criteria.
6219
 *
6220
 * Return:    true/false (can't fail)
6221
 *
6222
 *-------------------------------------------------------------------------
6223
 */
6224
static bool
6225
H5T_path_match(H5T_path_t *path, H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst,
6226
               H5VL_object_t *owned_vol_obj, H5T_conv_t func)
6227
1.34M
{
6228
1.34M
    bool ret_value = true;
6229
6230
1.34M
    FUNC_ENTER_NOAPI_NOINIT_NOERR
6231
6232
1.34M
    assert(path);
6233
6234
1.34M
    if (
6235
        /* Check that the specified conversion function persistence matches */
6236
1.34M
        ((H5T_PERS_SOFT == pers && path->is_hard) || (H5T_PERS_HARD == pers && !path->is_hard)) ||
6237
6238
        /* Check that the specified conversion path name matches */
6239
692k
        (name && *name && strcmp(name, path->name) != 0) ||
6240
6241
        /*
6242
         * Check that the specified source and destination datatypes match
6243
         * the source and destination datatypes in the conversion path
6244
         */
6245
692k
        (src && H5T_cmp(src, path->src, false)) || (dst && H5T_cmp(dst, path->dst, false)) ||
6246
6247
        /*
6248
         * Check that the specified VOL object pointer matches the `owned_vol_obj`
6249
         * field for either the source datatype or destination datatype in the
6250
         * conversion path
6251
         */
6252
692k
        (owned_vol_obj && (H5T_path_match_find_type_with_volobj(path->src, owned_vol_obj) == false) &&
6253
689k
         (H5T_path_match_find_type_with_volobj(path->dst, owned_vol_obj) == false)) ||
6254
6255
        /* Check that the specified conversion function matches */
6256
3.28k
        (func && func != path->conv.u.app_func))
6257
1.33M
        ret_value = false;
6258
6259
1.34M
    FUNC_LEAVE_NOAPI(ret_value)
6260
1.34M
} /* H5T_path_match() */
6261
6262
/*-------------------------------------------------------------------------
6263
 * Function:  H5T_path_match_find_type_with_volobj
6264
 *
6265
 * Purpose:   Helper function to determine whether a datatype is or
6266
 *            contains a datatype that has a VOL object pointer matching
6267
 *            the given VOL object pointer.
6268
 *
6269
 * Return:    true/false (can't fail)
6270
 *
6271
 *-------------------------------------------------------------------------
6272
 */
6273
static bool
6274
H5T_path_match_find_type_with_volobj(const H5T_t *datatype, const H5VL_object_t *owned_vol_obj)
6275
1.70M
{
6276
1.70M
    bool ret_value = false;
6277
6278
1.70M
    FUNC_ENTER_NOAPI_NOINIT_NOERR
6279
6280
1.70M
    assert(datatype);
6281
1.70M
    assert(owned_vol_obj);
6282
6283
1.70M
    ret_value = (datatype->shared->owned_vol_obj == owned_vol_obj);
6284
1.70M
    if (!ret_value) {
6285
1.69M
        switch (datatype->shared->type) {
6286
0
            case H5T_COMPOUND:
6287
0
                for (unsigned i = 0; i < datatype->shared->u.compnd.nmembs; i++) {
6288
0
                    if (ret_value)
6289
0
                        break;
6290
0
                    ret_value = H5T_path_match_find_type_with_volobj(datatype->shared->u.compnd.memb[i].type,
6291
0
                                                                     owned_vol_obj);
6292
0
                }
6293
0
                break;
6294
6295
321k
            case H5T_VLEN:
6296
                /* Should be an error if no parent, but simplify logic for a true/false return value */
6297
321k
                if (datatype->shared->parent)
6298
321k
                    ret_value = H5T_path_match_find_type_with_volobj(datatype->shared->parent, owned_vol_obj);
6299
321k
                break;
6300
6301
0
            case H5T_ARRAY:
6302
                /* Should be an error if no parent, but simplify logic for a true/false return value */
6303
0
                if (datatype->shared->parent)
6304
0
                    ret_value = H5T_path_match_find_type_with_volobj(datatype->shared->parent, owned_vol_obj);
6305
0
                break;
6306
6307
244k
            case H5T_INTEGER:
6308
581k
            case H5T_FLOAT:
6309
581k
            case H5T_TIME:
6310
947k
            case H5T_STRING:
6311
947k
            case H5T_BITFIELD:
6312
947k
            case H5T_OPAQUE:
6313
1.37M
            case H5T_REFERENCE: /* Should have been determined by above check */
6314
1.37M
            case H5T_ENUM:
6315
1.37M
            case H5T_COMPLEX:
6316
1.37M
            case H5T_NO_CLASS: /* Error value, but simplify logic for a true/false return value */
6317
1.37M
            case H5T_NCLASSES: /* Error value, but simplify logic for a true/false return value */
6318
1.37M
            default:
6319
1.37M
                ret_value = false;
6320
1.37M
                break;
6321
1.69M
        }
6322
1.69M
    }
6323
6324
1.70M
    FUNC_LEAVE_NOAPI(ret_value)
6325
1.70M
}
6326
6327
/*-------------------------------------------------------------------------
6328
 * Function:  H5T_path_noop
6329
 *
6330
 * Purpose:   Is the path the special no-op path? The no-op function can be
6331
 *            set by the application and there might be more than one no-op
6332
 *            path in a multi-threaded application if one thread is using
6333
 *            the no-op path when some other thread changes its definition.
6334
 *
6335
 * Return:    true/false (can't fail)
6336
 *
6337
 *-------------------------------------------------------------------------
6338
 */
6339
bool
6340
H5T_path_noop(const H5T_path_t *p)
6341
128k
{
6342
128k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
6343
6344
128k
    assert(p);
6345
6346
128k
    FUNC_LEAVE_NOAPI(p->is_noop || (p->is_hard && 0 == H5T_cmp(p->src, p->dst, false)))
6347
128k
} /* end H5T_path_noop() */
6348
6349
/*-------------------------------------------------------------------------
6350
 * Function:    H5T_noop_conv
6351
 *
6352
 * Purpose:     Check if a conversion between two dataypes will be a no-op
6353
 *
6354
 * Return:      true / false (can't fail)
6355
 *
6356
 *-------------------------------------------------------------------------
6357
 */
6358
bool
6359
H5T_noop_conv(const H5T_t *src, const H5T_t *dst)
6360
5.16k
{
6361
5.16k
    bool ret_value = false; /* Return value */
6362
6363
5.16k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
6364
6365
    /* Sanity check */
6366
5.16k
    assert(src);
6367
5.16k
    assert(src->shared);
6368
5.16k
    assert(dst);
6369
5.16k
    assert(dst->shared);
6370
6371
    /* Check the conversion path.  If source and destination types are equal
6372
     * then its a no-op conversion, as long as neither type has a "force conversion"
6373
     * flag.  Otherwise search over the conversion table entries.
6374
     */
6375
5.16k
    if (src->shared->force_conv == false && dst->shared->force_conv == false &&
6376
21
        0 == H5T_cmp(src, dst, true)) {
6377
21
        ret_value = true;
6378
21
    } /* end if */
6379
5.14k
    else {
6380
5.14k
        int idx = 0; /* Matching entry */
6381
6382
        /* Search the table of conversion paths */
6383
5.14k
        if (H5T__path_table_search(src, dst, &idx, NULL))
6384
2.97k
            ret_value = H5T_path_noop(H5T_g.path[idx]);
6385
5.14k
    } /* end else */
6386
6387
5.16k
    FUNC_LEAVE_NOAPI(ret_value)
6388
5.16k
} /* end H5T_noop_conv() */
6389
6390
/*-------------------------------------------------------------------------
6391
 * Function:  H5T_path_compound_subset
6392
 *
6393
 * Purpose:   Checks if the library's compound conversion function
6394
 *            is in use. Tells whether whether the source members are
6395
 *            a subset of destination, and the order is the same, and
6396
 *            no conversion is needed.  For example:
6397
 *                  struct source {            struct destination {
6398
 *                      TYPE1 A;      -->          TYPE1 A;
6399
 *                      TYPE2 B;      -->          TYPE2 B;
6400
 *                      TYPE3 C;      -->          TYPE3 C;
6401
 *                  };                             TYPE4 D;
6402
 *                                                 TYPE5 E;
6403
 *                                             };
6404
 *
6405
 * Return:    A pointer to the subset info struct in p, or NULL if the
6406
 *            library's compound conversion function is not in use.
6407
 *            Points directly into the H5T_path_t structure.
6408
 *
6409
 *-------------------------------------------------------------------------
6410
 */
6411
H5T_subset_info_t *
6412
H5T_path_compound_subset(const H5T_path_t *p)
6413
11.1k
{
6414
11.1k
    H5T_subset_info_t *ret_value = NULL;
6415
6416
11.1k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
6417
6418
11.1k
    assert(p);
6419
6420
    /* Only retrieve private info if the library compound conversion
6421
     * function is in use */
6422
11.1k
    if (!p->conv.is_app && (p->conv.u.lib_func == H5T__conv_struct))
6423
0
        ret_value = H5T__conv_struct_subset(&(p->cdata));
6424
6425
11.1k
    FUNC_LEAVE_NOAPI(ret_value)
6426
11.1k
} /* end H5T_path_compound_subset */
6427
6428
/*-------------------------------------------------------------------------
6429
 * Function:  H5T_path_bkg
6430
 *
6431
 * Purpose:   Get the "background" flag for the conversion path.
6432
 *
6433
 * Return:    Background flag (can't fail)
6434
 *
6435
 *-------------------------------------------------------------------------
6436
 */
6437
H5T_bkg_t
6438
H5T_path_bkg(const H5T_path_t *p)
6439
87.4k
{
6440
87.4k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
6441
6442
87.4k
    assert(p);
6443
6444
87.4k
    FUNC_LEAVE_NOAPI(p->cdata.need_bkg)
6445
87.4k
} /* end H5T_path_bkg() */
6446
6447
/*-------------------------------------------------------------------------
6448
 * Function:  H5T__compiler_conv
6449
 *
6450
 * Purpose:   Private function for H5Tcompiler_conv.  Finds out whether the
6451
 *            library's conversion function from type SRC to type DST
6452
 *            is a hard conversion.
6453
 *
6454
 * Return:    true:           hard conversion.
6455
 *            false:          soft conversion.
6456
 *            FAIL:           function failed.
6457
 *
6458
 *-------------------------------------------------------------------------
6459
 */
6460
static htri_t
6461
H5T__compiler_conv(H5T_t *src, H5T_t *dst)
6462
0
{
6463
0
    H5T_path_t *path;
6464
0
    htri_t      ret_value = FAIL; /* Return value */
6465
6466
0
    FUNC_ENTER_PACKAGE
6467
6468
    /* Find it */
6469
0
    if (NULL == (path = H5T_path_find(src, dst)))
6470
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, "conversion function not found");
6471
6472
0
    ret_value = (htri_t)path->is_hard;
6473
6474
0
done:
6475
0
    FUNC_LEAVE_NOAPI(ret_value)
6476
0
} /* end H5T__compiler_conv() */
6477
6478
/*-------------------------------------------------------------------------
6479
 * Function:  H5T_convert
6480
 *
6481
 * Purpose:   Call a conversion function to convert from source to
6482
 *            destination data type and accumulate timing statistics.
6483
 *
6484
 * Return:    Success:    non-negative
6485
 *
6486
 *            Failure:    negative
6487
 *
6488
 *-------------------------------------------------------------------------
6489
 */
6490
herr_t
6491
H5T_convert(H5T_path_t *tpath, const H5T_t *src_type, const H5T_t *dst_type, size_t nelmts, size_t buf_stride,
6492
            size_t bkg_stride, void *buf, void *bkg)
6493
91.0k
{
6494
91.0k
    H5T_conv_ctx_t conv_ctx = {0};
6495
#ifdef H5T_DEBUG
6496
    H5_timer_t timer = {0}; /* Timer for conversion */
6497
#endif
6498
91.0k
    hid_t  src_type_id = H5I_INVALID_HID;
6499
91.0k
    hid_t  dst_type_id = H5I_INVALID_HID;
6500
91.0k
    herr_t ret_value   = SUCCEED;
6501
6502
91.0k
    FUNC_ENTER_NOAPI(FAIL)
6503
6504
#ifdef H5T_DEBUG
6505
    if (H5DEBUG(T)) {
6506
        /* Initialize and start timer */
6507
        H5_timer_init(&timer);
6508
        H5_timer_start(&timer);
6509
    } /* end if */
6510
#endif
6511
6512
    /* Get the datatype conversion exception callback structure from the API context */
6513
91.0k
    if (H5CX_get_dt_conv_cb(&conv_ctx.u.conv.cb_struct) < 0)
6514
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get conversion exception callback");
6515
6516
    /*
6517
     * If this is an application conversion function or an exception callback
6518
     * function was supplied, register IDs for the datatypes so we can pass
6519
     * those as appropriate. Also grab the DXPL if necessary so we can pass
6520
     * that to the app conversion function.
6521
     */
6522
91.0k
    if (tpath->conv.is_app || conv_ctx.u.conv.cb_struct.func) {
6523
0
        if ((src_type_id = H5I_register(H5I_DATATYPE, src_type, false)) < 0)
6524
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register ID for source datatype");
6525
0
        if ((dst_type_id = H5I_register(H5I_DATATYPE, dst_type, false)) < 0)
6526
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
6527
0
                        "unable to register ID for destination datatype");
6528
6529
0
        if (tpath->conv.is_app)
6530
0
            conv_ctx.u.conv.dxpl_id = H5CX_get_dxpl();
6531
0
    }
6532
91.0k
    conv_ctx.u.conv.src_type_id = src_type_id;
6533
91.0k
    conv_ctx.u.conv.dst_type_id = dst_type_id;
6534
6535
91.0k
    if (H5T_convert_with_ctx(tpath, src_type, dst_type, &conv_ctx, nelmts, buf_stride, bkg_stride, buf, bkg) <
6536
91.0k
        0)
6537
1.74k
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "datatype conversion failed");
6538
6539
91.0k
done:
6540
    /* Remove IDs, but don't decrement their reference counts, as they
6541
     * could have been registered for datatypes that weren't copied
6542
     */
6543
91.0k
    if ((src_type_id >= 0) && (NULL == H5I_remove(src_type_id)))
6544
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't decrement temporary datatype ID");
6545
91.0k
    if ((dst_type_id >= 0) && (NULL == H5I_remove(dst_type_id)))
6546
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't decrement temporary datatype ID");
6547
6548
#ifdef H5T_DEBUG
6549
    if (H5DEBUG(T)) {
6550
        /* Stop timer */
6551
        H5_timer_stop(&timer);
6552
6553
        /* Record elapsed timer info */
6554
        H5_timer_get_times(timer, &tpath->stats.times);
6555
6556
        /* Increment # of calls and # of elements converted */
6557
        tpath->stats.ncalls++;
6558
        tpath->stats.nelmts += nelmts;
6559
    } /* end if */
6560
#endif
6561
6562
91.0k
    FUNC_LEAVE_NOAPI(ret_value)
6563
91.0k
} /* end H5T_convert() */
6564
6565
/*-------------------------------------------------------------------------
6566
 * Function:  H5T_convert_with_ctx
6567
 *
6568
 * Purpose:   Helper routine for H5T_convert that accepts a pointer to a
6569
 *            H5T_conv_ctx_t conversion context structure. Useful for
6570
 *            conversion routines involving container datatypes, such as
6571
 *            compounds, where the conversion context structure that was
6572
 *            setup during the initial H5T_convert call can be reused.
6573
 *            This avoids the expensive and unnecessary overhead of
6574
 *            recreating this structure and possibly re-registering IDs for
6575
 *            the source and destination datatypes for every single member
6576
 *            of the container datatype and every single element being
6577
 *            converted that consists of that container datatype.
6578
 *
6579
 * Return:    Non-negative on success/Negative on failure
6580
 *
6581
 *-------------------------------------------------------------------------
6582
 */
6583
herr_t
6584
H5T_convert_with_ctx(H5T_path_t *tpath, const H5T_t *src_type, const H5T_t *dst_type,
6585
                     const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride, size_t bkg_stride,
6586
                     void *buf, void *bkg)
6587
91.0k
{
6588
91.0k
    herr_t ret_value = SUCCEED;
6589
6590
91.0k
    FUNC_ENTER_NOAPI(FAIL)
6591
6592
    /* Call the appropriate conversion callback */
6593
91.0k
    tpath->cdata.command = H5T_CONV_CONV;
6594
91.0k
    if (tpath->conv.is_app) {
6595
        /* Prepare & restore library for user callback */
6596
0
        H5_BEFORE_USER_CB(FAIL)
6597
0
            {
6598
0
                ret_value = (tpath->conv.u.app_func)(
6599
0
                    conv_ctx->u.conv.src_type_id, conv_ctx->u.conv.dst_type_id, &(tpath->cdata), nelmts,
6600
0
                    buf_stride, bkg_stride, buf, bkg, conv_ctx->u.conv.dxpl_id);
6601
0
            }
6602
0
        H5_AFTER_USER_CB(FAIL)
6603
0
        if (ret_value < 0)
6604
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "datatype conversion failed");
6605
0
    } /* end if */
6606
91.0k
    else if ((tpath->conv.u.lib_func)(src_type, dst_type, &(tpath->cdata), conv_ctx, nelmts, buf_stride,
6607
91.0k
                                      bkg_stride, buf, bkg) < 0)
6608
1.74k
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "datatype conversion failed");
6609
6610
91.0k
done:
6611
91.0k
    FUNC_LEAVE_NOAPI(ret_value)
6612
91.0k
} /* end H5T_convert_with_ctx() */
6613
6614
/*-------------------------------------------------------------------------
6615
 * Function:  H5T_oloc
6616
 *
6617
 * Purpose:   Returns a pointer to the object location for a named datatype.
6618
 *
6619
 * Return:    Success:    Ptr directly into named datatype
6620
 *            Failure:    NULL
6621
 *
6622
 *-------------------------------------------------------------------------
6623
 */
6624
H5O_loc_t *
6625
H5T_oloc(H5T_t *dt)
6626
0
{
6627
0
    H5O_loc_t *ret_value = NULL;
6628
6629
0
    FUNC_ENTER_NOAPI(NULL)
6630
6631
0
    assert(dt);
6632
6633
0
    switch (dt->shared->state) {
6634
0
        case H5T_STATE_TRANSIENT:
6635
0
        case H5T_STATE_RDONLY:
6636
0
        case H5T_STATE_IMMUTABLE:
6637
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "not a named datatype");
6638
0
        case H5T_STATE_NAMED:
6639
0
        case H5T_STATE_OPEN:
6640
0
            assert(dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED);
6641
0
            ret_value = &dt->oloc;
6642
0
            break;
6643
0
        default:
6644
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, NULL, "invalid datatype state");
6645
0
    } /* end switch */
6646
6647
0
done:
6648
0
    FUNC_LEAVE_NOAPI(ret_value)
6649
0
} /* end H5T_oloc() */
6650
6651
/*-------------------------------------------------------------------------
6652
 * Function:  H5T_nameof
6653
 *
6654
 * Purpose:   Returns a pointer to the path for a named datatype.
6655
 *
6656
 * Return:    Success:    Ptr directly into named datatype
6657
 *            Failure:    NULL
6658
 *
6659
 *-------------------------------------------------------------------------
6660
 */
6661
H5G_name_t *
6662
H5T_nameof(H5T_t *dt)
6663
0
{
6664
0
    H5G_name_t *ret_value = NULL;
6665
6666
0
    FUNC_ENTER_NOAPI(NULL)
6667
6668
0
    assert(dt);
6669
6670
0
    switch (dt->shared->state) {
6671
0
        case H5T_STATE_TRANSIENT:
6672
0
        case H5T_STATE_RDONLY:
6673
0
        case H5T_STATE_IMMUTABLE:
6674
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "not a named datatype");
6675
0
        case H5T_STATE_NAMED:
6676
0
        case H5T_STATE_OPEN:
6677
0
            ret_value = &(dt->path);
6678
0
            break;
6679
0
        default:
6680
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, NULL, "invalid datatype state");
6681
0
    } /* end switch */
6682
6683
0
done:
6684
0
    FUNC_LEAVE_NOAPI(ret_value)
6685
0
} /* end H5T_nameof() */
6686
6687
/*-------------------------------------------------------------------------
6688
 * Function:    H5T_is_immutable
6689
 *
6690
 * Purpose:     Check if a datatype is immutable.
6691
 *
6692
 * Return:      true
6693
 *
6694
 *              false
6695
 *
6696
 *-------------------------------------------------------------------------
6697
 */
6698
htri_t
6699
H5T_is_immutable(const H5T_t *dt)
6700
0
{
6701
0
    htri_t ret_value = false;
6702
6703
0
    FUNC_ENTER_NOAPI(FAIL)
6704
6705
0
    assert(dt);
6706
6707
0
    if (dt->shared->state == H5T_STATE_IMMUTABLE)
6708
0
        ret_value = true;
6709
6710
0
done:
6711
0
    FUNC_LEAVE_NOAPI(ret_value)
6712
0
}
6713
6714
/*-------------------------------------------------------------------------
6715
 * Function:    H5T_is_named
6716
 *
6717
 * Purpose:     Check if a datatype is named/committed.
6718
 *
6719
 * Return:      true/false/FAIL
6720
 *
6721
 *-------------------------------------------------------------------------
6722
 */
6723
htri_t
6724
H5T_is_named(const H5T_t *dt)
6725
151k
{
6726
151k
    htri_t ret_value = false;
6727
6728
151k
    FUNC_ENTER_NOAPI(FAIL)
6729
6730
151k
    assert(dt);
6731
6732
151k
    if (dt->vol_obj)
6733
0
        ret_value = true;
6734
151k
    else
6735
151k
        ret_value = (H5T_STATE_OPEN == dt->shared->state || H5T_STATE_NAMED == dt->shared->state);
6736
6737
151k
done:
6738
151k
    FUNC_LEAVE_NOAPI(ret_value)
6739
151k
}
6740
6741
/*-------------------------------------------------------------------------
6742
 * Function:    H5T_convert_committed_datatype
6743
 *
6744
 * Purpose:     To convert the committed datatype "dt" to a transient embedded
6745
 *        type if the file location associated with the committed datatype is
6746
 *        different from the parameter "f".
6747
 *        "f" is the file location where the dataset or attribute will be created.
6748
 *
6749
 * Notes:       See HDFFV-9940
6750
 *
6751
 * Return:      Success:        non-negative
6752
 *              Failure:        negative
6753
 *
6754
 *-------------------------------------------------------------------------
6755
 */
6756
herr_t
6757
H5T_convert_committed_datatype(H5T_t *dt, H5F_t *f)
6758
0
{
6759
0
    herr_t ret_value = SUCCEED; /* Return value */
6760
6761
0
    FUNC_ENTER_NOAPI(FAIL)
6762
6763
0
    assert(dt);
6764
0
    assert(f);
6765
6766
0
    if (H5T_is_named(dt) && (dt->sh_loc.file != f)) {
6767
0
        assert(dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED);
6768
6769
0
        H5O_msg_reset_share(H5O_DTYPE_ID, dt);
6770
0
        if (H5O_loc_free(&dt->oloc) < 0)
6771
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to initialize location");
6772
0
        if (H5G_name_free(&dt->path) < 0)
6773
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to reset path");
6774
6775
        /* If the datatype is committed through the VOL, close it */
6776
0
        if (NULL != dt->vol_obj) {
6777
0
            H5VL_object_t *vol_obj = dt->vol_obj;
6778
6779
            /* Close the datatype through the VOL*/
6780
0
            if (H5VL_datatype_close(vol_obj, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
6781
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to close datatype");
6782
6783
            /* Free the datatype and set the VOL object pointer to NULL */
6784
0
            if (H5VL_free_object(vol_obj) < 0)
6785
0
                HGOTO_ERROR(H5E_ATTR, H5E_CANTDEC, FAIL, "unable to free VOL object");
6786
0
            dt->vol_obj = NULL;
6787
0
        } /* end if */
6788
6789
0
        dt->shared->state = H5T_STATE_TRANSIENT;
6790
0
    } /* end if */
6791
6792
0
done:
6793
0
    FUNC_LEAVE_NOAPI(ret_value)
6794
0
} /* end H5T_convert_committed_datatype() */
6795
6796
/*--------------------------------------------------------------------------
6797
 * Function:    H5T_get_ref_type
6798
 *
6799
 * Purpose:     Retrieves the type of reference for a datatype
6800
 *              H5T_t *dt;  IN: datatype pointer for the reference datatype
6801
 *
6802
 * Return:      Success:        A reference type defined in H5Rpublic.h
6803
 *              Failure:        H5R_BADTYPE
6804
 * Notes:       Given a reference datatype object, this function returns the reference type
6805
 *              of the datatype.
6806
 *--------------------------------------------------------------------------
6807
 */
6808
H5R_type_t
6809
H5T_get_ref_type(const H5T_t *dt)
6810
0
{
6811
0
    H5R_type_t ret_value = H5R_BADTYPE;
6812
6813
0
    FUNC_ENTER_NOAPI(H5R_BADTYPE)
6814
6815
0
    assert(dt);
6816
6817
0
    if (dt->shared->type == H5T_REFERENCE)
6818
0
        ret_value = dt->shared->u.atomic.u.r.rtype;
6819
6820
0
done:
6821
0
    FUNC_LEAVE_NOAPI(ret_value)
6822
0
} /* end H5T_get_ref_type() */
6823
6824
/*-------------------------------------------------------------------------
6825
 * Function:  H5T_is_sensible
6826
 *
6827
 * Purpose:   Determines if a data type is sensible to store on disk
6828
 *            (i.e. not partially initialized)
6829
 *
6830
 * Return:    Success:    true, false
6831
 *
6832
 *            Failure:    Negative
6833
 *
6834
 *-------------------------------------------------------------------------
6835
 */
6836
htri_t
6837
H5T_is_sensible(const H5T_t *dt)
6838
0
{
6839
0
    htri_t ret_value = FAIL; /* Return value */
6840
6841
0
    FUNC_ENTER_NOAPI(FAIL)
6842
6843
0
    assert(dt);
6844
6845
0
    switch (dt->shared->type) {
6846
0
        case H5T_COMPOUND:
6847
            /* Only allow compound datatypes with at least one member to be stored on disk */
6848
0
            if (dt->shared->u.compnd.nmembs > 0)
6849
0
                ret_value = true;
6850
0
            else
6851
0
                ret_value = false;
6852
0
            break;
6853
6854
0
        case H5T_ENUM:
6855
            /* Only allow enum datatypes with at least one member to be stored on disk */
6856
0
            if (dt->shared->u.enumer.nmembs > 0)
6857
0
                ret_value = true;
6858
0
            else
6859
0
                ret_value = false;
6860
0
            break;
6861
6862
0
        case H5T_NO_CLASS:
6863
0
        case H5T_INTEGER:
6864
0
        case H5T_FLOAT:
6865
0
        case H5T_TIME:
6866
0
        case H5T_STRING:
6867
0
        case H5T_BITFIELD:
6868
0
        case H5T_OPAQUE:
6869
0
        case H5T_REFERENCE:
6870
0
        case H5T_VLEN:
6871
0
        case H5T_ARRAY:
6872
0
        case H5T_COMPLEX:
6873
0
        case H5T_NCLASSES:
6874
0
        default:
6875
            /* Assume all other datatype are sensible to store on disk */
6876
0
            ret_value = true;
6877
0
            break;
6878
0
    } /* end switch */
6879
6880
0
done:
6881
0
    FUNC_LEAVE_NOAPI(ret_value)
6882
0
}
6883
6884
/*--------------------------------------------------------------------------
6885
 NAME
6886
    H5T_set_loc
6887
 PURPOSE
6888
    Recursively mark any datatypes as on disk/in memory
6889
 USAGE
6890
    htri_t H5T_set_loc(dt,f,loc)
6891
        H5T_t *dt;              IN/OUT: Pointer to the datatype to mark
6892
        H5F_t *f;               IN: Pointer to the file the datatype is in
6893
        H5T_loc_t loc           IN: location of type
6894
6895
 RETURNS
6896
    One of two values on success:
6897
        true - If the location of any vlen types changed
6898
        false - If the location of any vlen types is the same
6899
    <0 is returned on failure
6900
 DESCRIPTION
6901
    Recursively descends any VL or compound datatypes to mark all VL datatypes
6902
    as either on disk or in memory.
6903
 --------------------------------------------------------------------------
6904
 */
6905
htri_t
6906
H5T_set_loc(H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc)
6907
340k
{
6908
340k
    htri_t   changed;       /* Whether H5T_set_loc changed the type (even if the size didn't change) */
6909
340k
    htri_t   ret_value = 0; /* Indicate that success, but no location change */
6910
340k
    unsigned i;             /* Local index variable */
6911
340k
    size_t   old_size;      /* Previous size of a field */
6912
6913
340k
    FUNC_ENTER_NOAPI(FAIL)
6914
6915
340k
    assert(dt);
6916
340k
    assert(loc >= H5T_LOC_BADLOC && loc < H5T_LOC_MAXLOC);
6917
6918
    /* Datatypes can't change in size if the force_conv flag is not set */
6919
340k
    if (dt->shared->force_conv) {
6920
        /* Check the datatype of this element */
6921
78.5k
        switch (dt->shared->type) {
6922
0
            case H5T_ARRAY: /* Recurse on VL, compound and array base element type */
6923
                /* Recurse if it's VL, compound, enum or array */
6924
                /* (If the force_conv flag is _not_ set, the type cannot change in size, so don't recurse) */
6925
0
                if (dt->shared->parent->shared->force_conv &&
6926
0
                    H5T_IS_COMPOSITE(dt->shared->parent->shared->type)) {
6927
                    /* Keep the old base element size for later */
6928
0
                    old_size = dt->shared->parent->shared->size;
6929
6930
                    /* Mark the VL, compound or array type */
6931
0
                    if ((changed = H5T_set_loc(dt->shared->parent, file, loc)) < 0)
6932
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location");
6933
0
                    if (changed > 0)
6934
0
                        ret_value = changed;
6935
6936
                    /* Check if the field changed size */
6937
0
                    if (old_size != dt->shared->parent->shared->size) {
6938
                        /* Adjust the size of the array */
6939
0
                        dt->shared->size = dt->shared->u.array.nelem * dt->shared->parent->shared->size;
6940
0
                    } /* end if */
6941
0
                }     /* end if */
6942
0
                break;
6943
6944
0
            case H5T_COMPOUND: /* Check each field and recurse on VL, compound and array type */
6945
0
            {
6946
0
                ssize_t accum_change = 0; /* Amount of change in the offset of the fields */
6947
6948
                /* Sort the fields based on offsets */
6949
0
                H5T__sort_value(dt, NULL);
6950
6951
0
                for (i = 0; i < dt->shared->u.compnd.nmembs; i++) {
6952
0
                    H5T_t *memb_type; /* Member's datatype pointer */
6953
6954
                    /* Range check against compound member's offset */
6955
0
                    if ((accum_change < 0) && ((ssize_t)dt->shared->u.compnd.memb[i].offset < accum_change))
6956
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "invalid field size in datatype");
6957
6958
                    /* Apply the accumulated size change to the offset of the field */
6959
0
                    dt->shared->u.compnd.memb[i].offset += (size_t)accum_change;
6960
6961
                    /* Set the member type pointer (for convenience) */
6962
0
                    memb_type = dt->shared->u.compnd.memb[i].type;
6963
6964
                    /* Recurse if it's VL, compound, enum or array */
6965
                    /* (If the force_conv flag is _not_ set, the type cannot change in size, so don't recurse)
6966
                     */
6967
0
                    if (memb_type->shared->force_conv && H5T_IS_COMPOSITE(memb_type->shared->type)) {
6968
                        /* Keep the old field size for later */
6969
0
                        old_size = memb_type->shared->size;
6970
6971
                        /* Mark the VL, compound, enum or array type */
6972
0
                        if ((changed = H5T_set_loc(memb_type, file, loc)) < 0)
6973
0
                            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location");
6974
0
                        if (changed > 0)
6975
0
                            ret_value = changed;
6976
6977
                        /* Check if the field changed size */
6978
0
                        if (old_size != memb_type->shared->size) {
6979
6980
                            /* Fail if the old_size is zero */
6981
0
                            if (0 == old_size)
6982
0
                                HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL,
6983
0
                                            "old_size of zero would cause division by zero");
6984
6985
                            /* Adjust the size of the member */
6986
0
                            dt->shared->u.compnd.memb[i].size =
6987
0
                                (dt->shared->u.compnd.memb[i].size * memb_type->shared->size) / old_size;
6988
6989
                            /* Add that change to the accumulated size change */
6990
0
                            accum_change += (ssize_t)(memb_type->shared->size - old_size);
6991
0
                        } /* end if */
6992
0
                    }     /* end if */
6993
0
                }         /* end for */
6994
6995
                /* Range check against datatype size */
6996
0
                if ((accum_change < 0) && ((ssize_t)dt->shared->size < accum_change))
6997
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "invalid field size in datatype");
6998
6999
                /* Apply the accumulated size change to the datatype */
7000
0
                dt->shared->size += (size_t)accum_change;
7001
0
            } break;
7002
7003
32.9k
            case H5T_VLEN: /* Recurse on the VL information if it's VL, compound or array, then free VL
7004
                              sequence */
7005
                /* Recurse if it's VL, compound, enum or array (ignore references here so that we can encode
7006
                 * them as part of the same blob)*/
7007
                /* (If the force_conv flag is _not_ set, the type cannot change in size, so don't recurse) */
7008
32.9k
                if (dt->shared->parent->shared->force_conv &&
7009
19
                    H5T_IS_COMPOSITE(dt->shared->parent->shared->type) &&
7010
19
                    (dt->shared->parent->shared->type != H5T_REFERENCE)) {
7011
0
                    if ((changed = H5T_set_loc(dt->shared->parent, file, loc)) < 0)
7012
0
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location");
7013
0
                    if (changed > 0)
7014
0
                        ret_value = changed;
7015
0
                } /* end if */
7016
7017
                /* Validate file pointer for disk-based VL types */
7018
32.9k
                if (loc == H5T_LOC_DISK && NULL == file)
7019
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL,
7020
32.9k
                                "NULL file pointer for disk-based VL datatype");
7021
7022
                /* Mark this VL sequence */
7023
32.9k
                if ((changed = H5T__vlen_set_loc(dt, file, loc)) < 0)
7024
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location");
7025
32.9k
                if (changed > 0)
7026
15.3k
                    ret_value = changed;
7027
32.9k
                break;
7028
7029
45.5k
            case H5T_REFERENCE:
7030
                /* Reference types go through type conversion */
7031
45.5k
                if ((ret_value = H5T__ref_set_loc(dt, file, loc)) < 0)
7032
0
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "Unable to set reference location");
7033
45.5k
                break;
7034
7035
45.5k
            case H5T_NO_CLASS:
7036
0
            case H5T_INTEGER:
7037
0
            case H5T_FLOAT:
7038
0
            case H5T_TIME:
7039
0
            case H5T_STRING:
7040
0
            case H5T_BITFIELD:
7041
0
            case H5T_OPAQUE:
7042
0
            case H5T_ENUM:
7043
0
            case H5T_COMPLEX:
7044
0
            case H5T_NCLASSES:
7045
0
            default:
7046
0
                break;
7047
78.5k
        } /* end switch */
7048
78.5k
    }     /* end if */
7049
7050
340k
done:
7051
340k
    FUNC_LEAVE_NOAPI(ret_value)
7052
340k
} /* end H5T_set_loc() */
7053
7054
/*-------------------------------------------------------------------------
7055
 * Function:    H5T_is_relocatable
7056
 *
7057
 * Purpose:     Check if a datatype will change between disk and memory.
7058
 *
7059
 * Notes:       Currently, only variable-length and references change
7060
 *              between disk & memory (see cases where things are changed in
7061
 *              the H5T_set_loc() code above).
7062
 *
7063
 * Return:
7064
 *  One of two values on success:
7065
 *      true - If the location of any vlen types changed
7066
 *      false - If the location of any vlen types is the same
7067
 *  <0 is returned on failure
7068
 *
7069
 *-------------------------------------------------------------------------
7070
 */
7071
htri_t
7072
H5T_is_relocatable(const H5T_t *dt)
7073
0
{
7074
0
    htri_t ret_value = false;
7075
7076
0
    FUNC_ENTER_NOAPI(FAIL)
7077
7078
    /* Sanity check */
7079
0
    assert(dt);
7080
7081
    /* VL and reference datatypes are relocatable */
7082
0
    if (H5T_detect_class(dt, H5T_VLEN, false) || H5T_detect_class(dt, H5T_REFERENCE, false))
7083
0
        ret_value = true;
7084
7085
0
done:
7086
0
    FUNC_LEAVE_NOAPI(ret_value)
7087
0
} /* end H5T_is_relocatable() */
7088
7089
/*-------------------------------------------------------------------------
7090
 * Function:   H5T__detect_vlen_ref
7091
 *
7092
 * Purpose:    Check whether a datatype contains (or is) a vlen reference
7093
 *             datatype.
7094
 *
7095
 * Return:      true (1) or false (0) on success
7096
 *        (Can't fail)
7097
 *
7098
 *-------------------------------------------------------------------------
7099
 */
7100
static bool
7101
H5T__detect_vlen_ref(const H5T_t *dt)
7102
0
{
7103
0
    unsigned u;                 /* Local index variable */
7104
0
    bool     ret_value = false; /* Return value */
7105
7106
0
    FUNC_ENTER_PACKAGE_NOERR
7107
7108
    /* Sanity checks */
7109
0
    assert(dt);
7110
7111
    /* Check if this datatype is a vlen reference */
7112
    /* TODO currently H5T_STD_REF is always considered as a vlen type */
7113
0
    if (H5T_REFERENCE == dt->shared->type && !dt->shared->u.atomic.u.r.opaque)
7114
0
        HGOTO_DONE(true);
7115
7116
    /* Check for types that might have the correct type as a component */
7117
0
    switch (dt->shared->type) {
7118
0
        case H5T_COMPOUND:
7119
            /* Iterate over all the compound datatype's fields */
7120
0
            for (u = 0; u < dt->shared->u.compnd.nmembs; u++)
7121
                /* Recurse on field's datatype */
7122
0
                if (H5T__detect_vlen_ref(dt->shared->u.compnd.memb[u].type))
7123
0
                    HGOTO_DONE(true);
7124
0
            break;
7125
7126
0
        case H5T_ARRAY:
7127
0
        case H5T_VLEN:
7128
0
        case H5T_ENUM:
7129
0
            HGOTO_DONE(H5T__detect_vlen_ref(dt->shared->parent));
7130
0
            break;
7131
7132
0
        case H5T_NO_CLASS:
7133
0
        case H5T_INTEGER:
7134
0
        case H5T_FLOAT:
7135
0
        case H5T_TIME:
7136
0
        case H5T_STRING:
7137
0
        case H5T_BITFIELD:
7138
0
        case H5T_OPAQUE:
7139
0
        case H5T_REFERENCE:
7140
0
        case H5T_COMPLEX:
7141
0
        case H5T_NCLASSES:
7142
0
        default:
7143
0
            break;
7144
0
    } /* end if */
7145
7146
0
done:
7147
0
    FUNC_LEAVE_NOAPI(ret_value)
7148
0
} /* end H5T__detect_vlen_ref() */
7149
7150
/*-------------------------------------------------------------------------
7151
 * Function:    H5T_is_vl_storage
7152
 *
7153
 * Purpose:     Check if a datatype will be stored in a variable-length form.
7154
 *
7155
 * Notes:       Currently, only variable-length string & sequences and region
7156
 *              references are stored in a variable-length form.
7157
 *
7158
 * Return:
7159
 *  One of two values on success:
7160
 *      true - If the datatype will be stored in a variable-length form
7161
 *      false - If the datatype will NOT be stored in a variable-length form
7162
 *  <0 is returned on failure
7163
 *
7164
 *-------------------------------------------------------------------------
7165
 */
7166
htri_t
7167
H5T_is_vl_storage(const H5T_t *dt)
7168
0
{
7169
0
    htri_t ret_value = false;
7170
7171
0
    FUNC_ENTER_NOAPI(FAIL)
7172
7173
    /* Sanity check */
7174
0
    assert(dt);
7175
7176
    /* VL and region reference datatypes are stored in variable-length form */
7177
0
    if (H5T_detect_class(dt, H5T_VLEN, false))
7178
0
        ret_value = true;
7179
0
    else if (H5T_detect_class(dt, H5T_REFERENCE, false))
7180
0
        ret_value = H5T__detect_vlen_ref(dt);
7181
0
    else
7182
0
        ret_value = false;
7183
7184
0
done:
7185
0
    FUNC_LEAVE_NOAPI(ret_value)
7186
0
} /* end H5T_is_vl_storage() */
7187
7188
/*-------------------------------------------------------------------------
7189
 * Function:    H5T__upgrade_version_cb
7190
 *
7191
 * Purpose:     H5T__visit callback to Upgrade the version of a datatype
7192
 *              (if there's any benefit to doing so)
7193
 *
7194
 * Note:        The behavior below is tightly coupled with the "better"
7195
 *              encodings for datatype messages in the datatype message
7196
 *              encoding routine.
7197
 *
7198
 * Return:      Non-negative on success/Negative on failure
7199
 *
7200
 *-------------------------------------------------------------------------
7201
 */
7202
static herr_t
7203
H5T__upgrade_version_cb(H5T_t *dt, void *op_value)
7204
35
{
7205
35
    FUNC_ENTER_PACKAGE_NOERR
7206
7207
    /* Sanity check */
7208
35
    assert(dt);
7209
35
    assert(op_value);
7210
7211
    /* Special behavior for each type of datatype */
7212
35
    switch (dt->shared->type) {
7213
0
        case H5T_COMPOUND:
7214
0
        case H5T_ARRAY:
7215
0
        case H5T_ENUM:
7216
            /* These types benefit from "upgrading" their version */
7217
0
            if (*(unsigned *)op_value > dt->shared->version)
7218
0
                dt->shared->version = *(unsigned *)op_value;
7219
0
            break;
7220
7221
17
        case H5T_VLEN:
7222
17
            if (dt->shared->parent->shared->version > dt->shared->version)
7223
17
                dt->shared->version = dt->shared->parent->shared->version;
7224
17
            break;
7225
7226
0
        case H5T_COMPLEX:
7227
0
            if (dt->shared->parent->shared->version > dt->shared->version)
7228
0
                dt->shared->version = dt->shared->parent->shared->version;
7229
0
            break;
7230
7231
0
        case H5T_NO_CLASS:
7232
0
        case H5T_INTEGER:
7233
0
        case H5T_FLOAT:
7234
0
        case H5T_TIME:
7235
16
        case H5T_STRING:
7236
16
        case H5T_BITFIELD:
7237
16
        case H5T_OPAQUE:
7238
18
        case H5T_REFERENCE:
7239
18
        case H5T_NCLASSES:
7240
18
        default:
7241
18
            break;
7242
35
    } /* end switch */
7243
7244
35
    FUNC_LEAVE_NOAPI(SUCCEED)
7245
35
} /* end H5T__upgrade_version_cb() */
7246
7247
/*-------------------------------------------------------------------------
7248
 * Function:    H5T__upgrade_version
7249
 *
7250
 * Purpose:     Upgrade the version of a datatype (if there's any benefit to
7251
 *              doing so) and recursively apply to compound members and/or
7252
 *              parent datatypes.
7253
 *
7254
 * Return:      Non-negative on success/Negative on failure
7255
 *
7256
 *-------------------------------------------------------------------------
7257
 */
7258
herr_t
7259
H5T__upgrade_version(H5T_t *dt, unsigned new_version)
7260
17
{
7261
17
    herr_t ret_value = SUCCEED; /* Return value */
7262
7263
17
    FUNC_ENTER_PACKAGE
7264
7265
    /* Sanity check */
7266
17
    assert(dt);
7267
7268
    /* Iterate over entire datatype, upgrading the version of components, if it's useful */
7269
17
    if (H5T__visit(dt, (H5T_VISIT_SIMPLE | H5T_VISIT_COMPOSITE_LAST), H5T__upgrade_version_cb, &new_version) <
7270
17
        0)
7271
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADITER, FAIL, "iteration to upgrade datatype encoding version failed");
7272
7273
17
done:
7274
17
    FUNC_LEAVE_NOAPI(ret_value)
7275
17
} /* end H5T__upgrade_version() */
7276
7277
/*-------------------------------------------------------------------------
7278
 * Function:    H5T_set_version
7279
 *
7280
 * Purpose:     Set the encoding for a datatype to the version indicated by
7281
 *              the file's low bound if that is higher than the datatype's
7282
 *              version.
7283
 *
7284
 * Return:      Non-negative on success/Negative on failure
7285
 *
7286
 *-------------------------------------------------------------------------
7287
 */
7288
herr_t
7289
H5T_set_version(H5F_t *f, H5T_t *dt)
7290
0
{
7291
0
    unsigned vers;                /* The version */
7292
0
    herr_t   ret_value = SUCCEED; /* Return value */
7293
7294
0
    FUNC_ENTER_NOAPI(FAIL)
7295
7296
    /* Sanity check */
7297
0
    assert(f);
7298
0
    assert(dt);
7299
7300
0
    vers = H5O_dtype_ver_bounds[H5F_LOW_BOUND(f)];
7301
0
    if (vers > dt->shared->version) {
7302
        /* Upgrade the format version for the datatype */
7303
0
        if (H5T__upgrade_version(dt, vers) < 0)
7304
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't upgrade datatype encoding");
7305
0
    }
7306
7307
    /* Version bounds check */
7308
0
    if (dt->shared->version > H5O_dtype_ver_bounds[H5F_HIGH_BOUND(f)])
7309
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADRANGE, FAIL, "Datatype version out of bounds");
7310
7311
0
done:
7312
0
    FUNC_LEAVE_NOAPI(ret_value)
7313
0
} /* end H5T_set_version() */
7314
7315
/*-------------------------------------------------------------------------
7316
 * Function:    H5T_patch_file
7317
 *
7318
 * Purpose:     Patch the top-level file pointers contained in dt to point
7319
 *              to f, if dt is a committed type.  This is possible because
7320
 *              the top-level file pointer can be closed out from under
7321
 *              dt while dt is contained in the shared file's cache.
7322
 *
7323
 * Return:      SUCCEED
7324
 *
7325
 *-------------------------------------------------------------------------
7326
 */
7327
herr_t
7328
H5T_patch_file(H5T_t *dt, H5F_t *f)
7329
151k
{
7330
151k
    herr_t ret_value = SUCCEED;
7331
7332
151k
    FUNC_ENTER_NOAPI(FAIL)
7333
7334
    /* Sanity check */
7335
151k
    assert(dt);
7336
151k
    assert(f);
7337
7338
151k
    if (H5T_STATE_OPEN == dt->shared->state || H5T_STATE_NAMED == dt->shared->state) {
7339
0
        dt->oloc.file   = f;
7340
0
        dt->sh_loc.file = f;
7341
0
    } /* end if */
7342
7343
151k
done:
7344
151k
    FUNC_LEAVE_NOAPI(ret_value)
7345
151k
} /* end H5T_patch_file() */
7346
7347
/*-------------------------------------------------------------------------
7348
 * Function:    H5T_patch_vlen_file
7349
 *
7350
 * Purpose:     Patch the top-level file pointer contained in (dt->shared->u.vlen.file)
7351
 *              to point to file.  This is possible because
7352
 *              the top-level file pointer can be closed out from under
7353
 *              dt while dt is contained in the shared file's cache.
7354
 *
7355
 * Return:      SUCCEED
7356
 *
7357
 *-------------------------------------------------------------------------
7358
 */
7359
herr_t
7360
H5T_patch_vlen_file(H5T_t *dt, H5VL_object_t *file)
7361
109k
{
7362
109k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
7363
7364
    /* Sanity check */
7365
109k
    assert(dt);
7366
109k
    assert(dt->shared);
7367
109k
    assert(file);
7368
7369
109k
    if ((dt->shared->type == H5T_VLEN) && dt->shared->u.vlen.file != file)
7370
0
        dt->shared->u.vlen.file = file;
7371
7372
109k
    FUNC_LEAVE_NOAPI(SUCCEED)
7373
109k
} /* end H5T_patch_vlen_file() */
7374
7375
/*-------------------------------------------------------------------------
7376
 * Function:    H5T_own_vol_obj
7377
 *
7378
 * Purpose:     Transfers ownership of the supplied VOL object to the
7379
 *              datatype, the VOL object will be freed when the datatype
7380
 *              is closed.
7381
 *
7382
 * Return:      Non-negative on success/Negative on failure
7383
 *
7384
 *-------------------------------------------------------------------------
7385
 */
7386
herr_t
7387
H5T_own_vol_obj(H5T_t *dt, H5VL_object_t *vol_obj)
7388
10.5k
{
7389
10.5k
    herr_t ret_value = SUCCEED;
7390
7391
10.5k
    FUNC_ENTER_NOAPI(FAIL)
7392
7393
    /* Sanity check */
7394
10.5k
    assert(dt);
7395
10.5k
    assert(dt->shared);
7396
10.5k
    assert(vol_obj);
7397
7398
    /* Currently no support for owning multiple VOL objects, free the previous
7399
     * owned object.  Currently this is only used for holding open VOL objects
7400
     * used in the "loc" for vlens and references, so if this is being
7401
     * overwritten we don't need the old one anyways. */
7402
10.5k
    if (dt->shared->owned_vol_obj && H5VL_free_object(dt->shared->owned_vol_obj) < 0)
7403
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close owned VOL object");
7404
7405
    /* Take ownership */
7406
10.5k
    dt->shared->owned_vol_obj = vol_obj;
7407
10.5k
    (void)H5VL_object_inc_rc(vol_obj);
7408
7409
10.5k
done:
7410
10.5k
    FUNC_LEAVE_NOAPI(ret_value)
7411
10.5k
} /* end H5T_own_vol_obj() */
7412
7413
/*-------------------------------------------------------------------------
7414
 * Function:    H5T__get_path_table_npaths
7415
 *
7416
 * Purpose:     Testing function to return the number of type conversion
7417
 *              paths currently stored in the type conversion path table
7418
 *              cache.
7419
 *
7420
 * Return:      Number of type conversion paths (can't fail)
7421
 *
7422
 *-------------------------------------------------------------------------
7423
 */
7424
int
7425
H5T__get_path_table_npaths(void)
7426
0
{
7427
0
    int ret_value = 0;
7428
7429
0
    FUNC_ENTER_PACKAGE_NOERR
7430
7431
0
    ret_value = H5T_g.npaths;
7432
7433
0
    FUNC_LEAVE_NOAPI(ret_value)
7434
0
}
7435
7436
/*-------------------------------------------------------------------------
7437
 * Function:    H5T_is_numeric_with_unusual_unused_bits
7438
 *
7439
 * Purpose:     Detect if a datatype is a numeric datatype (int, float, or
7440
 *              bitfield) with an unusual # of unused bits.  This means
7441
 *              that the precision (i.e. the # of bits used) is less than
7442
 *              the size of the datatype, at power-of-two boundaries.
7443
 *
7444
 * Return:      true/false on success, can't fail
7445
 *
7446
 *-------------------------------------------------------------------------
7447
 */
7448
bool
7449
H5T_is_numeric_with_unusual_unused_bits(const H5T_t *dt)
7450
131k
{
7451
131k
    bool ret_value = false;
7452
7453
131k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
7454
7455
    /* Sanity check */
7456
131k
    assert(dt);
7457
131k
    assert(dt->shared);
7458
7459
    /* Is the correct type? */
7460
131k
    if (H5T_INTEGER == dt->shared->type || H5T_FLOAT == dt->shared->type ||
7461
81.0k
        H5T_BITFIELD == dt->shared->type) {
7462
7463
        /* Has unused bits? */
7464
51.3k
        if (dt->shared->size > 1 && dt->shared->u.atomic.prec < (dt->shared->size * 8))
7465
            /* Unused bits are unusually large? */
7466
511
            ret_value =
7467
511
                (dt->shared->size * 8) > (2 * (dt->shared->u.atomic.prec + dt->shared->u.atomic.offset));
7468
51.3k
    }
7469
7470
131k
    FUNC_LEAVE_NOAPI(ret_value)
7471
131k
} /* end H5T_is_numeric_with_unusual_unused_bits() */