Skip to content

Commit de6fd91

Browse files
committed
Create docs page for bson_alloc_array(0)
1 parent 34fa159 commit de6fd91

File tree

4 files changed

+91
-17
lines changed

4 files changed

+91
-17
lines changed

src/common/src/common-bson-dsl-private.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -659,24 +659,24 @@ BSON_IF_GNU_LIKE(_Pragma("GCC diagnostic ignored \"-Wshadow\""))
659659
} \
660660
} while (0);
661661

662-
#define _bsonParseMarkVisited(Index) \
663-
if (1) { \
664-
const size_t nth_int = Index / 64u; \
665-
const size_t nth_bit = Index % 64u; \
666-
while (nth_int >= _bpNumVisitBitInts) { \
667-
/* Say that five times, fast: */ \
668-
size_t new_num_visit_bit_ints = _bpNumVisitBitInts * 2u; \
662+
#define _bsonParseMarkVisited(Index) \
663+
if (1) { \
664+
const size_t nth_int = Index / 64u; \
665+
const size_t nth_bit = Index % 64u; \
666+
while (nth_int >= _bpNumVisitBitInts) { \
667+
/* Say that five times, fast: */ \
668+
size_t new_num_visit_bit_ints = _bpNumVisitBitInts * 2u; \
669669
uint64_t *new_visit_bit_ints = bson_array_alloc0(sizeof(uint64_t), new_num_visit_bit_ints); \
670-
memcpy(new_visit_bit_ints, _bpVisitBits, sizeof(uint64_t) * _bpNumVisitBitInts); \
671-
if (_bpVisitBits != _bpVisitBits_static) { \
672-
bson_free(_bpVisitBits); \
673-
} \
674-
_bpVisitBits = new_visit_bit_ints; \
675-
_bpNumVisitBitInts = new_num_visit_bit_ints; \
676-
} \
677-
\
678-
_bpVisitBits[nth_int] |= (UINT64_C(1) << nth_bit); \
679-
} else \
670+
memcpy(new_visit_bit_ints, _bpVisitBits, sizeof(uint64_t) * _bpNumVisitBitInts); \
671+
if (_bpVisitBits != _bpVisitBits_static) { \
672+
bson_free(_bpVisitBits); \
673+
} \
674+
_bpVisitBits = new_visit_bit_ints; \
675+
_bpNumVisitBitInts = new_num_visit_bit_ints; \
676+
} \
677+
\
678+
_bpVisitBits[nth_int] |= (UINT64_C(1) << nth_bit); \
679+
} else \
680680
((void)0)
681681

682682
#define _bsonParseDidVisitNth(Index) _bsonParseDidVisitNth_1(Index / 64u, Index % 64u)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:man_page: bson_alloc_array
2+
3+
bson_alloc_array()
4+
=============
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void *
12+
bson_alloc_array (size_t type_size, size_t num_elems);
13+
14+
Parameters
15+
----------
16+
17+
* ``type_size``: A size_t containing the size in bytes of a single object in the array.
18+
* ``num_elems``: A size_t containing the number of objects to be stored in the array.
19+
20+
Description
21+
-----------
22+
23+
This is a portable ``malloc()`` wrapper to allocate an array of objects.
24+
25+
In general, this function will return an allocation at least ``sizeof(void*)`` bytes or bigger.
26+
27+
If there was a failure to allocate ``type_size * num_elems`` bytes, the process will be aborted.
28+
29+
.. warning::
30+
31+
This function will abort on failure to allocate memory.
32+
33+
Returns
34+
-------
35+
36+
A pointer to a memory region which *HAS NOT* been zeroed.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:man_page: bson_alloc_array0
2+
3+
bson_alloc_array0()
4+
=============
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void *
12+
bson_alloc_array0 (size_t type_size, size_t num_elems);
13+
14+
Parameters
15+
----------
16+
17+
* ``type_size``: A size_t containing the size in bytes of a single object in the array.
18+
* ``num_elems``: A size_t containing the number of objects to be stored in the array.
19+
20+
Description
21+
-----------
22+
23+
This is a portable ``malloc()`` wrapper to allocate an array of objects that also sets the memory to zero.
24+
25+
In general, this function will return an allocation at least ``sizeof(void*)`` bytes or bigger.
26+
27+
If there was a failure to allocate ``type_size * num_elems`` bytes, the process will be aborted.
28+
29+
.. warning::
30+
31+
This function will abort on failure to allocate memory.
32+
33+
Returns
34+
-------
35+
36+
A pointer to a memory region which *HAS* been zeroed.

src/libbson/doc/bson_memory.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ To aid in language binding integration, Libbson allows for setting a custom memo
2626
bson_malloc0
2727
bson_aligned_alloc
2828
bson_aligned_alloc0
29+
bson_array_alloc
30+
bson_array_alloc0
2931
bson_mem_restore_vtable
3032
bson_mem_set_vtable
3133
bson_realloc

0 commit comments

Comments
 (0)