Coverage Report

Created: 2026-11-23 00:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5Snone.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
 * Purpose: "None" selection dataspace I/O functions.
15
 */
16
17
/****************/
18
/* Module Setup */
19
/****************/
20
21
#include "H5Smodule.h" /* This source code file is part of the H5S module */
22
23
/***********/
24
/* Headers */
25
/***********/
26
#include "H5private.h"  /* Generic Functions                        */
27
#include "H5Eprivate.h" /* Error handling                           */
28
#include "H5Iprivate.h" /* ID Functions                             */
29
#include "H5Spkg.h"     /* Dataspace functions                      */
30
31
/****************/
32
/* Local Macros */
33
/****************/
34
35
/******************/
36
/* Local Typedefs */
37
/******************/
38
39
/********************/
40
/* Local Prototypes */
41
/********************/
42
43
/* Selection callbacks */
44
static herr_t   H5S__none_copy(H5S_t *dst, const H5S_t *src, bool share_selection);
45
static herr_t   H5S__none_release(H5S_t *space);
46
static htri_t   H5S__none_is_valid(const H5S_t *space);
47
static hssize_t H5S__none_serial_size(H5S_t *space);
48
static herr_t   H5S__none_serialize(H5S_t *space, uint8_t **p);
49
static herr_t   H5S__none_deserialize(H5S_t **space, const uint8_t **p, const size_t p_size, bool skip);
50
static herr_t   H5S__none_bounds(const H5S_t *space, hsize_t *start, hsize_t *end);
51
static herr_t   H5S__none_offset(const H5S_t *space, hsize_t *off);
52
static int      H5S__none_unlim_dim(const H5S_t *space);
53
static htri_t   H5S__none_is_contiguous(const H5S_t *space);
54
static htri_t   H5S__none_is_single(const H5S_t *space);
55
static htri_t   H5S__none_is_regular(H5S_t *space);
56
static htri_t   H5S__none_shape_same(H5S_t *space1, H5S_t *space2);
57
static htri_t   H5S__none_intersect_block(H5S_t *space, const hsize_t *start, const hsize_t *end);
58
static herr_t   H5S__none_adjust_u(H5S_t *space, const hsize_t *offset);
59
static herr_t   H5S__none_adjust_s(H5S_t *space, const hssize_t *offset);
60
static herr_t   H5S__none_project_scalar(const H5S_t *space, hsize_t *offset);
61
static herr_t   H5S__none_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset);
62
static herr_t   H5S__none_iter_init(H5S_t *space, H5S_sel_iter_t *iter);
63
64
/* Selection iteration callbacks */
65
static herr_t  H5S__none_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords);
66
static herr_t  H5S__none_iter_block(const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end);
67
static hsize_t H5S__none_iter_nelmts(const H5S_sel_iter_t *iter);
68
static htri_t  H5S__none_iter_has_next_block(const H5S_sel_iter_t *iter);
69
static herr_t  H5S__none_iter_next(H5S_sel_iter_t *sel_iter, size_t nelem);
70
static herr_t  H5S__none_iter_next_block(H5S_sel_iter_t *sel_iter);
71
static herr_t  H5S__none_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, size_t *nseq,
72
                                           size_t *nbytes, hsize_t *off, size_t *len);
73
static herr_t  H5S__none_iter_release(H5S_sel_iter_t *sel_iter);
74
75
/*****************************/
76
/* Library Private Variables */
77
/*****************************/
78
79
/*********************/
80
/* Package Variables */
81
/*********************/
82
83
/* Selection properties for "none" selections */
84
const H5S_select_class_t H5S_sel_none[1] = {{
85
    H5S_SEL_NONE,
86
87
    /* Methods on selection */
88
    H5S__none_copy,
89
    H5S__none_release,
90
    H5S__none_is_valid,
91
    H5S__none_serial_size,
92
    H5S__none_serialize,
93
    H5S__none_deserialize,
94
    H5S__none_bounds,
95
    H5S__none_offset,
96
    H5S__none_unlim_dim,
97
    NULL,
98
    H5S__none_is_contiguous,
99
    H5S__none_is_single,
100
    H5S__none_is_regular,
101
    H5S__none_shape_same,
102
    H5S__none_intersect_block,
103
    H5S__none_adjust_u,
104
    H5S__none_adjust_s,
105
    H5S__none_project_scalar,
106
    H5S__none_project_simple,
107
    H5S__none_iter_init,
108
}};
109
110
/*******************/
111
/* Local Variables */
112
/*******************/
113
114
/* Iteration properties for "none" selections */
115
static const H5S_sel_iter_class_t H5S_sel_iter_none[1] = {{
116
    H5S_SEL_NONE,
117
118
    /* Methods on selection iterator */
119
    H5S__none_iter_coords,
120
    H5S__none_iter_block,
121
    H5S__none_iter_nelmts,
122
    H5S__none_iter_has_next_block,
123
    H5S__none_iter_next,
124
    H5S__none_iter_next_block,
125
    H5S__none_iter_get_seq_list,
126
    H5S__none_iter_release,
127
}};
128
129
/*-------------------------------------------------------------------------
130
 * Function:    H5S__none_iter_init
131
 *
132
 * Purpose:     Initializes iteration information for "none" selection.
133
 *
134
 * Return:      Non-negative on success, negative on failure.
135
 *
136
 *-------------------------------------------------------------------------
137
 */
