Coverage Report

Created: 2026-11-22 16:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5Tcommit.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 the functionality for committing datatypes
15
 *      to a file for the H5T interface.
16
 */
17
18
/****************/
19
/* Module Setup */
20
/****************/
21
22
#include "H5Tmodule.h" /* This source code file is part of the H5T module */
23
24
/***********/
25
/* Headers */
26
/***********/
27
#include "H5private.h"   /* Generic Functions                        */
28
#include "H5CXprivate.h" /* API Contexts                             */
29
#include "H5Eprivate.h"  /* Error handling                           */
30
#include "H5ESprivate.h" /* Event Sets                               */
31
#include "H5FLprivate.h" /* Free lists                               */
32
#include "H5FOprivate.h" /* File objects                             */
33
#include "H5Iprivate.h"  /* IDs                                      */
34
#include "H5Lprivate.h"  /* Links                                    */
35
#include "H5MMprivate.h" /* Memory Management                        */
36
#include "H5Oprivate.h"  /* Object headers                           */
37
#include "H5Pprivate.h"  /* Property lists                           */
38
#include "H5Tpkg.h"      /* Datatypes                                */
39
#include "H5VLprivate.h" /* Virtual Object Layer                     */
40
41
/****************/
42
/* Local Macros */
43
/****************/
44
45
/******************/
46
/* Local Typedefs */
47
/******************/
48
49
/********************/
50
/* Package Typedefs */
51
/********************/
52
53
/********************/
54
/* Local Prototypes */
55
/********************/
56
static herr_t H5T__commit_api_common(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id,
57
                                     hid_t tcpl_id, hid_t tapl_id, void **token_ptr,
58
                                     H5VL_object_t **_vol_obj_ptr);
59
static hid_t  H5T__open_api_common(hid_t loc_id, const char *name, hid_t tapl_id, void **token_ptr,
60
                                   H5VL_object_t **_vol_obj_ptr);
61
static H5T_t *H5T__open_oid(const H5G_loc_t *loc);
62
static herr_t H5T_destruct_datatype(void *datatype, H5VL_connector_t *vol_connector);
63
64
/*********************/
65
/* Public Variables */
66
/*********************/
67
68
/*********************/
69
/* Package Variables */
70
/*********************/
71
72
/*****************************/
73
/* Library Private Variables */
74
/*****************************/
75
76
/*******************/
77
/* Local Variables */
78
/*******************/
79
80
/*-------------------------------------------------------------------------
81
 * Function:    H5T__commit_api_common
82
 *
83
 * Purpose:     This is the common function for committing a datytype.
84
 *
85
 * Return:      Non-negative on success/Negative on failure
86
 *
87
 *-------------------------------------------------------------------------
88
 */
89
static herr_t
90
H5T__commit_api_common(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id,
91
                       hid_t tapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr)
92
0
{
93
0
    void           *data        = NULL; /* VOL-managed datatype data */
94
0
    H5VL_object_t  *new_obj     = NULL; /* VOL object that holds the datatype object and the VOL info */
95
0
    H5T_t          *dt          = NULL; /* High level datatype object that wraps the VOL object */
96
0
    H5VL_object_t  *tmp_vol_obj = NULL; /* Object for loc_id */
97
0
    H5VL_object_t **vol_obj_ptr =
98
0
        (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */
99
0
    H5VL_loc_params_t loc_params;                     /* Location parameters */
100
0
    herr_t            ret_value = SUCCEED;            /* Return value */
101
102
0
    FUNC_ENTER_PACKAGE
103
104
    /* Check arguments */
105
0
    if (!name)
106
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "name parameter cannot be NULL");
107
0
    if (!*name)
108
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "name parameter cannot be an empty string");
109
0
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
110
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
111
0
    if (H5T_is_named(dt))
112
0
        HGOTO_ERROR(H5E_ARGS, H5E_CANTSET, FAIL, "datatype is already committed");
113
114
    /* Get correct property list */
115
0
    if (H5P_DEFAULT == lcpl_id)
116
0
        lcpl_id = H5P_LINK_CREATE_DEFAULT;
117
0
    else if (true != H5P_isa_class(lcpl_id, H5P_LINK_CREATE))
118
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link creation property list");
119
120
    /* Get correct property list */
121
0
    if (H5P_DEFAULT == tcpl_id)
122
0
        tcpl_id = H5P_DATATYPE_CREATE_DEFAULT;
123
0
    else if (true != H5P_isa_class(tcpl_id, H5P_DATATYPE_CREATE))
124
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not datatype creation property list");
125
126
    /* Set the LCPL for the API context */
127
0
    H5CX_set_lcpl(lcpl_id);
128
129
    /* Set up object access arguments */
130
0
    if (H5VL_setup_acc_args(loc_id, H5P_CLS_TACC, true, &tapl_id, vol_obj_ptr, &loc_params) < 0)
131
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't set object access arguments");
132
133
    /* Commit the type */
134
0
    if (NULL == (data = H5VL_datatype_commit(*vol_obj_ptr, &loc_params, name, type_id, lcpl_id, tcpl_id,
135
0
                                             tapl_id, H5P_DATASET_XFER_DEFAULT, token_ptr)))
136
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to commit datatype");
137
138
    /* Set up VOL object */
139
0
    if (NULL == (new_obj = H5VL_create_object(data, H5VL_OBJ_CONNECTOR(*vol_obj_ptr))))
140
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "can't create VOL object for committed datatype");
141
142
    /* Set the committed type object to the VOL connector pointer in the H5T_t struct */
143
0
    dt->vol_obj = new_obj;
144
145
0
done:
146
0
    FUNC_LEAVE_NOAPI(ret_value)
147
0
} /* end H5T__commit_api_common() */
148
149
/*-------------------------------------------------------------------------
150
 * Function:    H5Tcommit2
151
 *
152
 * Purpose:     Save a transient datatype to a file and turn the type handle
153
 *              into a "named", immutable type.
154
 *
155
 * Return:      Non-negative on success/Negative on failure
156
 *
157
 *-------------------------------------------------------------------------
158
 */
159
herr_t
160
H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id)
161
0
{
162
0
    herr_t ret_value = SUCCEED; /* Return value */
163
164
0
    FUNC_ENTER_API(FAIL)
165
166
    /* Commit the dataset synchronously */
167
0
    if ((ret_value = H5T__commit_api_common(loc_id, name, type_id, lcpl_id, tcpl_id, tapl_id, NULL, NULL)) <
168
0
        0)
169
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to commit datatype synchronously");
170
171
0
done:
172
0
    FUNC_LEAVE_API(ret_value)
173
0
} /* end H5Tcommit2() */
174
175
/*-------------------------------------------------------------------------
176
 * Function:    H5Tcommit_async
177
 *
178
 * Purpose:     Asynchronous version of H5Tcommit2
179
 *
180
 * Return:      Non-negative on success/Negative on failure
181
 *
182
 *-------------------------------------------------------------------------
183
 */
184
herr_t
185
H5Tcommit_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name,
186
                hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id, hid_t es_id)
187
0
{
188
0
    H5VL_object_t *vol_obj   = NULL;            /* Object for loc_id */
189
0
    void          *token     = NULL;            /* Request token for async operation        */
190
0
    void         **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation        */
191
0
    herr_t         ret_value = SUCCEED;         /* Return value */
192
193
0
    FUNC_ENTER_API(FAIL)
194
195
    /* Set up request token pointer for asynchronous operation */
196
0
    if (H5ES_NONE != es_id)
197
0
        token_ptr = &token;
198
199
    /* Commit the datatype asynchronously */
200
0
    if ((ret_value = H5T__commit_api_common(loc_id, name, type_id, lcpl_id, tcpl_id, tapl_id, token_ptr,
201
0
                                            &vol_obj)) < 0)
202
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to commit datatype asynchronously");
203
204
    /* If a token was created, add the token to the event set */
205
0
    if (NULL != token)
206
        /* clang-format off */
207
0
        if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token,
208
0
                        H5ARG_TRACE10(__func__, "*s*sIui*siiiii", app_file, app_func, app_line, loc_id, name, type_id, lcpl_id, tcpl_id, tapl_id, es_id)) < 0)
