Thu, 01 Jan 2026 17:59:32 +0100
update ucx
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 16 | 29 | * @file allocator.h |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | * Interface for custom allocators. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #ifndef UCX_ALLOCATOR_H |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #define UCX_ALLOCATOR_H |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "common.h" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | * The class definition for an allocator. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | typedef struct { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | * The allocator's malloc() implementation. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | */ |
| 22 | 45 | void *(*malloc)(void *data, size_t n); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | * The allocator's realloc() implementation. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | */ |
| 22 | 50 | void *(*realloc)(void *data, void *mem, size_t n); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | * The allocator's calloc() implementation. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | */ |
| 22 | 55 | void *(*calloc)(void *data, size_t nmemb, size_t size); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | * The allocator's free() implementation. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | */ |
| 22 | 60 | void (*free)(void *data, void *mem); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | } cx_allocator_class; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | * Structure holding the data for an allocator. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | struct cx_allocator_s { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | * A pointer to the instance of the allocator class. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | cx_allocator_class *cl; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | * A pointer to the data this allocator uses. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | void *data; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | }; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | * High-Level type alias for the allocator type. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | typedef struct cx_allocator_s CxAllocator; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | /** |
| 21 | 83 | * A pre-defined allocator using standard library malloc() etc. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | */ |
| 22 | 85 | CX_EXPORT extern const CxAllocator * const cxStdlibAllocator; |
| 21 | 86 | |
| 87 | /** | |
| 88 | * The default allocator that is used by UCX. | |
| 89 | * Initialized with cxStdlibAllocator, but you may change it. | |
| 90 | */ | |
| 22 | 91 | CX_EXPORT extern const CxAllocator * cxDefaultAllocator; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | * Function pointer type for destructor functions. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | * A destructor function deallocates possible contents and MAY free the memory |
| 16 | 97 | * pointed to by @p memory. Read the documentation of the respective function |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
98 | * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
99 | * that particular implementation. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | * @param memory a pointer to the object to destruct |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
103 | typedef void (*cx_destructor_func)(void *memory); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | * Function pointer type for destructor functions. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | * A destructor function deallocates possible contents and MAY free the memory |
| 16 | 109 | * pointed to by @p memory. Read the documentation of the respective function |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
110 | * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
111 | * that particular implementation. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | * @param data an optional pointer to custom data |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | * @param memory a pointer to the object to destruct |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | */ |
| 22 | 116 | typedef void (*cx_destructor_func2)(void *data, void *memory); |
| 117 | ||
| 118 | ||
| 119 | /** | |
| 120 | * Function pointer type for clone functions. | |
| 121 | * | |
| 122 | * A clone function is supposed to create a deep copy of the memory pointed to | |
| 123 | * by the @p source pointer. | |
| 124 | * If the @p target pointer is non-null, the clone function is supposed to store | |
| 125 | * the copy into that memory region. | |
| 126 | * Otherwise, the clone function shall use the specified @p allocator to create | |
| 127 | * a new object. | |
| 128 | * | |
| 129 | * The return value of a clone function is always a pointer to the target | |
| 130 | * memory region, or @c NULL if any allocation failed. | |
| 131 | * A clone function SHOULD NOT fail for any other reason than an allocation | |
| 132 | * failure. | |
| 133 | * | |
| 134 | * @param target the target memory or @c NULL, if memory shall be allocated | |
| 135 | * @param source the source memory | |
| 136 | * @param allocator the allocator that shall be used | |
| 137 | * @param data optional additional data | |
| 138 | * @return either the specified @p target, a pointer to the allocated memory, | |
| 139 | * or @c NULL, if any error occurred | |
| 140 | */ | |
| 31 | 141 | typedef void*(*cx_clone_func)(void *target, const void *source, |
| 22 | 142 | const CxAllocator *allocator, void *data); |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
143 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
144 | /** |
| 30 | 145 | * Returns the system's memory page size. |
| 146 | * | |
| 147 | * If the page size cannot be retrieved from the system, | |
| 148 | * a default of 4096 bytes is assumed. | |
| 149 | * | |
| 150 | * @return the system's memory page size in bytes | |
| 151 | */ | |
| 38 | 152 | CX_EXTERN CX_NODISCARD |
| 153 | unsigned long cx_system_page_size(void); | |
| 30 | 154 | |
| 155 | /** | |
| 31 | 156 | * Reallocate a previously allocated block. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
157 | * |
| 31 | 158 | * Internal function - do not use. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
159 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
160 | * @param mem pointer to the pointer to allocated block |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
161 | * @param n the new size in bytes |
| 16 | 162 | * @retval zero success |
| 163 | * @retval non-zero failure | |
| 164 | * @see cx_reallocatearray() | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
165 | */ |
| 38 | 166 | CX_EXTERN CX_NONNULL CX_NODISCARD |
| 167 | int cx_reallocate_(void **mem, size_t n); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | /** |
| 31 | 170 | * Reallocate a previously allocated block. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
171 | * |
| 31 | 172 | * Internal function - do not use. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
173 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
174 | * @param mem pointer to the pointer to allocated block |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
175 | * @param nmemb the number of elements |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
176 | * @param size the size of each element |
| 16 | 177 | * @retval zero success |
| 178 | * @retval non-zero failure | |
| 179 | * @see cx_reallocate() | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
180 | */ |
| 38 | 181 | CX_EXTERN CX_NONNULL CX_NODISCARD |
| 182 | int cx_reallocatearray_(void **mem, size_t nmemb, size_t size); | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
183 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
184 | /** |
| 16 | 185 | * Reallocate a previously allocated block and changes the pointer in-place, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
186 | * if necessary. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | * |
| 21 | 188 | * @note This will use stdlib reallocate and @em not the cxDefaultAllocator. |
| 189 | * | |
| 16 | 190 | * @par Error handling |
| 191 | * @c errno will be set by realloc() on failure. | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | * |
| 16 | 193 | * @param mem (@c void**) pointer to the pointer to allocated block |
| 194 | * @param n (@c size_t) the new size in bytes | |
| 195 | * @retval zero success | |
| 196 | * @retval non-zero failure | |
| 197 | * @see cx_reallocatearray() | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | */ |
| 16 | 199 | #define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n) |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
200 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
201 | /** |
| 16 | 202 | * Reallocate a previously allocated block and changes the pointer in-place, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
203 | * if necessary. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
204 | * |
| 16 | 205 | * The size is calculated by multiplying @p nemb and @p size. |
| 206 | * | |
| 21 | 207 | * @note This will use stdlib reallocate and @em not the cxDefaultAllocator. |
| 208 | * | |
| 16 | 209 | * @par Error handling |
| 210 | * @c errno will be set by realloc() on failure or when the multiplication of | |
| 211 | * @p nmemb and @p size overflows. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
212 | * |
| 16 | 213 | * @param mem (@c void**) pointer to the pointer to allocated block |
| 214 | * @param nmemb (@c size_t) the number of elements | |
| 215 | * @param size (@c size_t) the size of each element | |
| 216 | * @retval zero success | |
| 217 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
218 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
219 | #define cx_reallocatearray(mem, nmemb, size) \ |
| 16 | 220 | cx_reallocatearray_((void**)(mem), nmemb, size) |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
221 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
222 | /** |
| 21 | 223 | * Allocates memory and sets every byte to zero. |
| 224 | * | |
| 225 | * @param n (@c size_t) the number of bytes | |
| 226 | * @return (@c void*) a pointer to the allocated memory | |
| 227 | */ | |
| 228 | #define cx_zalloc(n) calloc(1, n) | |
| 229 | ||
| 230 | /** | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
231 | * Free a block allocated by this allocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
232 | * |
| 16 | 233 | * @note Freeing a block of a different allocator is undefined. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
234 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
235 | * @param allocator the allocator |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
236 | * @param mem a pointer to the block to free |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
237 | */ |
| 38 | 238 | CX_EXTERN CX_NONNULL_ARG(1) |
| 239 | void cxFree(const CxAllocator *allocator, void *mem); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | /** |
| 16 | 242 | * Allocate @p n bytes of memory. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | * @param allocator the allocator |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | * @param n the number of bytes |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | * @return a pointer to the allocated memory |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | */ |
| 38 | 248 | CX_EXTERN CX_NODISCARD CX_NONNULL |
| 249 | CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2) | |
| 250 | void *cxMalloc(const CxAllocator *allocator, size_t n); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | /** |
| 16 | 253 | * Reallocate the previously allocated block in @p mem, making the new block |
| 254 | * @p n bytes long. | |
| 22 | 255 | * This function may return the same pointer passed to it if moving |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
256 | * the memory was not necessary. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | * |
| 16 | 258 | * @note Re-allocating a block allocated by a different allocator is undefined. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | * |
| 31 | 260 | * @attention This function is bug-prone. Consider using cxReallocate(). |
| 261 | * | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | * @param allocator the allocator |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | * @param mem pointer to the previously allocated block |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | * @param n the new size in bytes |
| 16 | 265 | * @return a pointer to the reallocated memory |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | */ |
| 38 | 267 | CX_EXTERN CX_NODISCARD CX_NONNULL_ARG(1) |
| 268 | CX_DEALLOC_UCX CX_ALLOCSIZE(3) | |
| 269 | void *cxRealloc(const CxAllocator *allocator, void *mem, size_t n); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | /** |
| 31 | 272 | * Reallocate the previously allocated block in @p mem. |
| 273 | * | |
| 22 | 274 | * This function may return the same pointer passed to it if moving |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
275 | * the memory was not necessary. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
276 | * |
| 16 | 277 | * The size is calculated by multiplying @p nemb and @p size. |
| 22 | 278 | * If that multiplication overflows, this function returns @c NULL, and @c errno |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
279 | * will be set. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
280 | * |
| 16 | 281 | * @note Re-allocating a block allocated by a different allocator is undefined. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
282 | * |
| 31 | 283 | * @attention This function is bug-prone. Consider using cxReallocateArray(). |
| 284 | * | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
285 | * @param allocator the allocator |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
286 | * @param mem pointer to the previously allocated block |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
287 | * @param nmemb the number of elements |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
288 | * @param size the size of each element |
| 16 | 289 | * @return a pointer to the reallocated memory |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
290 | */ |
| 38 | 291 | CX_EXTERN CX_NODISCARD CX_NONNULL_ARG(1) |
| 292 | CX_DEALLOC_UCX CX_ALLOCSIZE(3, 4) | |
| 293 | void *cxReallocArray(const CxAllocator *allocator, | |
| 22 | 294 | void *mem, size_t nmemb, size_t size); |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
295 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
296 | /** |
| 31 | 297 | * Reallocate a previously allocated block. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | * |
| 31 | 299 | * Internal function - do not use. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | * @param allocator the allocator |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | * @param mem pointer to the pointer to allocated block |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | * @param n the new size in bytes |
| 16 | 304 | * @retval zero success |
| 305 | * @retval non-zero failure | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | */ |
| 38 | 307 | CX_EXTERN CX_NODISCARD CX_NONNULL |
| 308 | int cxReallocate_(const CxAllocator *allocator, void **mem, size_t n); | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
309 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
310 | /** |
| 16 | 311 | * Reallocate a previously allocated block and changes the pointer in-place, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
312 | * if necessary. |
| 16 | 313 | * This function acts like cxRealloc() using the pointer pointed to by @p mem. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
314 | * |
| 16 | 315 | * @note Re-allocating a block allocated by a different allocator is undefined. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
316 | * |
| 16 | 317 | * @par Error handling |
| 22 | 318 | * @c errno will be set if the underlying realloc function does so. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
319 | * |
| 16 | 320 | * @param allocator (@c CxAllocator*) the allocator |
| 321 | * @param mem (@c void**) pointer to the pointer to allocated block | |
| 322 | * @param n (@c size_t) the new size in bytes | |
| 323 | * @retval zero success | |
| 324 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
325 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
326 | #define cxReallocate(allocator, mem, n) \ |
| 16 | 327 | cxReallocate_(allocator, (void**)(mem), n) |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
328 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
329 | /** |
| 31 | 330 | * Reallocate a previously allocated block. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
331 | * |
| 31 | 332 | * Internal function - do not use. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
333 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
334 | * @param allocator the allocator |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
335 | * @param mem pointer to the pointer to allocated block |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
336 | * @param nmemb the number of elements |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
337 | * @param size the size of each element |
| 16 | 338 | * @retval zero success |
| 339 | * @retval non-zero on failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
340 | */ |
| 38 | 341 | CX_EXTERN CX_NODISCARD CX_NONNULL |
| 342 | int cxReallocateArray_(const CxAllocator *allocator, | |
| 22 | 343 | void **mem, size_t nmemb, size_t size); |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
344 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
345 | /** |
| 16 | 346 | * Reallocate a previously allocated block and changes the pointer in-place, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
347 | * if necessary. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
348 | * This function acts like cxReallocArray() using the pointer pointed to |
| 16 | 349 | * by @p mem. |
| 350 | * | |
| 351 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
352 | * |
| 16 | 353 | * @par Error handling |
| 354 | * @c errno will be set, if the underlying realloc function does so or the | |
| 355 | * multiplication of @p nmemb and @p size overflows. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
356 | * |
| 16 | 357 | * @param allocator (@c CxAllocator*) the allocator |
| 358 | * @param mem (@c void**) pointer to the pointer to allocated block | |
| 359 | * @param nmemb (@c size_t) the number of elements | |
| 360 | * @param size (@c size_t) the size of each element | |
| 361 | * @retval zero success | |
| 362 | * @retval non-zero failure | |
| 363 | */ | |
| 364 | #define cxReallocateArray(allocator, mem, nmemb, size) \ | |
| 365 | cxReallocateArray_(allocator, (void**) (mem), nmemb, size) | |
| 366 | ||
| 367 | /** | |
| 31 | 368 | * Allocate @p nmemb elements of @p size bytes each, all initialized to zero. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
369 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
370 | * @param allocator the allocator |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
371 | * @param nmemb the number of elements |
| 16 | 372 | * @param size the size of each element in bytes |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | * @return a pointer to the allocated memory |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | */ |
| 38 | 375 | CX_EXTERN CX_NONNULL_ARG(1) CX_NODISCARD |
| 376 | CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2, 3) | |
| 377 | void *cxCalloc(const CxAllocator *allocator, size_t nmemb, size_t size); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | |
| 21 | 379 | /** |
| 380 | * Allocate @p n bytes of memory and sets every byte to zero. | |
| 381 | * | |
| 382 | * @param allocator the allocator | |
| 383 | * @param n the number of bytes | |
| 384 | * @return a pointer to the allocated memory | |
| 385 | */ | |
| 38 | 386 | CX_EXTERN CX_NODISCARD CX_NONNULL |
| 387 | CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2) | |
| 388 | void *cxZalloc(const CxAllocator *allocator, size_t n); | |
| 21 | 389 | |
| 390 | /** | |
| 31 | 391 | * Allocate @p n bytes of memory. |
| 392 | * | |
| 21 | 393 | * Convenience macro that invokes cxMalloc() with the cxDefaultAllocator. |
| 31 | 394 | * |
| 395 | * @param n (@c size_t) the number of bytes | |
| 396 | * @return (@c void*) a pointer to the allocated memory | |
| 21 | 397 | */ |
| 31 | 398 | #define cxMallocDefault(n) cxMalloc(cxDefaultAllocator, n) |
| 399 | ||
| 21 | 400 | /** |
| 31 | 401 | * Allocate @p n bytes of memory and sets every byte to zero. |
| 402 | * | |
| 21 | 403 | * Convenience macro that invokes cxZalloc() with the cxDefaultAllocator. |
| 31 | 404 | * |
| 405 | * @param n (@c size_t) the number of bytes | |
| 406 | * @return (@c void*) a pointer to the allocated memory | |
| 21 | 407 | */ |
| 31 | 408 | #define cxZallocDefault(n) cxZalloc(cxDefaultAllocator, n) |
| 409 | ||
| 21 | 410 | /** |
| 31 | 411 | * Allocate @p nmemb elements of @p size bytes each, all initialized to zero. |
| 412 | * | |
| 21 | 413 | * Convenience macro that invokes cxCalloc() with the cxDefaultAllocator. |
| 31 | 414 | * |
| 415 | * @param nmemb (@c size_t) the number of elements | |
| 416 | * @param size (@c size_t) the size of each element in bytes | |
| 417 | * @return (@c void*) a pointer to the allocated memory | |
| 21 | 418 | */ |
| 31 | 419 | #define cxCallocDefault(nmemb, size) cxCalloc(cxDefaultAllocator, nmemb, size) |
| 420 | ||
| 21 | 421 | /** |
| 31 | 422 | * Reallocate the previously allocated block in @p mem. |
| 423 | * | |
| 424 | * This function may return the same pointer passed to it if moving | |
| 425 | * the memory was not necessary. | |
| 426 | * | |
| 21 | 427 | * Convenience macro that invokes cxRealloc() with the cxDefaultAllocator. |
| 31 | 428 | * |
| 429 | * @attention This function is bug-prone. Consider using cxReallocateDefault(). | |
| 430 | * | |
| 431 | * @param mem (@c void*) pointer to the previously allocated block | |
| 432 | * @param n (@c size_t) the new size in bytes | |
| 433 | * @return (@c void*) a pointer to the reallocated memory | |
| 21 | 434 | */ |
| 31 | 435 | #define cxReallocDefault(mem, n) cxRealloc(cxDefaultAllocator, mem, n) |
| 436 | ||
| 21 | 437 | /** |
| 31 | 438 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 439 | * if necessary. | |
| 440 | * This function acts like cxRealloc() using the pointer pointed to by @p mem. | |
| 441 | * | |
| 21 | 442 | * Convenience macro that invokes cxReallocate() with the cxDefaultAllocator. |
| 31 | 443 | * |
| 444 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 445 | * | |
| 446 | * @par Error handling | |
| 447 | * @c errno will be set if the underlying realloc function does so. | |
| 448 | * | |
| 449 | * @param mem (@c void**) pointer to the pointer to allocated block | |
| 450 | * @param n (@c size_t) the new size in bytes | |
| 451 | * @retval zero success | |
| 452 | * @retval non-zero failure | |
| 21 | 453 | */ |
| 31 | 454 | #define cxReallocateDefault(mem, n) cxReallocate(cxDefaultAllocator, mem, n) |
| 455 | ||
| 21 | 456 | /** |
| 31 | 457 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 458 | * if necessary. | |
| 459 | * This function acts like cxReallocArray() using the pointer pointed to | |
| 460 | * by @p mem. | |
| 461 | * | |
| 462 | * Convenience macro that invokes cxReallocateArray() with the cxDefaultAllocator. | |
| 463 | * | |
| 464 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 465 | * | |
| 466 | * @par Error handling | |
| 467 | * @c errno will be set, if the underlying realloc function does so or the | |
| 468 | * multiplication of @p nmemb and @p size overflows. | |
| 469 | * | |
| 470 | * @param mem (@c void**) pointer to the pointer to allocated block | |
| 471 | * @param nmemb (@c size_t) the number of elements | |
| 472 | * @param size (@c size_t) the size of each element | |
| 473 | * @retval zero success | |
| 474 | * @retval non-zero failure | |
| 21 | 475 | */ |
| 31 | 476 | #define cxReallocateArrayDefault(mem, nmemb, size) \ |
| 477 | cxReallocateArray(cxDefaultAllocator, mem, nmemb, size) | |
| 478 | ||
| 21 | 479 | /** |
| 31 | 480 | * Reallocate the previously allocated block in @p mem. |
| 481 | * | |
| 482 | * Convenience macro that invokes cxReallocArray() with the cxDefaultAllocator. | |
| 483 | * | |
| 484 | * This function may return the same pointer passed to it if moving | |
| 485 | * the memory was not necessary. | |
| 486 | * | |
| 487 | * The size is calculated by multiplying @p nemb and @p size. | |
| 488 | * If that multiplication overflows, this function returns @c NULL, and @c errno | |
| 489 | * will be set. | |
| 490 | * | |
| 491 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 492 | * | |
| 493 | * @attention This function is bug-prone. Consider using cxReallocateArrayDefault(). | |
| 494 | * | |
| 495 | * @param mem (@c void*) pointer to the previously allocated block | |
| 496 | * @param nmemb (@c size_t) the number of elements | |
| 497 | * @param size (@c size_t) the size of each element | |
| 498 | * @return (@c void*) a pointer to the reallocated memory | |
| 499 | */ | |
| 500 | #define cxReallocArrayDefault(mem, nmemb, size) cxReallocArray(cxDefaultAllocator, mem, nmemb, size) | |
| 501 | ||
| 502 | /** | |
| 503 | * Free a block of memory. | |
| 504 | * | |
| 30 | 505 | * Convenience function that invokes cxFree() with the cxDefaultAllocator. |
| 31 | 506 | * |
| 507 | * @param mem the memory to deallocate | |
| 21 | 508 | */ |
| 38 | 509 | CX_EXTERN |
| 510 | void cxFreeDefault(void *mem); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | #endif // UCX_ALLOCATOR_H |