138
static herr_t
139
H5S__none_iter_init(H5S_t H5_ATTR_UNUSED *space, H5S_sel_iter_t *iter)
140
0
{
141
0
    FUNC_ENTER_PACKAGE_NOERR
142
143
    /* Check args */
144
0
    assert(space && H5S_SEL_NONE == H5S_GET_SELECT_TYPE(space));
145
0
    assert(iter);
146
147
    /* Initialize type of selection iterator */
148
0
    iter->type = H5S_sel_iter_none;
149
150
0
    FUNC_LEAVE_NOAPI(SUCCEED)
151
0
} /* end H5S__none_iter_init() */
152
153
/*-------------------------------------------------------------------------
154
 * Function:    H5S__none_iter_coords
155
 *
156
 * Purpose:     Retrieve the current coordinates of iterator for current
157
 *              selection
158
 *
159
 * Return:      Non-negative on success, negative on failure
160
 *
161
 *-------------------------------------------------------------------------
162
 */
163
static herr_t
164
H5S__none_iter_coords(const H5S_sel_iter_t H5_ATTR_UNUSED *iter, hsize_t H5_ATTR_UNUSED *coords)
165
0
{
166
0
    FUNC_ENTER_PACKAGE_NOERR
167
168
    /* Check args */
169
0
    assert(iter);
170
0
    assert(coords);
171
172
0
    FUNC_LEAVE_NOAPI(FAIL)
173
0
} /* end H5S__none_iter_coords() */
174
175
/*-------------------------------------------------------------------------
176
 * Function:    H5S__none_iter_block
177
 *
178
 * Purpose:     Retrieve the current block of iterator for current
179
 *              selection
180
 *
181
 * Return:      Non-negative on success, negative on failure
182
 *
183
 *-------------------------------------------------------------------------
184
 */
185
static herr_t
186
H5S__none_iter_block(const H5S_sel_iter_t H5_ATTR_UNUSED *iter, hsize_t H5_ATTR_UNUSED *start,
187
                     hsize_t H5_ATTR_UNUSED *end)
188
0
{
189
0
    FUNC_ENTER_PACKAGE_NOERR
190
191
    /* Check args */
192
0
    assert(iter);
193
0
    assert(start);
194
0
    assert(end);
195
196
0
    FUNC_LEAVE_NOAPI(FAIL)
197
0
} /* end H5S__none_iter_block() */
198
199
/*-------------------------------------------------------------------------
200
 * Function:    H5S__none_iter_nelmts
201
 *
202
 * Purpose:     Return number of elements left to process in iterator
203
 *
204
 * Return:      Non-negative number of elements on success, zero on failure
205
 *
206
 *-------------------------------------------------------------------------
207
 */