209
            /* clang-format on */
210
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "can't insert token into event set");
211
212
0
done:
213
0
    FUNC_LEAVE_API(ret_value)
214
0
} /* end H5Tcommit_async() */
215
216
/*-------------------------------------------------------------------------
217
 * Function:  H5T__commit_named
218
 *
219
 * Purpose: Internal routine to save a transient datatype to a file and
220
 *              turn the type ID into a "named", immutable type.
221
 *
222
 * Return:  Non-negative on success/Negative on failure
223
 *
224
 *-------------------------------------------------------------------------
225
 */
226
herr_t
227
H5T__commit_named(const H5G_loc_t *loc, const char *name, H5T_t *dt, hid_t lcpl_id, hid_t tcpl_id)
228
0
{
229
0
    H5O_obj_create_t ocrt_info;           /* Information for object creation */
230
0
    H5T_obj_create_t tcrt_info;           /* Information for named datatype creation */
231
0
    H5T_state_t      old_state;           /* The state of the datatype before H5T__commit. */
232
0
    herr_t           ret_value = SUCCEED; /* Return value */
233
234
0
    FUNC_ENTER_PACKAGE
235
236
    /* Sanity checks */
237
0
    assert(loc);
238
0
    assert(name && *name);
239
0
    assert(dt);
240
0
    assert(lcpl_id != H5P_DEFAULT);
241
0
    assert(tcpl_id != H5P_DEFAULT);
242
243
    /* Record the type's state so that we can revert to it if linking fails */
244
0
    old_state = dt->shared->state;
245
246
    /* Set up named datatype creation info */
247
0
    tcrt_info.dt      = dt;
248
0
    tcrt_info.tcpl_id = tcpl_id;
249
250
    /* Set up object creation information */
251
0
    ocrt_info.obj_type = H5O_TYPE_NAMED_DATATYPE;
252
0
    ocrt_info.crt_info = &tcrt_info;
253
0
    ocrt_info.new_obj  = NULL;
254
255
    /* Create the new named datatype and link it to its parent group */
256
0
    if (H5L_link_object(loc, name, &ocrt_info, lcpl_id) < 0)
257
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to create and link to named datatype");
258
0
    assert(ocrt_info.new_obj);
259
260
0
done:
261
    /* If the datatype was committed but something failed after that, we need
262
     * to return it to the state it was in before it was committed.
263
     */
264
0
    if (ret_value < 0 && (NULL != ocrt_info.new_obj)) {
265
0
        if (dt->shared->state == H5T_STATE_OPEN && dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED) {
266
            /* Remove the datatype from the list of opened objects in the file */
267
0
            if (H5FO_top_decr(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) < 0)
268
0
                HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "can't decrement count for object");
269
0
            if (H5FO_delete(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) < 0)
270
0
                HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL,
271
0
                            "can't remove dataset from list of open objects");
272
273
            /* Close the datatype object */
274
0
            if (H5O_close(&(dt->oloc), NULL) < 0)
275
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to release object header");
276
277
            /* Remove the datatype's object header from the file */
278
0
            if (H5O_delete(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) < 0)
279
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTDELETE, FAIL, "unable to delete object header");
280
281
            /* Mark datatype as being back in memory */
282
0
            if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY))
283
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTDELETE, FAIL, "unable to return datatype to memory");
284
0
            dt->sh_loc.type   = H5O_SHARE_TYPE_UNSHARED;
285
0
            dt->shared->state = old_state;
286
0
        } /* end if */
287
0
    }     /* end if */
288
289
0
    FUNC_LEAVE_NOAPI(ret_value)
290
0
} /* end H5T__commit_named() */
291
292
/*-------------------------------------------------------------------------
293
 * Function:    H5Tcommit_anon
294
 *
295
 * Purpose:     Save a transient datatype to a file and turn the type handle
296
 *              into a "named", immutable type.
297
 *
298
 *              The resulting ID should be linked into the file with
299
 *              H5Olink or it will be deleted when closed.
300
 *
301
 * Note:        The datatype access property list is unused currently, but
302
 *              is checked for sanity anyway.
303
 *
304
 * Return:      Non-negative on success/Negative on failure
305
 *
306
 *-------------------------------------------------------------------------
307
 */
308
herr_t
309
H5Tcommit_anon(hid_t loc_id, hid_t type_id, hid_t tcpl_id, hid_t tapl_id)
310
0
{
311
0
    void             *dt      = NULL; /* datatype object created by VOL connector */
312
0
    H5VL_object_t    *new_obj = NULL; /* VOL object that holds the datatype object and the VOL info */
313
0
    H5T_t            *type    = NULL; /* Datatype created */
314
0
    H5VL_object_t    *vol_obj = NULL; /* object of loc_id */
315
0
    H5VL_loc_params_t loc_params;
316
0
    herr_t            ret_value = SUCCEED; /* Return value */
317
318
0
    FUNC_ENTER_API(FAIL)
319
320
    /* Check arguments */
321
0
    if (NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
322
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
323
0
    if (H5T_is_named(type))
324
0
        HGOTO_ERROR(H5E_ARGS, H5E_CANTSET, FAIL, "datatype is already committed");
325
326
    /* Get correct property list */
327
0
    if (H5P_DEFAULT == tcpl_id)
328
0
        tcpl_id = H5P_DATATYPE_CREATE_DEFAULT;
329
0
    else if (true != H5P_isa_class(tcpl_id, H5P_DATATYPE_CREATE))
330
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not datatype creation property list");
331
332
0
    if (H5P_DEFAULT == tapl_id)
333
0
        tapl_id = H5P_DATATYPE_ACCESS_DEFAULT;
334
0
    else if (true != H5P_isa_class(tapl_id, H5P_DATATYPE_ACCESS))
335
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not datatype access property list");
336
337
    /* Verify access property list and set up collective metadata if appropriate */
338
0
    if (H5CX_set_apl(&tapl_id, H5P_CLS_TACC, loc_id, true) < 0)
339
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't set access property list info");
340
341
    /* Fill in location struct fields */
342
0
    loc_params.type     = H5VL_OBJECT_BY_SELF;
343
0
    loc_params.obj_type = H5I_get_type(loc_id);
344
345
    /* Get the file object */
346
0
    if (NULL == (vol_obj = H5VL_vol_object(loc_id)))
347
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier");
348
349
    /* Commit the datatype */
350
0
    if (NULL == (dt = H5VL_datatype_commit(vol_obj, &loc_params, NULL, type_id, H5P_LINK_CREATE_DEFAULT,
351
0
                                           tcpl_id, tapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL)))
352
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to commit datatype");
353
354
    /* Setup VOL object */
355
0
    if (NULL == (new_obj = H5VL_create_object(dt, H5VL_OBJ_CONNECTOR(vol_obj))))
356
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "can't create VOL object for committed datatype");
357
358
    /* Set the committed type object to the VOL connector pointer in the H5T_t struct */
359
0
    type->vol_obj = new_obj;
360
361
0
done:
362
0
    FUNC_LEAVE_API(ret_value)
363
0
} /* end H5Tcommit_anon() */
364
365
/*-------------------------------------------------------------------------
366
 * Function:    H5T__commit_anon
367
 *
368
 * Purpose:     Create an anonymous committed datatype.
369
 *
370
 * Return:      SUCCEED/FAIL
371
 *
372
 *-------------------------------------------------------------------------
373
 */
