Coverage Report

Created: 2026-05-30 06:07

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