208
static hsize_t
209
H5S__none_iter_nelmts(const H5S_sel_iter_t H5_ATTR_UNUSED *iter)
210
0
{
211
0
    FUNC_ENTER_PACKAGE_NOERR
212
213
    /* Check args */
214
0
    assert(iter);
215
216
0
    FUNC_LEAVE_NOAPI(0)
217
0
} /* end H5S__none_iter_nelmts() */
218
219
/*--------------------------------------------------------------------------
220
 NAME
221
    H5S__none_iter_has_next_block
222
 PURPOSE
223
    Check if there is another block left in the current iterator
224
 USAGE
225
    htri_t H5S__none_iter_has_next_block(iter)
226
        const H5S_sel_iter_t *iter;       IN: Pointer to selection iterator
227
 RETURNS
228
    Non-negative (true/false) on success/Negative on failure
229
 DESCRIPTION
230
    Check if there is another block available in the selection iterator.
231
 GLOBAL VARIABLES
232
 COMMENTS, BUGS, ASSUMPTIONS
233
 EXAMPLES
234
 REVISION LOG
235
--------------------------------------------------------------------------*/
236
static htri_t
237
H5S__none_iter_has_next_block(const H5S_sel_iter_t H5_ATTR_UNUSED *iter)
238
0
{
239
0
    FUNC_ENTER_PACKAGE_NOERR
240
241
    /* Check args */
242
0
    assert(iter);
243
244
0
    FUNC_LEAVE_NOAPI(FAIL)
245
0
} /* end H5S__none_iter_has_next_block() */
246
247
/*--------------------------------------------------------------------------
248
 NAME
249
    H5S__none_iter_next
250
 PURPOSE
251
    Increment selection iterator
252
 USAGE
253
    herr_t H5S__none_iter_next(iter, nelem)
254
        H5S_sel_iter_t *iter;       IN: Pointer to selection iterator
255
        size_t nelem;               IN: Number of elements to advance by
256
 RETURNS
257
    Non-negative on success/Negative on failure
258
 DESCRIPTION
259
    Advance selection iterator to the NELEM'th next element in the selection.
260
 GLOBAL VARIABLES
261
 COMMENTS, BUGS, ASSUMPTIONS
262
 EXAMPLES
263
 REVISION LOG
264
--------------------------------------------------------------------------*/
265
static herr_t
266
H5S__none_iter_next(H5S_sel_iter_t H5_ATTR_UNUSED *iter, size_t H5_ATTR_UNUSED nelem)
267
0
{
268
0
    FUNC_ENTER_PACKAGE_NOERR
269
270
    /* Check args */
271
0
    assert(iter);
272
0
    assert(nelem > 0);
273
274
0
    FUNC_LEAVE_NOAPI(SUCCEED)
275
0
} /* end H5S__none_iter_next() */
276
277
/*--------------------------------------------------------------------------
278
 NAME
279
    H5S__none_iter_next_block
280
 PURPOSE
281
    Increment selection iterator to next block
282
 USAGE
283
    herr_t H5S__none_iter_next(iter)
284
        H5S_sel_iter_t *iter;       IN: Pointer to selection iterator
285
 RETURNS
286
    Non-negative on success/Negative on failure
287
 DESCRIPTION
288
    Advance selection iterator to the next block in the selection.
289
 GLOBAL VARIABLES
290
 COMMENTS, BUGS, ASSUMPTIONS
291
 EXAMPLES
292
 REVISION LOG
293
--------------------------------------------------------------------------*/
294
static herr_t
295
H5S__none_iter_next_block(H5S_sel_iter_t H5_ATTR_UNUSED *iter)
296
0
{
297
0
    FUNC_ENTER_PACKAGE_NOERR
298
299
    /* Check args */
300
0
    assert(iter);
301
302
0
    FUNC_LEAVE_NOAPI(FAIL)
303
0
} /* end H5S__none_iter_next_block() */
304
305
/*--------------------------------------------------------------------------
306
 NAME
307
    H5S__none_iter_get_seq_list
308
 PURPOSE
309
    Create a list of offsets & lengths for a selection
310
 USAGE
311
    herr_t H5S__none_iter_get_seq_list(iter,maxseq,maxelem,nseq,nelem,off,len)
312
        H5S_sel_iter_t *iter;   IN/OUT: Selection iterator describing last
313
                                    position of interest in selection.
314
        size_t maxseq;          IN: Maximum number of sequences to generate
315
        size_t maxelem;         IN: Maximum number of elements to include in the
316
                                    generated sequences
317
        size_t *nseq;           OUT: Actual number of sequences generated
318
        size_t *nelem;          OUT: Actual number of elements in sequences generated
319
        hsize_t *off;           OUT: Array of offsets
320
        size_t *len;            OUT: Array of lengths
321
 RETURNS
322
    Non-negative on success/Negative on failure.
323
 DESCRIPTION
324
    Use the selection in the dataspace to generate a list of byte offsets and
325
    lengths for the region(s) selected.  Start/Restart from the position in the
326
    ITER parameter.  The number of sequences generated is limited by the MAXSEQ
327
    parameter and the number of sequences actually generated is stored in the
328
    NSEQ parameter.
329
 GLOBAL VARIABLES
330
 COMMENTS, BUGS, ASSUMPTIONS
331
 EXAMPLES
332
 REVISION LOG
333
--------------------------------------------------------------------------*/
334
static herr_t
335
H5S__none_iter_get_seq_list(H5S_sel_iter_t H5_ATTR_UNUSED *iter, size_t H5_ATTR_UNUSED maxseq,
336
                            size_t H5_ATTR_UNUSED maxelem, size_t *nseq, size_t *nelem,
337
                            hsize_t H5_ATTR_UNUSED *off, size_t H5_ATTR_UNUSED *len)