374
herr_t
375
H5T__commit_anon(H5F_t *file, H5T_t *type, hid_t tcpl_id)
376
0
{
377
0
    H5O_loc_t *oloc;                /* Object location for datatype */
378
0
    herr_t     ret_value = SUCCEED; /* Return value */
379
380
0
    FUNC_ENTER_PACKAGE
381
382
    /* Sanity checks */
383
0
    assert(file);
384
0
    assert(type);
385
0
    assert(tcpl_id != H5P_DEFAULT);
386
387
    /* Commit the type */
388
0
    if (H5T__commit(file, type, tcpl_id) < 0)
389
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to commit datatype");
390
391
    /* Release the datatype's object header */
392
393
    /* Get the new committed datatype's object location */
394
0
    if (NULL == (oloc = H5T_oloc(type)))
395
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get object location of committed datatype");
396
397
    /* Decrement refcount on committed datatype's object header in memory */
398
0
    if (H5O_dec_rc_by_loc(oloc) < 0)
399
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on newly created object");
400
401
0
done:
402
0
    FUNC_LEAVE_NOAPI(ret_value)
403
0
} /* H5T__commit_anon() */
404
405
/*-------------------------------------------------------------------------
406
 * Function:  H5T__commit
407
 *
408
 * Purpose: Commit a type, giving it a name and causing it to become
409
 *    immutable.
410
 *
411
 * Return:  Non-negative on success/Negative on failure
412
 *
413
 *-------------------------------------------------------------------------
414
 */
415
herr_t
416
H5T__commit(H5F_t *file, H5T_t *type, hid_t tcpl_id)
417
0
{
418
0
    H5O_t     *oh = NULL;            /* Pointer to actual object header */
419
0
    H5O_loc_t  temp_oloc;            /* Temporary object header location */
420
0
    H5G_name_t temp_path;            /* Temporary path */
421
0
    bool       loc_init     = false; /* Have temp_oloc and temp_path been initialized? */
422
0
    bool       ohdr_created = false; /* Has the object header been created yet? */
423
0
    size_t     dtype_size;           /* Size of the datatype message */
424
0
    herr_t     ret_value = SUCCEED;  /* Return value */
425
426
0
    FUNC_ENTER_PACKAGE
427
428
0
    assert(file);
429
0
    assert(type);
430
0
    assert(tcpl_id != H5P_DEFAULT);
431
432
    /* Check if we are allowed to write to this file */
433
0
    if (0 == (H5F_INTENT(file) & H5F_ACC_RDWR))
434
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "no write intent on file");
435
436
    /*
437
     * Check arguments.  We cannot commit an immutable type because H5Tclose()
438
     * normally fails on such types (try H5Tclose(H5T_NATIVE_INT)) but closing
439
     * a named type should always succeed.
440
     */
441
0
    if (H5T_STATE_NAMED == type->shared->state || H5T_STATE_OPEN == type->shared->state)
442
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "datatype is already committed");
443
0
    if (H5T_STATE_IMMUTABLE == type->shared->state)
444
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "datatype is immutable");
445
446
    /* Check for a "sensible" datatype to store on disk */
447
0
    if (H5T_is_sensible(type) <= 0)
448
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "datatype is not sensible");
449
450
    /* Mark datatype as being on disk now.  This step changes the size of
451
     *  datatype as stored on disk.
452
     */
453
0
    if (H5T_set_loc(type, H5F_VOL_OBJ(file), H5T_LOC_DISK) < 0)
454
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk");
455
456
    /* Reset datatype location and path */
457
0
    if (H5O_loc_reset(&temp_oloc) < 0)
458
0
        HGOTO_ERROR(H5E_SYM, H5E_CANTRESET, FAIL, "unable to initialize location");
459
0
    if (H5G_name_reset(&temp_path) < 0)
460
0
        HGOTO_ERROR(H5E_SYM, H5E_CANTRESET, FAIL, "unable to initialize path");
461
0
    loc_init = true;
462
463
    /* Set the version for datatype */
464
0
    if (H5T_set_version(file, type) < 0)
465
0
        HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set version of datatype");
466
467
    /* Calculate message size information, for creating object header */
468
0
    dtype_size = H5O_msg_size_f(file, tcpl_id, H5O_DTYPE_ID, type, (size_t)0);
469
0
    assert(dtype_size);
470
471
    /*
472
     * Create the object header and open it for write access. Insert the data
473
     * type message and then give the object header a name.
474
     */
475
0
    if (H5O_create(file, dtype_size, (size_t)1, tcpl_id, &temp_oloc) < 0)
476
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to create datatype object header");
477
0
    ohdr_created = true;
478
479
    /* Pin the object header */
480
0
    if (NULL == (oh = H5O_pin(&temp_oloc)))
481
0
        HGOTO_ERROR(H5E_ATTR, H5E_CANTPIN, FAIL, "unable to pin object header");
482
483
    /* Check for creating committed datatype with unusual datatype */
484
0
    if (!(H5O_has_chksum(oh) || (H5F_RFIC_FLAGS(file) & H5F_RFIC_UNUSUAL_NUM_UNUSED_NUMERIC_BITS)) &&
485
0
        H5T_is_numeric_with_unusual_unused_bits(type))
486
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,
487
0
                    "creating committed datatype with unusual datatype, see documentation for "
488
0
                    "H5Pset_relax_file_integrity_checks for details.");
489
490
    /* Insert the datatype message */
491
0
    if (H5O_msg_append_oh(file, oh, H5O_DTYPE_ID, H5O_MSG_FLAG_CONSTANT | H5O_MSG_FLAG_DONTSHARE,
492
0
                          H5O_UPDATE_TIME, type) < 0)
493
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to insert type header message");
494
495
    /* Copy the new object header's location into the datatype, taking ownership of it */
496
0
    if (H5O_loc_copy_shallow(&(type->oloc), &temp_oloc) < 0)
497
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy datatype location");
498
0
    if (H5G_name_copy(&(type->path), &temp_path, H5_COPY_SHALLOW) < 0)
499
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy datatype location");
500
0
    loc_init = false;
501
502
    /* Set the shared info fields */
503
0
    H5T_update_shared(type);
504
0
    type->shared->state    = H5T_STATE_OPEN;
505
0
    type->shared->fo_count = 1;
506
507
    /* Add datatype to the list of open objects in the file */
508
0
    if (H5FO_top_incr(type->sh_loc.file, type->sh_loc.u.loc.oh_addr) < 0)
509
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, FAIL, "can't incr object ref. count");
510
0
    if (H5FO_insert(type->sh_loc.file, type->sh_loc.u.loc.oh_addr, type->shared, true) < 0)
511
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "can't insert datatype into list of open objects");
512
513
    /* Mark datatype as being on memory again.  Since this datatype may still be
514
     *  used in memory after committed to disk, change its size back as in memory.
515
     */
516
0
    if (H5T_set_loc(type, NULL, H5T_LOC_MEMORY) < 0)
517
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype in memory");
518
519
0
done:
520
0
    if (oh && H5O_unpin(oh) < 0)
521
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTUNPIN, FAIL, "unable to unpin object header");
522
523
0
    if (ret_value < 0) {
524
        /* Close & delete the object header on failure */
525
0
        if (ohdr_created) {
526
0
            H5O_loc_t *oloc_ptr; /* Pointer to object header location */
527
528
            /* Point at correct object header location, depending on state when failure occurred */
529
0
            if (loc_init)
530
0
                oloc_ptr = &temp_oloc;
531
0
            else
532
0
                oloc_ptr = &(type->oloc);
533
0
            if (H5O_dec_rc_by_loc(oloc_ptr) < 0)
534
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL,
535
0
                            "unable to decrement refcount on newly created object");
536
0
            if (H5O_close(oloc_ptr, NULL) < 0)
537
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to release object header");
538
0
            if (H5O_delete(file, oloc_ptr->addr) < 0)
539
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTDELETE, FAIL, "unable to delete object header");
540
0
        }