338
0
{
339
0
    FUNC_ENTER_PACKAGE_NOERR
340
341
    /* Check args */
342
0
    assert(iter);
343
0
    assert(maxseq > 0);
344
0
    assert(maxelem > 0);
345
0
    assert(nseq);
346
0
    assert(nelem);
347
0
    assert(off);
348
0
    assert(len);
349
350
    /* "none" selections don't generate sequences of bytes */
351
0
    *nseq = 0;
352
353
    /* They don't use any elements, either */
354
0
    *nelem = 0;
355
356
0
    FUNC_LEAVE_NOAPI(SUCCEED)
357
0
} /* end H5S__none_iter_get_seq_list() */
358
359
/*--------------------------------------------------------------------------
360
 NAME
361
    H5S__none_iter_release
362
 PURPOSE
363
    Release "none" selection iterator information for a dataspace
364
 USAGE
365
    herr_t H5S__none_iter_release(iter)
366
        H5S_sel_iter_t *iter;       IN: Pointer to selection iterator
367
 RETURNS
368
    Non-negative on success/Negative on failure
369
 DESCRIPTION
370
    Releases all information for a dataspace "none" selection iterator
371
 GLOBAL VARIABLES
372
 COMMENTS, BUGS, ASSUMPTIONS
373
 EXAMPLES
374
 REVISION LOG
375
--------------------------------------------------------------------------*/
376
static herr_t
377
H5S__none_iter_release(H5S_sel_iter_t H5_ATTR_UNUSED *iter)
378
0
{
379
0
    FUNC_ENTER_PACKAGE_NOERR
380
381
    /* Check args */
382
0
    assert(iter);
383
384
0
    FUNC_LEAVE_NOAPI(SUCCEED)
385
0
} /* end H5S__none_iter_release() */
386
387
/*--------------------------------------------------------------------------
388
 NAME
389
    H5S__none_release
390
 PURPOSE
391
    Release none selection information for a dataspace
392
 USAGE
393
    herr_t H5S__none_release(space)
394
        H5S_t *space;       IN: Pointer to dataspace
395
 RETURNS
396
    Non-negative on success/Negative on failure
397
 DESCRIPTION
398
    Releases "none" selection information for a dataspace
399
 GLOBAL VARIABLES
400
 COMMENTS, BUGS, ASSUMPTIONS
401
 EXAMPLES
402
 REVISION LOG
403
--------------------------------------------------------------------------*/
404
static herr_t
405
H5S__none_release(H5S_t H5_ATTR_UNUSED *space)
406
1
{
407
1
    FUNC_ENTER_PACKAGE_NOERR
408
409
    /* Check args */
410
1
    assert(space);
411
412
1
    FUNC_LEAVE_NOAPI(SUCCEED)
413
1
} /* end H5S__none_release() */
414
415
/*--------------------------------------------------------------------------
416
 NAME
417
    H5S__none_copy
418
 PURPOSE
419
    Copy a selection from one dataspace to another
420
 USAGE
421
    herr_t H5S__none_copy(dst, src, share_selection)
422
        H5S_t *dst;  OUT: Pointer to the destination dataspace
423
        H5S_t *src;  IN: Pointer to the source dataspace
424
        bool;     IN: Whether to share the selection between the dataspaces
425
 RETURNS
426
    Non-negative on success/Negative on failure
427
 DESCRIPTION
428
    Copies the 'none' selection information from the source
429
    dataspace to the destination dataspace.
430
 GLOBAL VARIABLES
431
 COMMENTS, BUGS, ASSUMPTIONS
432
 EXAMPLES
433
 REVISION LOG
434
--------------------------------------------------------------------------*/
435
static herr_t
436
H5S__none_copy(H5S_t *dst, const H5S_t H5_ATTR_UNUSED *src, bool H5_ATTR_UNUSED share_selection)
437
4.14k
{
438
4.14k
    FUNC_ENTER_PACKAGE_NOERR
439
440
4.14k
    assert(src);
441
4.14k
    assert(dst);
442
443
    /* Set number of elements in selection */
444
4.14k
    dst->select.num_elem = 0;
445
446
4.14k
    FUNC_LEAVE_NOAPI(SUCCEED)
447
4.14k
} /* end H5S__none_copy() */
448
449
/*--------------------------------------------------------------------------
450
 NAME
451
    H5S__none_is_valid
452
 PURPOSE
453
    Check whether the selection fits within the extent, with the current
454
    offset defined.
455
 USAGE
456
    htri_t H5S__none_is_valid(space);
457
        H5S_t *space;             IN: Dataspace pointer to query
458
 RETURNS
459
    true if the selection fits within the extent, false if it does not and
460
        Negative on an error.
461
 DESCRIPTION
462
    Determines if the current selection at the current offset fits within the
463
    extent for the dataspace.  Offset is irrelevant for this type of selection.
464
 GLOBAL VARIABLES
465
 COMMENTS, BUGS, ASSUMPTIONS
466
 EXAMPLES
467
 REVISION LOG
468
--------------------------------------------------------------------------*/
469
static htri_t
470
H5S__none_is_valid(const H5S_t H5_ATTR_UNUSED *space)
471
0
{
472
0
    FUNC_ENTER_PACKAGE_NOERR
473
474
0
    assert(space);
475
476
0
    FUNC_LEAVE_NOAPI(true)
477
0
} /* end H5S__none_is_valid() */
478
479
/*--------------------------------------------------------------------------
480
 NAME
481
    H5S__none_serial_size
482
 PURPOSE
483
    Determine the number of bytes needed to store the serialized "none"
484
        selection information.
485
 USAGE
486
    hssize_t H5S__none_serial_size(space)
487
        H5S_t *space;             IN: Dataspace pointer to query
488
 RETURNS
489
    The number of bytes required on success, negative on an error.
490
 DESCRIPTION
491
    Determines the number of bytes required to serialize an "none"
492
    selection for storage on disk.
493
 GLOBAL VARIABLES
494
 COMMENTS, BUGS, ASSUMPTIONS
495
 EXAMPLES
496
 REVISION LOG
497
--------------------------------------------------------------------------*/
498
static hssize_t
499
H5S__none_serial_size(H5S_t H5_ATTR_UNUSED *space)
500
0
{
501
0
    FUNC_ENTER_PACKAGE_NOERR
502
503
0
    assert(space);
504
505
    /* Basic number of bytes required to serialize point selection:
506
     *  <type (4 bytes)> + <version (4 bytes)> + <padding (4 bytes)> +
507
     *      <length (4 bytes)> = 16 bytes
508
     */
509
0
    FUNC_LEAVE_NOAPI(16)
510
0
} /* end H5S__none_serial_size() */
511
512
/*--------------------------------------------------------------------------
513
 NAME
514
    H5S__none_serialize
515
 PURPOSE
516
    Serialize the current selection into a user-provided buffer.
517
 USAGE
518
    herr_t H5S__none_serialize(space, p)
519
        H5S_t *space;           IN: Dataspace with selection to serialize
520
        uint8_t **p;            OUT: Pointer to buffer to put serialized
521
                                selection.  Will be advanced to end of
522
                                serialized selection.
523
 RETURNS
524
    Non-negative on success/Negative on failure
525
 DESCRIPTION
526
    Serializes the current element selection into a buffer.  (Primarily for
527
    storing on disk).
528
 GLOBAL VARIABLES
529
 COMMENTS, BUGS, ASSUMPTIONS
530
 EXAMPLES
531
 REVISION LOG
532
--------------------------------------------------------------------------*/
533
static herr_t
534
H5S__none_serialize(H5S_t *space, uint8_t **p)
535
0
{
536
0
    uint8_t *pp = (*p); /* Local pointer for decoding */
537
538
0
    FUNC_ENTER_PACKAGE_NOERR
539
540
    /* Check args */
541
0
    assert(space);
542
0
    assert(p);
543
0
    assert(pp);
544
545
    /* Store the preamble information */
546
0
    UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */
547
0
    UINT32ENCODE(pp, (uint32_t)H5S_NONE_VERSION_1);         /* Store the version number */
548
0
    UINT32ENCODE(pp, (uint32_t)0);                          /* Store the un-used padding */
549
0
    UINT32ENCODE(pp, (uint32_t)0);                          /* Store the additional information length */
550
551
    /* Update encoding pointer */
552
0
    *p = pp;
553
554
0
    FUNC_LEAVE_NOAPI(SUCCEED)
555
0
} /* end H5S__none_serialize() */
556
557
/*--------------------------------------------------------------------------
558
 NAME
559
    H5S__none_deserialize
560
 PURPOSE
561
    Deserialize the current selection from a user-provided buffer.
562
 USAGE
563
    herr_t H5S__none_deserialize(space, version, flags, p)
564
        H5S_t **space;          IN/OUT: Dataspace pointer to place
565
                                selection into
566
        uint8 **p;              OUT: Pointer to buffer holding serialized
567
                                selection.  Will be advanced to end of
568
                                serialized selection.
569
 RETURNS
570
    Non-negative on success/Negative on failure
571
 DESCRIPTION
572
    Deserializes the current selection into a buffer.  (Primarily for retrieving
573
    from disk).
574
 GLOBAL VARIABLES
575
 COMMENTS, BUGS, ASSUMPTIONS
576
 EXAMPLES
577
 REVISION LOG
578
--------------------------------------------------------------------------*/
579
static herr_t
580
H5S__none_deserialize(H5S_t **space, const uint8_t **p, const size_t p_size, bool skip)
581
0
{
582
0
    H5S_t *tmp_space = NULL;            /* Pointer to actual dataspace to use,
583
                                           either *space or a newly allocated one */
584
0
    uint32_t       version;             /* Version number */
585
0
    herr_t         ret_value = SUCCEED; /* return value */
586
0
    const uint8_t *p_end;               /* Pointer to last valid byte in buffer */
587
588
0
    FUNC_ENTER_PACKAGE
589
590
0
    assert(p);
591
0
    assert(*p);
592
593
0
    if (skip)
594
0
        p_end = *p;
595
0
    else if (p_size == 0)
596
0
        HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, "empty none selection buffer");