541
542
        /* Release the location info, if the datatype doesn't own it */
543
0
        if (loc_init) {
544
0
            H5O_loc_free(&temp_oloc);
545
0
            H5G_name_free(&temp_path);
546
0
        }
547
548
        /* Reset the shared state for the datatype */
549
0
        if ((type->shared->state == H5T_STATE_TRANSIENT || type->shared->state == H5T_STATE_RDONLY) &&
550
0
            (type->sh_loc.type == H5O_SHARE_TYPE_COMMITTED))
551
0
            type->sh_loc.type = H5O_SHARE_TYPE_UNSHARED;
552
0
    }
553
554
0
    FUNC_LEAVE_NOAPI(ret_value)
555
0
} /* H5T__commit() */
556
557
/*-------------------------------------------------------------------------
558
 * Function:    H5Tcommitted
559
 *
560
 * Purpose:     Determines if a datatype is committed or not.
561
 *
562
 * Return:      true/false/Negative
563
 *
564
 *-------------------------------------------------------------------------
565
 */
566
htri_t
567
H5Tcommitted(hid_t type_id)
568
0
{
569
0
    H5T_t *type;      /* Datatype to query */
570
0
    htri_t ret_value; /* Return value */
571
572
0
    FUNC_ENTER_API(FAIL)
573
574
    /* Check arguments */
575
0
    if (NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
576
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
577
578
    /* Set return value */
579
0
    ret_value = H5T_is_named(type);
580
581
0
done:
582
0
    FUNC_LEAVE_API(ret_value)
583
0
} /* end H5Tcommitted() */
584
585
/*-------------------------------------------------------------------------
586
 * Function:  H5T_link
587
 *
588
 * Purpose: Adjust the link count for an object header by adding
589
 *    ADJUST to the link count.
590
 *
591
 * Return:  Success:  New link count
592
 *    Failure:  -1
593
 *
594
 *-------------------------------------------------------------------------
595
 */
596
int
597
H5T_link(const H5T_t *type, int adjust)
598
0
{
599
0
    int ret_value = -1; /* Return value */
600
601
0
    FUNC_ENTER_NOAPI((-1))
602
603
0
    assert(type);
604
0
    assert(type->sh_loc.type == H5O_SHARE_TYPE_COMMITTED);
605
606
    /* Adjust the link count on the named datatype */
607
0
    if ((ret_value = H5O_link(&type->oloc, adjust)) < 0)
608
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_LINKCOUNT, (-1), "unable to adjust named datatype link count");
609
610
0
done:
611
0
    FUNC_LEAVE_NOAPI(ret_value)
612
0
} /* end H5T_link() */
613
614
/*-------------------------------------------------------------------------
615
 * Function:    H5T__open_api_common
616
 *
617
 * Purpose:     This is the common function for opening a datatype.
618
 *
619
 * Return:      Success:    Object ID of the named datatype
620
 *
621
 *              Failure:    H5I_INVALID_HID
622
 *
623
 *-------------------------------------------------------------------------
624
 */
625
static hid_t
626
H5T__open_api_common(hid_t loc_id, const char *name, hid_t tapl_id, void **token_ptr,
627
                     H5VL_object_t **_vol_obj_ptr)
628
0
{
629
0
    void           *dt          = NULL; /* datatype object created by VOL connector */
630
0
    H5VL_object_t  *tmp_vol_obj = NULL; /* Object for loc_id */
631
0
    H5VL_object_t **vol_obj_ptr =
632
0
        (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */
633
0
    H5VL_loc_params_t loc_params;
634
0
    hid_t             ret_value = H5I_INVALID_HID; /* Return value */
635
636
0
    FUNC_ENTER_PACKAGE
637
638
    /* Check args */
639
0
    if (!name)
640
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be NULL");
641
0
    if (!*name)
642
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be an empty string");
643
644
    /* Set up object access arguments */
645
0
    if (H5VL_setup_acc_args(loc_id, H5P_CLS_TACC, false, &tapl_id, vol_obj_ptr, &loc_params) < 0)
646
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments");
647
648
    /* Open the datatype */
649
0
    if (NULL == (dt = H5VL_datatype_open(*vol_obj_ptr, &loc_params, name, tapl_id, H5P_DATASET_XFER_DEFAULT,
650
0
                                         token_ptr)))
651
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open named datatype");
652
653
    /* Register the type and return the ID */
654
0
    if ((ret_value = H5VL_register(H5I_DATATYPE, dt, H5VL_OBJ_CONNECTOR(*vol_obj_ptr), true)) < 0)
655
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register named datatype");
656
657
0
done:
658
    /* Cleanup on error */
659
0
    if (H5I_INVALID_HID == ret_value)
660
0
        if (dt && H5T_destruct_datatype(dt, H5VL_OBJ_CONNECTOR(*vol_obj_ptr)) < 0)
661
0
            HDONE_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release datatype");
662
663
0
    FUNC_LEAVE_NOAPI(ret_value)
664
0
} /* end H5T__open_api_common() */
665
666
/*-------------------------------------------------------------------------
667
 * Function:    H5Topen2
668
 *
669
 * Purpose:     Opens a named datatype using a Datatype Access Property
670
 *              List.
671
 *
672
 * Return:      Success:    Object ID of the named datatype
673
 *
674
 *              Failure:    H5I_INVALID_HID
675
 *
676
 *-------------------------------------------------------------------------
677
 */
678
hid_t
679
H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id)
680
0
{
681
0
    hid_t ret_value = H5I_INVALID_HID; /* Return value */
682
683
0
    FUNC_ENTER_API(H5I_INVALID_HID)
684
685
    /* Open the datatype synchronously */
686
0
    if ((ret_value = H5T__open_api_common(loc_id, name, tapl_id, NULL, NULL)) < 0)
687
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, H5I_INVALID_HID,
688
0
                    "unable to open named datatype synchronously");
689
0
done:
690
0
    FUNC_LEAVE_API(ret_value)
691
0
} /* end H5Topen2() */
692
693
/*-------------------------------------------------------------------------
694
 * Function:    H5Topen_async
695
 *
696
 * Purpose:     Asynchronous version of H5Topen2.
697
 *
698
 * Return:      Success:    Object ID of the named datatype
699
 *
700
 *              Failure:    H5I_INVALID_HID
701
 *
702
 *-------------------------------------------------------------------------
703
 */
704
hid_t
705
H5Topen_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name,
706
              hid_t tapl_id, hid_t es_id)
707
0
{
708
0
    H5VL_object_t *vol_obj   = NULL;            /* Object for loc_id */
709
0
    void          *token     = NULL;            /* Request token for async operation */
710
0
    void         **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */
711
0
    hid_t          ret_value = H5I_INVALID_HID; /* Return value */
712
713
0
    FUNC_ENTER_API(H5I_INVALID_HID)
714
715
    /* Set up request token pointer for asynchronous operation */
716
0
    if (H5ES_NONE != es_id)
717
0
        token_ptr = &token; /* Point at token for VOL connector to set up */
718
719
    /* Open the datatype asynchronously */
720
0
    if ((ret_value = H5T__open_api_common(loc_id, name, tapl_id, token_ptr, &vol_obj)) < 0)
721
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, H5I_INVALID_HID,
722
0
                    "unable to open named datatype asynchronously");
723
724
    /* If a token was created, add the token to the event set */
725
0
    if (NULL != token)
726
        /* clang-format off */
727
0
        if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token,
728
0
                        H5ARG_TRACE7(__func__, "*s*sIui*sii", app_file, app_func, app_line, loc_id, name, tapl_id, es_id)) < 0) {
729
            /* clang-format on */
730
0
            if (H5I_dec_app_ref_always_close(ret_value) < 0)
731
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, H5I_INVALID_HID,
732
0
                            "can't decrement count on datatype ID");