597
0
    else
598
0
        p_end = *p + p_size - 1;
599
600
    /* As part of the efforts to push all selection-type specific coding
601
       to the callbacks, the coding for the allocation of a null dataspace
602
       is moved from H5S_select_deserialize() in H5Sselect.c to here.
603
       This is needed for decoding virtual layout in H5O__layout_decode() */
604
    /* Allocate space if not provided */
605
0
    if (!*space) {
606
0
        if (NULL == (tmp_space = H5S_create(H5S_SIMPLE)))
607
0
            HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create dataspace");
608
0
    } /* end if */
609
0
    else
610
0
        tmp_space = *space;
611
612
    /* Decode version */
613
0
    if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, *p, sizeof(uint32_t), p_end))
614
0
        HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, "buffer overflow while decoding selection version");
615
0
    UINT32DECODE(*p, version);
616
617
0
    if (version < H5S_NONE_VERSION_1 || version > H5S_NONE_VERSION_LATEST)
618
0
        HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for none selection");
619
620
    /* Skip over the remainder of the header */
621
0
    if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, *p, 8, p_end))
622
0
        HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, "buffer overflow while decoding selection header");
623
0
    *p += 8;
624
625
    /* Change to "none" selection */
626
0
    if (H5S_select_none(tmp_space) < 0)
627
0
        HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection");
628
629
    /* Return space to the caller if allocated */
630
0
    if (!*space)
631
0
        *space = tmp_space;
632
633
0
done:
634
    /* Free temporary space if not passed to caller (only happens on error) */
635
0
    if (!*space && tmp_space)
636
0
        if (H5S_close(tmp_space) < 0)
637
0
            HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't close dataspace");
638
639
0
    FUNC_LEAVE_NOAPI(ret_value)
640
0
} /* end H5S__none_deserialize() */
641
642
/*--------------------------------------------------------------------------
643
 NAME
644
    H5S__none_bounds
645
 PURPOSE
646
    Gets the bounding box containing the selection.
647
 USAGE
648
    herr_t H5S__none_bounds(space, start, end)
649
        H5S_t *space;           IN: Dataspace pointer of selection to query
650
        hsize_t *start;         OUT: Starting coordinate of bounding box
651
        hsize_t *end;           OUT: Opposite coordinate of bounding box
652
 RETURNS
653
    Non-negative on success, negative on failure
654
 DESCRIPTION
655
    Retrieves the bounding box containing the current selection and places
656
    it into the user's buffers.  The start and end buffers must be large
657
    enough to hold the dataspace rank number of coordinates.  The bounding box
658
    exactly contains the selection, ie. if a 2-D element selection is currently
659
    defined with the following points: (4,5), (6,8) (10,7), the bounding box
660
    with be (4, 5), (10, 8).  Calling this function on a "none" selection
661
    returns fail.
662
 GLOBAL VARIABLES
663
 COMMENTS, BUGS, ASSUMPTIONS
664
 EXAMPLES
665
 REVISION LOG
666
--------------------------------------------------------------------------*/
667
static herr_t
668
H5S__none_bounds(const H5S_t H5_ATTR_UNUSED *space, hsize_t H5_ATTR_UNUSED *start,
669
                 hsize_t H5_ATTR_UNUSED *end)
670
0
{
671
0
    FUNC_ENTER_PACKAGE_NOERR
672
673
0
    assert(space);
674
0
    assert(start);
675
0
    assert(end);
676
677
0
    FUNC_LEAVE_NOAPI(FAIL)
678
0
} /* end H5S_none_bounds() */
679
680
/*--------------------------------------------------------------------------
681
 NAME
682
    H5S__none_offset
683
 PURPOSE
684
    Gets the linear offset of the first element for the selection.
685
 USAGE
686
    herr_t H5S__none_offset(space, offset)
687
        const H5S_t *space;     IN: Dataspace pointer of selection to query
688
        hsize_t *offset;        OUT: Linear offset of first element in selection
689
 RETURNS
690
    Non-negative on success, negative on failure
691
 DESCRIPTION
692
    Retrieves the linear offset (in "units" of elements) of the first element
693
    selected within the dataspace.
694
 GLOBAL VARIABLES
695
 COMMENTS, BUGS, ASSUMPTIONS
696
    Calling this function on a "none" selection returns fail.
697
 EXAMPLES
698
 REVISION LOG
699
--------------------------------------------------------------------------*/
700
static herr_t
701
H5S__none_offset(const H5S_t H5_ATTR_UNUSED *space, hsize_t H5_ATTR_UNUSED *offset)
702
0
{
703
0
    FUNC_ENTER_PACKAGE_NOERR
704
705
0
    assert(space);
706
0
    assert(offset);
707
708
0
    FUNC_LEAVE_NOAPI(FAIL)
709
0
} /* end H5S__none_offset() */
710
711
/*--------------------------------------------------------------------------
712
 NAME
713
    H5S__none_unlim_dim
714
 PURPOSE
715
    Return unlimited dimension of selection, or -1 if none
716
 USAGE
717
    int H5S__none_unlim_dim(space)
718
        H5S_t *space;           IN: Dataspace pointer to check
719
 RETURNS
720
    Unlimited dimension of selection, or -1 if none (never fails).
721
 DESCRIPTION
722
    Returns the index of the unlimited dimension in this selection, or -1
723
    if the selection has no unlimited dimension.  "None" selections cannot
724
    have an unlimited dimension, so this function always returns -1.
725
 GLOBAL VARIABLES
726
 COMMENTS, BUGS, ASSUMPTIONS
727
 EXAMPLES
728
 REVISION LOG
729
--------------------------------------------------------------------------*/
730
static int
731
H5S__none_unlim_dim(const H5S_t H5_ATTR_UNUSED *space)
732
0
{
733
0
    FUNC_ENTER_PACKAGE_NOERR
734
735
0
    FUNC_LEAVE_NOAPI(-1)
736
0
} /* end H5S__none_unlim_dim() */
737
738
/*--------------------------------------------------------------------------
739
 NAME
740
    H5S__none_is_contiguous
741
 PURPOSE
742
    Check if a "none" selection is contiguous within the dataspace extent.
743
 USAGE
744
    htri_t H5S__none_is_contiguous(space)
745
        H5S_t *space;           IN: Dataspace pointer to check
746
 RETURNS
747
    true/false/FAIL
748
 DESCRIPTION
749
    Checks to see if the current selection in the dataspace is contiguous.
750
    This is primarily used for reading the entire selection in one swoop.
751
 GLOBAL VARIABLES
752
 COMMENTS, BUGS, ASSUMPTIONS
753
 EXAMPLES
754
 REVISION LOG
755
--------------------------------------------------------------------------*/
756
static htri_t
757
H5S__none_is_contiguous(const H5S_t H5_ATTR_UNUSED *space)
758
0
{
759
0
    FUNC_ENTER_PACKAGE_NOERR
760
761
0
    assert(space);
762
763
0
    FUNC_LEAVE_NOAPI(false)
764
0
} /* end H5S__none_is_contiguous() */
765
766
/*--------------------------------------------------------------------------
767
 NAME
768
    H5S__none_is_single
769
 PURPOSE
770
    Check if a "none" selection is a single block within the dataspace extent.
771
 USAGE
772
    htri_t H5S__none_is_single(space)
773
        H5S_t *space;           IN: Dataspace pointer to check
774
 RETURNS
775
    true/false/FAIL
776
 DESCRIPTION
777
    Checks to see if the current selection in the dataspace is a single block.
778
    This is primarily used for reading the entire selection in one swoop.
779
 GLOBAL VARIABLES
780
 COMMENTS, BUGS, ASSUMPTIONS
781
 EXAMPLES
782
 REVISION LOG
783
--------------------------------------------------------------------------*/
784
static htri_t
785
H5S__none_is_single(const H5S_t H5_ATTR_UNUSED *space)
786
0
{
787
0
    FUNC_ENTER_PACKAGE_NOERR
788
789
0
    assert(space);
790
791
0
    FUNC_LEAVE_NOAPI(false)
792
0
} /* end H5S__none_is_single() */
793
794
/*--------------------------------------------------------------------------
795
 NAME
796
    H5S__none_is_regular
797
 PURPOSE
798
    Check if a "none" selection is "regular"
799
 USAGE
800
    htri_t H5S__none_is_regular(space)
801
        H5S_t *space;     IN: Dataspace pointer to check
802
 RETURNS
803
    true/false/FAIL
804
 DESCRIPTION
805
    Checks to see if the current selection in a dataspace is the a regular
806
    pattern.
807
    This is primarily used for reading the entire selection in one swoop.
808
 GLOBAL VARIABLES
809
 COMMENTS, BUGS, ASSUMPTIONS
810
 EXAMPLES
811
 REVISION LOG
812
--------------------------------------------------------------------------*/
813
static htri_t
814
H5S__none_is_regular(H5S_t H5_ATTR_UNUSED *space)
815
0
{
816
0
    FUNC_ENTER_PACKAGE_NOERR
817
818
    /* Check args */
819
0
    assert(space);
820
821
0
    FUNC_LEAVE_NOAPI(true)
822
0
} /* end H5S__none_is_regular() */
823
824
/*--------------------------------------------------------------------------
825
 NAME
826
    H5S__none_shape_same
827
 PURPOSE
828
    Check if a two "none" selections are the same shape
829
 USAGE
830
    htri_t H5S__none_shape_same(space1, space2)
831
        H5S_t *space1;           IN: First dataspace to check
832
        H5S_t *space2;           IN: Second dataspace to check
833
 RETURNS
834
    true / false / FAIL
835
 DESCRIPTION
836
    Checks to see if the current selection in each dataspace are the same
837
    shape.
838
 GLOBAL VARIABLES
839
 COMMENTS, BUGS, ASSUMPTIONS
840
 EXAMPLES
841
 REVISION LOG
842
--------------------------------------------------------------------------*/
843
static htri_t
844
H5S__none_shape_same(H5S_t H5_ATTR_UNUSED *space1, H5S_t H5_ATTR_UNUSED *space2)
845
0
{
846
0
    FUNC_ENTER_PACKAGE_NOERR
847
848
    /* Check args */
849
0
    assert(space1);
850
0
    assert(space2);
851
852
0
    FUNC_LEAVE_NOAPI(true)
853
0
} /* end H5S__none_shape_same() */
854
855
/*--------------------------------------------------------------------------
856
 NAME
857
    H5S__none_intersect_block
858
 PURPOSE
859
    Detect intersections of selection with block
860
 USAGE
861
    htri_t H5S__none_intersect_block(space, start, end)
862
        H5S_t *space;           IN: Dataspace with selection to use
863
        const hsize_t *start;   IN: Starting coordinate for block
864
        const hsize_t *end;     IN: Ending coordinate for block
865
 RETURNS
866
    Non-negative true / false on success, negative on failure
867
 DESCRIPTION
868
    Quickly detect intersections with a block
869
 GLOBAL VARIABLES
870
 COMMENTS, BUGS, ASSUMPTIONS
871
 EXAMPLES
872
 REVISION LOG
873
--------------------------------------------------------------------------*/
874
htri_t
875
H5S__none_intersect_block(H5S_t H5_ATTR_UNUSED *space, const hsize_t H5_ATTR_UNUSED *start,
876
                          const hsize_t H5_ATTR_UNUSED *end)