733
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set");
734
0
        } /* end if */
735
736
0
done:
737
0
    FUNC_LEAVE_API(ret_value)
738
0
} /* end H5Topen_async() */
739
740
/*-------------------------------------------------------------------------
741
 * Function:    H5Tget_create_plist
742
 *
743
 * Purpose:     Returns a copy of the datatype creation property list.
744
 *
745
 * Note:        There are no datatype creation properties currently, just
746
 *              object creation ones.
747
 *
748
 * Return:      Success:    ID for a copy of the datatype creation
749
 *                          property list.  The property list ID should be
750
 *                          released by calling H5Pclose().
751
 *
752
 *              Failure:    H5I_INVALID_HID
753
 *
754
 *-------------------------------------------------------------------------
755
 */
756
hid_t
757
H5Tget_create_plist(hid_t dtype_id)
758
0
{
759
0
    H5T_t *type      = NULL;            /* Datatype object for ID */
760
0
    htri_t is_named  = FAIL;            /* Is the datatype named? */
761
0
    hid_t  ret_value = H5I_INVALID_HID; /* Return value */
762
763
0
    FUNC_ENTER_API(H5I_INVALID_HID)
764
765
    /* Check arguments */
766
0
    if (NULL == (type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE)))
767
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a datatype");
768
769
    /* Check if the datatype is committed */
770
0
    if (FAIL == (is_named = H5T_is_named(type)))
771
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID, "can't check whether datatype is committed");
772
773
    /* If the datatype is not committed/named, just copy the default
774
     * creation property list and return that.
775
     */
776
0
    if (false == is_named) {
777
0
        H5P_genplist_t *tcpl_plist = NULL;
778
779
        /* Copy the default datatype creation property list */
780
0
        if (NULL == (tcpl_plist = (H5P_genplist_t *)H5I_object(H5P_LST_DATATYPE_CREATE_ID_g)))
781
0
            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "can't get default creation property list");
782
0
        if ((ret_value = H5P_copy_plist(tcpl_plist, true)) < 0)
783
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID,
784
0
                        "unable to copy the creation property list");
785
0
    } /* end if */
786
    /* If the datatype is committed, retrieve further information */
787
0
    else {
788
0
        H5VL_object_t           *vol_obj = type->vol_obj;
789
0
        H5VL_datatype_get_args_t vol_cb_args; /* Arguments to VOL callback */
790
791
        /* Set up VOL callback arguments */
792
0
        vol_cb_args.op_type               = H5VL_DATATYPE_GET_TCPL;
793
0
        vol_cb_args.args.get_tcpl.tcpl_id = H5I_INVALID_HID;
794
795
        /* Get the property list through the VOL */
796
0
        if (H5VL_datatype_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
797
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID, "can't get object creation info");
798
799
        /* Set return value */
800
0
        ret_value = vol_cb_args.args.get_tcpl.tcpl_id;
801
0
    } /* end else */
802
803
0
done:
804
0
    FUNC_LEAVE_API(ret_value)
805
0
} /* end H5Tget_create_plist() */
806
807
/*-------------------------------------------------------------------------
808
 * Function:    H5Tflush
809
 *
810
 * Purpose:     Flushes all buffers associated with a named datatype to disk.
811
 *
812
 * Return:      Non-negative on success, negative on failure
813
 *
814
 *-------------------------------------------------------------------------
815
 */
816
herr_t
817
H5Tflush(hid_t type_id)
818
0
{
819
0
    H5T_t *dt;                  /* Datatype for this operation */
820
0
    herr_t ret_value = SUCCEED; /* Return value */
821
822
0
    FUNC_ENTER_API(FAIL)
823
824
    /* Check args */
825
0
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
826
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
827
0
    if (!H5T_is_named(dt))
828
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a committed datatype");
829
830
    /* Flush metadata for named datatype */
831
0
    if (dt->vol_obj) {
832
0
        H5VL_datatype_specific_args_t vol_cb_args; /* Arguments to VOL callback */
833
834
        /* Set up collective metadata if appropriate */
835
0
        if (H5CX_set_loc(type_id) < 0)
836
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't set access property list info");
837
838
        /* Set up VOL callback arguments */
839
0
        vol_cb_args.op_type            = H5VL_DATATYPE_FLUSH;
840
0
        vol_cb_args.args.flush.type_id = type_id;
841
842
0
        if (H5VL_datatype_specific(dt->vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
843
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFLUSH, FAIL, "unable to flush datatype");
844
0
    }
845
846
0
done:
847
0
    FUNC_LEAVE_API(ret_value)
848
0
} /* H5Tflush */
849
850
/*-------------------------------------------------------------------------
851
 * Function:    H5Trefresh
852
 *
853
 * Purpose:     Refreshes all buffers associated with a named datatype.
854
 *
855
 * Return:      Non-negative on success, negative on failure
856
 *
857
 *-------------------------------------------------------------------------
858
 */
859
herr_t
860
H5Trefresh(hid_t type_id)
861
0
{
862
0
    H5T_t *dt;                  /* Datatype for this operation */
863
0
    herr_t ret_value = SUCCEED; /* Return value */
864
865
0
    FUNC_ENTER_API(FAIL)
866
867
    /* Check args */
868
0
    if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
869
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
870
0
    if (!H5T_is_named(dt))
871
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a committed datatype");
872
873
    /* Refresh the datatype's metadata */
874
0
    if (dt->vol_obj) {
875
0
        H5VL_datatype_specific_args_t vol_cb_args; /* Arguments to VOL callback */
876
877
        /* Set up collective metadata if appropriate */
878
0
        if (H5CX_set_loc(type_id) < 0)
879
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't set access property list info");
880
881
        /* Set up VOL callback arguments */
882
0
        vol_cb_args.op_type              = H5VL_DATATYPE_REFRESH;
883
0
        vol_cb_args.args.refresh.type_id = type_id;
884
885
0
        if (H5VL_datatype_specific(dt->vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
886
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTLOAD, FAIL, "unable to refresh datatype");
887
0
    }
888
889
0
done:
890
0
    FUNC_LEAVE_API(ret_value)
891
0
} /* H5Trefresh */
892
893
/*-------------------------------------------------------------------------
894
 * Function:    H5T__get_create_plist
895
 *
896
 * Purpose:     Returns a copy of the datatype creation property list.
897
 *
898
 * Note:        There are no datatype creation properties currently, just
899
 *              object creation ones.
900
 *
901
 * Return:      Success:    ID for a copy of the datatype creation
902
 *                          property list.  The property list ID should be
903
 *                          released by calling H5Pclose().
904
 *
905
 *              Failure:    H5I_INVALID_HID
906
 *
907
 *-------------------------------------------------------------------------
908
 */
909
hid_t
910
H5T__get_create_plist(const H5T_t *type)
911
0
{
912
0
    H5P_genplist_t *tcpl_plist;                    /* Existing datatype creation propertty list */
913
0
    H5P_genplist_t *new_plist;                     /* New datatype creation property list */
914
0
    hid_t           new_tcpl_id = FAIL;            /* New datatype creation property list */
915
0
    hid_t           ret_value   = H5I_INVALID_HID; /* Return value */
916
917
0
    FUNC_ENTER_PACKAGE
918
919
    /* Sanity check */
920
0
    assert(type);
921
922
    /* Copy the default datatype creation property list */
923
0
    if (NULL == (tcpl_plist = (H5P_genplist_t *)H5I_object(H5P_LST_DATATYPE_CREATE_ID_g)))
924
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, H5I_INVALID_HID, "can't get default creation property list");
925
0
    if ((new_tcpl_id = H5P_copy_plist(tcpl_plist, true)) < 0)
926
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID, "unable to copy the creation property list");
927
928
    /* Get property list object for new TCPL */
929
0
    if (NULL == (new_plist = (H5P_genplist_t *)H5I_object(new_tcpl_id)))
930
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, H5I_INVALID_HID, "can't get property list");
931
932
    /* Retrieve any object creation properties */
933
0
    if (H5O_get_create_plist(&type->oloc, new_plist) < 0)
934
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID, "can't get object creation info");
935
936
    /* Set the return value */
937
0
    ret_value = new_tcpl_id;
938
939
0
done:
940
0
    if (ret_value < 0)
941
0
        if (new_tcpl_id > 0)
942
0
            if (H5I_dec_app_ref(new_tcpl_id) < 0)
943
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, H5I_INVALID_HID, "unable to close temporary object");
944
945
0
    FUNC_LEAVE_NOAPI(ret_value)
946
0
} /* end H5T__get_create_plist() */
947
948
/*-------------------------------------------------------------------------
949
 * Function:  H5T__open_name
950
 *
951
 * Purpose: Open a named datatype.
952
 *
953
 * Return:  Success:  Ptr to a new datatype.
954
 *    Failure:  NULL
955
 *
956
 *-------------------------------------------------------------------------
957
 */
958
H5T_t *
959
H5T__open_name(const H5G_loc_t *loc, const char *name)
960
0
{
961
0
    H5T_t     *dt = NULL;         /* Datatype opened in file */
962
0
    H5G_name_t path;              /* Datatype group hier. path */
963
0
    H5O_loc_t  oloc;              /* Datatype object location */
964
0
    H5G_loc_t  type_loc;          /* Group object for datatype */
965
0
    H5O_type_t obj_type;          /* Type of object at location */
966
0
    bool       obj_found = false; /* Object at 'name' found */
967
0
    H5T_t     *ret_value = NULL;  /* Return value */
968
969
0
    FUNC_ENTER_PACKAGE
970
971
    /* Sanity check */
972
0
    assert(loc);
973
0
    assert(name);
974
975
    /* Set up datatype location to fill in */
976
0
    type_loc.oloc = &oloc;
977
0
    type_loc.path = &path;
978
0
    H5G_loc_reset(&type_loc);
979
980
    /*
981
     * Find the named datatype object header and read the datatype message
982
     * from it.
983
     */
984
0
    if (H5G_loc_find(loc, name, &type_loc /*out*/) < 0)
985
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "not found");
986
0
    obj_found = true;
987
988
    /* Check that the object found is the correct type */
989
0
    if (H5O_obj_type(&oloc, &obj_type) < 0)
990
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, NULL, "can't get object type");
991
0
    if (obj_type != H5O_TYPE_NAMED_DATATYPE)
992
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, NULL, "not a named datatype");
993
994
    /* Open it */
995
0
    if (NULL == (dt = H5T_open(&type_loc)))
996
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to open named datatype");
997
998
0
    ret_value = dt;
999
1000
0
done:
1001
    /* Error cleanup */
1002
0
    if (NULL == ret_value)
1003
0
        if (obj_found && H5_addr_defined(type_loc.oloc->addr))
1004
0
            if (H5G_loc_free(&type_loc) < 0)
1005
0
                HDONE_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, NULL, "can't free location");
1006
1007
0
    FUNC_LEAVE_NOAPI(ret_value)
1008
0
} /* end H5T__open_name() */
1009
1010
/*-------------------------------------------------------------------------
1011
 * Function:  H5T_open
1012
 *
1013
 * Purpose: Open a named datatype.
1014
 *
1015
 * Return:  Success:  Ptr to a new datatype.
1016
 *
1017
 *    Failure:  NULL
1018
 *
1019
 *-------------------------------------------------------------------------
1020
 */
1021
H5T_t *
1022
H5T_open(const H5G_loc_t *loc)
1023
26
{
1024
26
    H5T_shared_t *shared_fo = NULL;
1025
26
    H5T_t        *dt        = NULL;
1026
26
    H5T_t        *ret_value = NULL; /* Return value */
1027
1028
26
    FUNC_ENTER_NOAPI(NULL)
1029
1030
26
    assert(loc);
1031
1032
    /* Check if datatype was already open */
1033
26
    if (NULL == (shared_fo = (H5T_shared_t *)H5FO_opened(loc->oloc->file, loc->oloc->addr))) {
1034
        /* Open the datatype object */
1035
26
        if (NULL == (dt = H5T__open_oid(loc)))
1036
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "not found");
1037
1038
        /* Add the datatype to the list of opened objects in the file */
1039
26
        if (H5FO_insert(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr, dt->shared, false) < 0)
1040
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, NULL,
1041
26
                        "can't insert datatype into list of open objects");
1042
1043
        /* Increment object count for the object in the top file */
1044
26
        if (H5FO_top_incr(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) < 0)
1045
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, NULL, "can't increment object count");
1046
1047
        /* Mark any datatypes as being in memory now */
1048
26
        if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0)
1049
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location");
1050
1051
26
        dt->shared->fo_count = 1;
1052
26
    } /* end if */
1053
0
    else {
1054
0
        if (NULL == (dt = H5FL_MALLOC(H5T_t)))
1055
0
            HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate space for datatype");
1056
0
        dt->vol_obj = NULL;
1057
1058
#if defined(H5_USING_MEMCHECKER) || !defined(NDEBUG)
1059
        /* Clear object location */
1060
        if (H5O_loc_reset(&(dt->oloc)) < 0)
1061
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to reset location");
1062
1063
        /* Clear path name */
1064
        if (H5G_name_reset(&(dt->path)) < 0)
1065
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to reset path");
1066
#endif /* H5_USING_MEMCHECKER */
1067
1068
        /* Shallow copy (take ownership) of the object location object */
1069
0
        if (H5O_loc_copy_shallow(&dt->oloc, loc->oloc) < 0)
1070
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy object location");
1071
1072
        /* Shallow copy (take ownership) of the group hier. path */
1073
0
        if (H5G_name_copy(&(dt->path), loc->path, H5_COPY_SHALLOW) < 0)
1074
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy path");
1075
1076
        /* Set the shared component info */
1077
0
        H5T_update_shared(dt);
1078
1079
        /* Point to shared datatype info */
1080
0
        dt->shared = shared_fo;
1081
1082
        /* Mark any datatypes as being in memory now */
1083
0
        if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0)
1084
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location");
1085
1086
        /* Increment ref. count on shared info */
1087
0
        shared_fo->fo_count++;
1088
1089
        /* Check if the object has been opened through the top file yet */
1090
0
        if (H5FO_top_count(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) == 0) {
1091
            /* Open the object through this top file */
1092
0
            if (H5O_open(&(dt->oloc)) < 0)
1093
0
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to open object header");
1094
0
        } /* end if */
1095
1096
        /* Increment object count for the object in the top file */
1097
0
        if (H5FO_top_incr(dt->sh_loc.file, dt->sh_loc.u.loc.oh_addr) < 0)
1098
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, NULL, "can't increment object count");
1099
0
    } /* end else */
1100
1101
26
    ret_value = dt;
1102
1103
26
done:
1104
26
    if (ret_value == NULL) {
1105
0
        if (dt) {
1106
0
            if (shared_fo == NULL) { /* Need to free shared file object */
1107
0
                if (dt->shared->owned_vol_obj && H5VL_free_object(dt->shared->owned_vol_obj) < 0)
1108
0
                    HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close owned VOL object");
1109
0
                dt->shared = H5FL_FREE(H5T_shared_t, dt->shared);
1110
0
            } /* end if */
1111
1112
0
            H5O_loc_free(&(dt->oloc));
1113
0
            H5G_name_free(&(dt->path));
1114
1115
0
            dt = H5FL_FREE(H5T_t, dt);
1116
0
        } /* end if */
1117
1118
0
        if (shared_fo)
1119
0
            shared_fo->fo_count--;
1120
0
    } /* end if */