877
0
{
878
0
    FUNC_ENTER_PACKAGE_NOERR
879
880
    /* Sanity check */
881
0
    assert(space);
882
0
    assert(H5S_SEL_NONE == H5S_GET_SELECT_TYPE(space));
883
0
    assert(start);
884
0
    assert(end);
885
886
0
    FUNC_LEAVE_NOAPI(false)
887
0
} /* end H5S__none_intersect_block() */
888
889
/*--------------------------------------------------------------------------
890
 NAME
891
    H5S__none_adjust_u
892
 PURPOSE
893
    Adjust an "none" selection by subtracting an offset
894
 USAGE
895
    herr_t H5S__none_adjust_u(space, offset)
896
        H5S_t *space;           IN/OUT: Pointer to dataspace to adjust
897
        const hsize_t *offset; IN: Offset to subtract
898
 RETURNS
899
    Non-negative on success, negative on failure
900
 DESCRIPTION
901
    Moves selection by subtracting an offset from it.
902
 GLOBAL VARIABLES
903
 COMMENTS, BUGS, ASSUMPTIONS
904
 EXAMPLES
905
 REVISION LOG
906
--------------------------------------------------------------------------*/
907
static herr_t
908
H5S__none_adjust_u(H5S_t H5_ATTR_UNUSED *space, const hsize_t H5_ATTR_UNUSED *offset)
909
0
{
910
0
    FUNC_ENTER_PACKAGE_NOERR
911
912
    /* Check args */
913
0
    assert(space);
914
0
    assert(offset);
915
916
0
    FUNC_LEAVE_NOAPI(SUCCEED)
917
0
} /* end H5S__none_adjust_u() */
918
919
/*--------------------------------------------------------------------------
920
 NAME
921
    H5S__none_adjust_s
922
 PURPOSE
923
    Adjust an "none" selection by subtracting an offset
924
 USAGE
925
    herr_t H5S__none_adjust_u(space, offset)
926
        H5S_t *space;           IN/OUT: Pointer to dataspace to adjust
927
        const hssize_t *offset; IN: Offset to subtract
928
 RETURNS
929
    Non-negative on success, negative on failure
930
 DESCRIPTION
931
    Moves selection by subtracting an offset from it.
932
 GLOBAL VARIABLES
933
 COMMENTS, BUGS, ASSUMPTIONS
934
 EXAMPLES
935
 REVISION LOG
936
--------------------------------------------------------------------------*/
937
static herr_t
938
H5S__none_adjust_s(H5S_t H5_ATTR_UNUSED *space, const hssize_t H5_ATTR_UNUSED *offset)
939
0
{
940
0
    FUNC_ENTER_PACKAGE_NOERR
941
942
    /* Check args */
943
0
    assert(space);
944
0
    assert(offset);
945
946
0
    FUNC_LEAVE_NOAPI(SUCCEED)
947
0
} /* end H5S__none_adjust_s() */
948
949
/*-------------------------------------------------------------------------
950
 * Function:    H5S__none_project_scalar
951
 *
952
 * Purpose:     Projects a 'none' selection into a scalar dataspace
953
 *
954
 * Return:      Non-negative on success, negative on failure.
955
 *
956
 *-------------------------------------------------------------------------
957
 */