1121
1122
26
    FUNC_LEAVE_NOAPI(ret_value)
1123
26
} /* end H5T_open() */
1124
1125
/*-------------------------------------------------------------------------
1126
 * Function:  H5T__open_oid
1127
 *
1128
 * Purpose: Open a named datatype.
1129
 *
1130
 * Return:  Success:  Ptr to a new datatype.
1131
 *
1132
 *    Failure:  NULL
1133
 *
1134
 *-------------------------------------------------------------------------
1135
 */
1136
static H5T_t *
1137
H5T__open_oid(const H5G_loc_t *loc)
1138
26
{
1139
26
    H5T_t *dt        = NULL; /* Datatype from the file */
1140
26
    H5T_t *ret_value = NULL; /* Return value */
1141
1142
26
    FUNC_ENTER_PACKAGE_TAG(loc->oloc->addr)
1143
1144
26
    assert(loc);
1145
1146
    /* Open named datatype object in file */
1147
26
    if (H5O_open(loc->oloc) < 0)
1148
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to open named datatype");
1149
1150
    /* Deserialize the datatype message into a datatype in memory */
1151
26
    if (NULL == (dt = (H5T_t *)H5O_msg_read(loc->oloc, H5O_DTYPE_ID, NULL)))
1152
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to load type message from object header");
1153
1154
    /* Mark the type as named and open */
1155
26
    dt->shared->state = H5T_STATE_OPEN;
1156
1157
    /* Shallow copy (take ownership) of the object location object */
1158
26
    if (H5O_loc_copy_shallow(&dt->oloc, loc->oloc) < 0)
1159
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy object location");
1160
1161
    /* Shallow copy (take ownership) of the group hier. path */
1162
26
    if (H5G_name_copy(&(dt->path), loc->path, H5_COPY_SHALLOW) < 0)
1163
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy path");
1164
1165
    /* Set the shared component info */
1166
26
    H5T_update_shared(dt);
1167
1168
    /* Set return value */
1169
26
    ret_value = dt;
1170
1171
26
done:
1172
26
    if (ret_value == NULL)
1173
0
        if (dt == NULL)
1174
0
            H5O_close(loc->oloc, NULL);
1175
1176
26
    FUNC_LEAVE_NOAPI_TAG(ret_value)
1177
26
} /* end H5T__open_oid() */
1178
1179
/*-------------------------------------------------------------------------
1180
 * Function:  H5T_update_shared
1181
 *
1182
 * Purpose: Update the shared location information from the object location
1183
 *
1184
 * Return:  Non-negative on success/Negative on failure
1185
 *
1186
 *-------------------------------------------------------------------------
1187
 */
1188
herr_t
1189
H5T_update_shared(H5T_t *dt)
1190
26
{
1191
26
    FUNC_ENTER_NOAPI_NOINIT_NOERR
1192
1193
26
    assert(dt);
1194
1195
    /* Set the shared location fields from the named datatype info */
1196
26
    H5O_UPDATE_SHARED(&(dt->sh_loc), H5O_SHARE_TYPE_COMMITTED, dt->oloc.file, H5O_DTYPE_ID, 0, dt->oloc.addr)
1197
1198
26
    FUNC_LEAVE_NOAPI(SUCCEED)
1199
26
} /* H5T_update_shared() */
1200
1201
/*-------------------------------------------------------------------------
1202
 * Function:    H5T_construct_datatype
1203
 *
1204
 * Purpose:     Create a Library datatype with a connector specific datatype object
1205
 *
1206
 * Return:      Success:    A type structure
1207
 *              Failure:    NULL
1208
 *
1209
 *-------------------------------------------------------------------------
1210
 */
1211
H5T_t *
1212
H5T_construct_datatype(H5VL_object_t *vol_obj)
1213
26
{
1214
26
    H5T_t                   *dt = NULL;        /* Datatype object from VOL connector */
1215
26
    H5VL_datatype_get_args_t vol_cb_args;      /* Arguments to VOL callback */
1216
26
    size_t                   nalloc    = 0;    /* Size required to store serialized form of datatype */
1217
26
    void                    *buf       = NULL; /* Buffer to store serialized datatype */
1218
26
    H5T_t                   *ret_value = NULL;
1219
1220
26
    FUNC_ENTER_NOAPI(NULL)
1221
1222
    /* Set up VOL callback arguments */
1223
26
    vol_cb_args.op_type                   = H5VL_DATATYPE_GET_BINARY_SIZE;
1224
26
    vol_cb_args.args.get_binary_size.size = &nalloc;
1225
1226
    /* Get required buf size for encoding the datatype */
1227
26
    if (H5VL_datatype_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
1228
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to get datatype serialized size");
1229
1230
    /* Allocate buffer to store binary description of the datatype */
1231
26
    if (NULL == (buf = (void *)H5MM_calloc(nalloc)))
1232
0
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate space for datatype");
1233
1234
    /* Set up VOL callback arguments */
1235
26
    vol_cb_args.op_type                  = H5VL_DATATYPE_GET_BINARY;
1236
26
    vol_cb_args.args.get_binary.buf      = buf;
1237
26
    vol_cb_args.args.get_binary.buf_size = nalloc;
1238
1239
    /* get binary description of the datatype */
1240
26
    if (H5VL_datatype_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
1241
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to get serialized datatype");
1242
1243
    /* Construct datatype, from serialized form in buffer */
1244
26
    if (NULL == (dt = H5T_decode(nalloc, buf)))
1245
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "can't decode datatype");
1246
26
    dt->vol_obj = vol_obj;
1247
1248
    /* Set return value */
1249
26
    ret_value = dt;
1250
1251
26
done:
1252
26
    if (buf)
1253
26
        buf = H5MM_xfree(buf);
1254
1255
26
    FUNC_LEAVE_NOAPI(ret_value)
1256
26
} /* end H5T_construct_datatype() */
1257
1258
/*-------------------------------------------------------------------------
1259
 * Function:    H5T_destruct_datatype
1260
 *
1261
 * Purpose:     Helper function to free a committed datatype object that
1262
 *              hasn't yet been wrapped within a VOL object. This usually
1263
 *              happens when a failure occurs during opening a committed
1264
 *              datatype. When this happens, the datatype must be wrapped
1265
 *              inside a temporary VOL object in order to route the close
1266
 *              operation through the stack of VOL connectors.
1267
 *
1268
 * Return:      Non-negative on success/Negative on failure
1269
 *
1270
 *-------------------------------------------------------------------------
1271
 */
1272
static herr_t
1273
H5T_destruct_datatype(void *datatype, H5VL_connector_t *vol_connector)
1274
0
{
1275
0
    H5VL_object_t *vol_obj   = NULL;
1276
0
    herr_t         ret_value = FAIL;
1277
1278
0
    FUNC_ENTER_NOAPI(FAIL)
1279
1280
0
    if (NULL == (vol_obj = H5VL_create_object(datatype, vol_connector)))
1281
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "can't create VOL object for committed datatype");
1282
1283
0
    if (H5VL_datatype_close(vol_obj, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
1284
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to release datatype");
1285
1286
0
done:
1287
0
    if (vol_obj && H5VL_free_object(vol_obj) < 0)
1288
0
        HDONE_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't free VOL object");
1289
1290
0
    FUNC_LEAVE_NOAPI(ret_value)
1291
0
} /* end H5T_destruct_datatype() */
1292
1293
/*-------------------------------------------------------------------------
1294
 * Function:    H5T_get_named_type
1295
 *
1296
 * Purpose:     Returns the VOL object for the named datatype if it exists
1297
 *
1298
 * Return:      Success:    Pointer to the VOL object for the datatype
1299
 *              Failure:    NULL
1300
 *
1301
 *-------------------------------------------------------------------------
1302
 */
1303
H5VL_object_t *
1304
H5T_get_named_type(const H5T_t *dt)
1305
0
{
1306
0
    H5VL_object_t *ret_value = NULL; /* Return value */
1307
1308
0
    FUNC_ENTER_NOAPI_NOINIT_NOERR
1309
1310
0
    if (NULL != dt->vol_obj)
1311
0
        ret_value = dt->vol_obj;
1312
1313
0
    FUNC_LEAVE_NOAPI(ret_value)
1314
0
} /* end H5T_get_named_type() */
1315
1316
/*-------------------------------------------------------------------------
1317
 * Function:    H5T_get_actual_type
1318
 *
1319
 * Purpose:     Returns underlying native datatype created by native connector
1320
 *              if datatype is committed, otherwise return the datatype
1321
 *              object associate with the ID.
1322
 *
1323
 * Return:      Success:    Pointer to the VOL-managed data for this datatype
1324
 *              Failure:    NULL
1325
 *
1326
 *-------------------------------------------------------------------------
1327
 */
1328
H5T_t *
1329
H5T_get_actual_type(H5T_t *dt)
1330
132
{
1331
132
    H5T_t *ret_value = NULL; /* Return value */
1332
1333
132
    FUNC_ENTER_NOAPI_NOINIT_NOERR
1334
1335
    /* Check if the datatype is committed */
1336
132
    if (NULL == dt->vol_obj)
1337
106
        ret_value = dt;
1338
26
    else
1339
26
        ret_value = (H5T_t *)H5VL_object_data(dt->vol_obj);
1340
1341
132
    FUNC_LEAVE_NOAPI(ret_value)
1342
132
} /* end H5T_get_actual_type() */
1343
1344
/*-------------------------------------------------------------------------
1345
 * Function:    H5T_save_refresh_state
1346
 *
1347
 * Purpose:     Save state for datatype reconstruction after a refresh.
1348
 *
1349
 * Return:      SUCCEED/FAIL
1350
 *
1351
 *-------------------------------------------------------------------------
1352
 */
1353
herr_t
1354
H5T_save_refresh_state(hid_t tid, H5O_shared_t *cached_H5O_shared)
1355
0
{
1356
0
    H5T_t *dt        = NULL;    /* High level datatype object that wraps the VOL object */
1357
0
    H5T_t *vol_dt    = NULL;    /* H5T_t pointer stored in the datatype's vol_obj field */
1358
0
    herr_t ret_value = SUCCEED; /* Return value */
1359
1360
0
    FUNC_ENTER_NOAPI(FAIL)
1361
1362
0
    assert(cached_H5O_shared);
1363
1364
0
    if (NULL == (dt = (H5T_t *)H5I_object_verify(tid, H5I_DATATYPE)))
1365
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "tid is not a datatype ID");
1366
0
    vol_dt = H5T_get_actual_type(dt);
1367
0
    if (NULL == vol_dt)
1368
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "tid is not not a named datatype ID");
1369
1370
    /* Increase the count on the file object */
1371
0
    vol_dt->shared->fo_count += 1;
1372
1373
    /* Increment object count for the object in the top file */
1374
0
    if (H5FO_top_incr(vol_dt->sh_loc.file, vol_dt->sh_loc.u.loc.oh_addr) < 0)
1375
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, FAIL, "can't increment object count");
1376
1377
    /* Cache the H5O_shared_t data */
1378
0
    H5MM_memcpy(cached_H5O_shared, &(vol_dt->sh_loc), sizeof(H5O_shared_t));
1379
1380
0
done:
1381
0
    FUNC_LEAVE_NOAPI(ret_value)
1382
0
} /* end H5T_save_refresh_state() */
1383
1384
/*-------------------------------------------------------------------------
1385
 * Function:    H5T_restore_refresh_state
1386
 *
1387
 * Purpose:     Restore state for datatype reconstruction after a refresh.
1388
 *
1389
 * Return:      SUCCEED/FAIL
1390
 *
1391
 *-------------------------------------------------------------------------
1392
 */
1393
herr_t
1394
H5T_restore_refresh_state(hid_t tid, H5O_shared_t *cached_H5O_shared)
1395
0
{
1396
0
    H5T_t *dt        = NULL;    /* High level datatype object that wraps the VOL object */
1397
0
    H5T_t *vol_dt    = NULL;    /* H5T_t pointer stored in the datatype's vol_obj field */
1398
0
    herr_t ret_value = SUCCEED; /* Return value */
1399
1400
0
    FUNC_ENTER_NOAPI(FAIL)
1401
1402
0
    assert(cached_H5O_shared);
1403
1404
0
    if (NULL == (dt = (H5T_t *)H5I_object_verify(tid, H5I_DATATYPE)))
1405
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "tid not a datatype ID");
1406
0
    vol_dt = H5T_get_actual_type(dt);
1407
0
    if (NULL == vol_dt)
1408
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "tid is not not a named datatype ID");
1409
1410
    /* Restore the H5O_shared_t data */
1411
0
    H5MM_memcpy(&(vol_dt->sh_loc), cached_H5O_shared, sizeof(H5O_shared_t));
1412
1413
    /* Decrement the ref. count for this object in the top file */
1414
0
    if (H5FO_top_decr(vol_dt->sh_loc.file, vol_dt->sh_loc.u.loc.oh_addr) < 0)
1415
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement object count");
1416
1417
    /* Decrease the count on the file object */
1418
0
    vol_dt->shared->fo_count -= 1;
1419
1420
0
done:
1421
0
    FUNC_LEAVE_NOAPI(ret_value)
1422
0
} /* end H5T_restore_refresh_state() */
1423
1424
/*-------------------------------------------------------------------------
1425
 * Function:    H5T_already_vol_managed
1426
 *
1427
 * Purpose:     Check if the committed datatype is already VOL managed
1428
 *
1429
 * Return:      true / false
1430
 *
1431
 *-------------------------------------------------------------------------
1432
 */
1433
bool
1434
H5T_already_vol_managed(const H5T_t *dt)
1435
0
{
1436
0
    FUNC_ENTER_NOAPI_NOINIT_NOERR
1437
1438
    /* Sanity check */
1439
0
    assert(dt);
1440
1441
0
    FUNC_LEAVE_NOAPI(dt->vol_obj != NULL)
1442
0
} /* end H5T_already_vol_managed() */
1443
1444
/*-------------------------------------------------------------------------
1445
 * Function:    H5T_invoke_vol_optional
1446
 *
1447
 * Purpose:     Invokes an optional VOL connector-specific operation on a named datatype
1448
 *
1449
 * Return:      Success:    Non-negative
1450
 *              Failure:    Negative
1451
 *
1452
 *-------------------------------------------------------------------------
1453
 */
1454
herr_t
1455
H5T_invoke_vol_optional(H5T_t *dt, H5VL_optional_args_t *args, hid_t dxpl_id, void **req,
1456
                        H5VL_object_t **vol_obj_ptr)
1457
0
{
1458
0
    herr_t ret_value = SUCCEED; /* Return value */
1459
1460
0
    FUNC_ENTER_NOAPI(FAIL)
1461
1462
    /* Check that datatype is committed */
1463
0
    if (!H5T_is_named(dt))
1464
0
        HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a committed datatype");
1465
1466
    /* Only invoke callback if VOL object is set for the datatype */
1467
0
    if (dt->vol_obj)
1468
0
        if (H5VL_datatype_optional_op(dt->vol_obj, args, dxpl_id, req, vol_obj_ptr) < 0)
1469
0
            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPERATE, FAIL, "unable to execute datatype optional callback");
1470
1471
0
done:
1472
0
    FUNC_LEAVE_NOAPI(ret_value)
1473
0
} /* end H5T_invoke_vol_optional() */