958
static herr_t
959
H5S__none_project_scalar(const H5S_t H5_ATTR_UNUSED *space, hsize_t H5_ATTR_UNUSED *offset)
960
0
{
961
0
    FUNC_ENTER_PACKAGE_NOERR
962
963
    /* Check args */
964
0
    assert(space && H5S_SEL_NONE == H5S_GET_SELECT_TYPE(space));
965
0
    assert(offset);
966
967
0
    FUNC_LEAVE_NOAPI(FAIL)
968
0
} /* end H5S__none_project_scalar() */
969
970
/*-------------------------------------------------------------------------
971
 * Function:    H5S__none_project_simple
972
 *
973
 * Purpose:     Projects an 'none' selection onto/into a simple dataspace
974
 *              of a different rank
975
 *
976
 * Return:      Non-negative on success, negative on failure.
977
 *
978
 *-------------------------------------------------------------------------
979
 */
980
static herr_t
981
H5S__none_project_simple(const H5S_t H5_ATTR_UNUSED *base_space, H5S_t *new_space,
982
                         hsize_t H5_ATTR_UNUSED *offset)
983
0
{
984
0
    herr_t ret_value = SUCCEED; /* Return value */
985
986
0
    FUNC_ENTER_PACKAGE
987
988
    /* Check args */
989
0
    assert(base_space && H5S_SEL_NONE == H5S_GET_SELECT_TYPE(base_space));
990
0
    assert(new_space);
991
0
    assert(offset);
992
993
    /* Select the entire new space */
994
0
    if (H5S_select_none(new_space) < 0)
995
0
        HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "unable to set none selection");
996
997
0
done:
998
0
    FUNC_LEAVE_NOAPI(ret_value)
999
0
} /* end H5S__none_project_simple() */
1000
1001
/*--------------------------------------------------------------------------
1002
 NAME
1003
    H5S_select_none
1004
 PURPOSE
1005
    Specify that nothing is selected in the extent
1006
 USAGE
1007
    herr_t H5S_select_none(dsid)
1008
        hid_t dsid;             IN: Dataspace ID of selection to modify
1009
 RETURNS
1010
    Non-negative on success/Negative on failure
1011
 DESCRIPTION
1012
    This function de-selects the entire extent for a dataspace.
1013
 GLOBAL VARIABLES
1014
 COMMENTS, BUGS, ASSUMPTIONS
1015
 EXAMPLES
1016
 REVISION LOG
1017
--------------------------------------------------------------------------*/
1018
herr_t
1019
H5S_select_none(H5S_t *space)
1020
1
{
1021
1
    herr_t ret_value = SUCCEED; /* return value */
1022
1023
1
    FUNC_ENTER_NOAPI(FAIL)
1024
1025
    /* Check args */
1026
1
    assert(space);
1027
1028
    /* Remove current selection first */
1029
1
    if (H5S_SELECT_RELEASE(space) < 0)
1030
0
        HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release hyperslab");
1031
1032
    /* Set number of elements in selection */
1033
1
    space->select.num_elem = 0;
1034
1035
    /* Set selection type */
1036
1
    space->select.type = H5S_sel_none;
1037
1038
1
done:
1039
1
    FUNC_LEAVE_NOAPI(ret_value)
1040
1
} /* end H5S_select_none() */
1041
1042
/*--------------------------------------------------------------------------
1043
 NAME
1044
    H5Sselect_none
1045
 PURPOSE
1046
    Specify that nothing is selected in the extent
1047
 USAGE
1048
    herr_t H5Sselect_none(dsid)
1049
        hid_t dsid;             IN: Dataspace ID of selection to modify
1050
 RETURNS
1051
    Non-negative on success/Negative on failure
1052
 DESCRIPTION
1053
    This function de-selects the entire extent for a dataspace.
1054
 GLOBAL VARIABLES
1055
 COMMENTS, BUGS, ASSUMPTIONS
1056
 EXAMPLES
1057
 REVISION LOG
1058
--------------------------------------------------------------------------*/
1059
herr_t
1060
H5Sselect_none(hid_t spaceid)
1061
0
{
1062
0
    H5S_t *space;               /* Dataspace to modify selection of */
1063
0
    herr_t ret_value = SUCCEED; /* return value */
1064
1065
0
    FUNC_ENTER_API(FAIL)
1066
1067
    /* Check args */
1068
0
    if (NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE)))
1069
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace");
1070
1071
    /* Change to "none" selection */
1072
0
    if (H5S_select_none(space) < 0)
1073
0
        HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection");
1074
1075
0
done:
1076
    FUNC_LEAVE_API(ret_value)
1077
0
} /* end H5Sselect_none() */