Fri, 25 Apr 2025 22:04:30 +0200
implement more table column types (QT)
| 174 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | /** | |
| 440 | 29 | * @file allocator.h |
| 174 | 30 | * Interface for custom allocators. |
| 31 | */ | |
| 32 | ||
| 33 | #ifndef UCX_ALLOCATOR_H | |
| 34 | #define UCX_ALLOCATOR_H | |
| 35 | ||
| 36 | #include "common.h" | |
| 37 | ||
| 38 | #ifdef __cplusplus | |
| 39 | extern "C" { | |
| 40 | #endif | |
| 41 | ||
| 42 | /** | |
| 43 | * The class definition for an allocator. | |
| 44 | */ | |
| 45 | typedef struct { | |
| 46 | /** | |
| 47 | * The allocator's malloc() implementation. | |
| 48 | */ | |
| 49 | void *(*malloc)( | |
| 50 | void *data, | |
| 51 | size_t n | |
| 52 | ); | |
| 53 | ||
| 54 | /** | |
| 55 | * The allocator's realloc() implementation. | |
| 56 | */ | |
| 57 | void *(*realloc)( | |
| 58 | void *data, | |
| 59 | void *mem, | |
| 60 | size_t n | |
| 324 | 61 | ); |
| 174 | 62 | |
| 63 | /** | |
| 64 | * The allocator's calloc() implementation. | |
| 65 | */ | |
| 66 | void *(*calloc)( | |
| 67 | void *data, | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
68 | size_t nmemb, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
69 | size_t size |
| 174 | 70 | ); |
| 71 | ||
| 72 | /** | |
| 73 | * The allocator's free() implementation. | |
| 74 | */ | |
| 75 | void (*free)( | |
| 76 | void *data, | |
| 77 | void *mem | |
| 324 | 78 | ); |
| 174 | 79 | } cx_allocator_class; |
| 80 | ||
| 81 | /** | |
| 82 | * Structure holding the data for an allocator. | |
| 83 | */ | |
| 84 | struct cx_allocator_s { | |
| 85 | /** | |
| 86 | * A pointer to the instance of the allocator class. | |
| 87 | */ | |
| 88 | cx_allocator_class *cl; | |
| 89 | /** | |
| 90 | * A pointer to the data this allocator uses. | |
| 91 | */ | |
| 92 | void *data; | |
| 93 | }; | |
| 94 | ||
| 95 | /** | |
| 96 | * High-Level type alias for the allocator type. | |
| 97 | */ | |
| 98 | typedef struct cx_allocator_s CxAllocator; | |
| 99 | ||
| 100 | /** | |
| 101 | * A default allocator using standard library malloc() etc. | |
| 102 | */ | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
103 | cx_attr_export |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
104 | extern const CxAllocator * const cxDefaultAllocator; |
| 174 | 105 | |
| 106 | /** | |
| 107 | * Function pointer type for destructor functions. | |
| 108 | * | |
| 109 | * A destructor function deallocates possible contents and MAY free the memory | |
| 440 | 110 | * pointed to by @p memory. Read the documentation of the respective function |
| 111 | * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in | |
| 112 | * that particular implementation. | |
| 174 | 113 | * |
| 114 | * @param memory a pointer to the object to destruct | |
| 115 | */ | |
| 324 | 116 | typedef void (*cx_destructor_func)(void *memory); |
| 174 | 117 | |
| 118 | /** | |
| 119 | * Function pointer type for destructor functions. | |
| 120 | * | |
| 121 | * A destructor function deallocates possible contents and MAY free the memory | |
| 440 | 122 | * pointed to by @p memory. Read the documentation of the respective function |
| 123 | * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in | |
| 124 | * that particular implementation. | |
| 174 | 125 | * |
| 126 | * @param data an optional pointer to custom data | |
| 127 | * @param memory a pointer to the object to destruct | |
| 128 | */ | |
| 129 | typedef void (*cx_destructor_func2)( | |
| 130 | void *data, | |
| 131 | void *memory | |
| 324 | 132 | ); |
| 174 | 133 | |
| 134 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
135 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 440 | 136 | * if necessary. |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
137 | * |
| 440 | 138 | * @par Error handling |
| 139 | * @c errno will be set by realloc() on failure. | |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
140 | * |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
141 | * @param mem pointer to the pointer to allocated block |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
142 | * @param n the new size in bytes |
| 440 | 143 | * @retval zero success |
| 144 | * @retval non-zero failure | |
| 145 | * @see cx_reallocatearray() | |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
146 | */ |
| 440 | 147 | cx_attr_nonnull |
| 148 | cx_attr_nodiscard | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
149 | cx_attr_export |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
150 | int cx_reallocate_( |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
151 | void **mem, |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
152 | size_t n |
| 324 | 153 | ); |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
154 | |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
155 | /** |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
156 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 440 | 157 | * if necessary. |
| 158 | * | |
| 159 | * The size is calculated by multiplying @p nemb and @p size. | |
| 160 | * | |
| 161 | * @par Error handling | |
| 162 | * @c errno will be set by realloc() on failure or when the multiplication of | |
| 163 | * @p nmemb and @p size overflows. | |
| 164 | * | |
| 165 | * @param mem pointer to the pointer to allocated block | |
| 166 | * @param nmemb the number of elements | |
| 167 | * @param size the size of each element | |
| 168 | * @retval zero success | |
| 169 | * @retval non-zero failure | |
| 170 | * @see cx_reallocate() | |
| 171 | */ | |
| 172 | cx_attr_nonnull | |
| 173 | cx_attr_nodiscard | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
174 | cx_attr_export |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
175 | int cx_reallocatearray_( |
| 440 | 176 | void **mem, |
| 177 | size_t nmemb, | |
| 178 | size_t size | |
| 179 | ); | |
| 180 | ||
| 181 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
182 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 440 | 183 | * if necessary. |
| 184 | * | |
| 185 | * @par Error handling | |
| 186 | * @c errno will be set by realloc() on failure. | |
| 187 | * | |
| 188 | * @param mem (@c void**) pointer to the pointer to allocated block | |
| 189 | * @param n (@c size_t) the new size in bytes | |
| 190 | * @retval zero success | |
| 191 | * @retval non-zero failure | |
| 192 | * @see cx_reallocatearray() | |
| 193 | */ | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
194 | #define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n) |
| 440 | 195 | |
| 196 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
197 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 440 | 198 | * if necessary. |
| 199 | * | |
| 200 | * The size is calculated by multiplying @p nemb and @p size. | |
| 201 | * | |
| 202 | * @par Error handling | |
| 203 | * @c errno will be set by realloc() on failure or when the multiplication of | |
| 204 | * @p nmemb and @p size overflows. | |
| 205 | * | |
| 206 | * @param mem (@c void**) pointer to the pointer to allocated block | |
| 207 | * @param nmemb (@c size_t) the number of elements | |
| 208 | * @param size (@c size_t) the size of each element | |
| 209 | * @retval zero success | |
| 210 | * @retval non-zero failure | |
| 211 | */ | |
| 212 | #define cx_reallocatearray(mem, nmemb, size) \ | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
213 | cx_reallocatearray_((void**)(mem), nmemb, size) |
| 440 | 214 | |
| 215 | /** | |
| 216 | * Free a block allocated by this allocator. | |
| 217 | * | |
| 218 | * @note Freeing a block of a different allocator is undefined. | |
| 219 | * | |
| 220 | * @param allocator the allocator | |
| 221 | * @param mem a pointer to the block to free | |
| 222 | */ | |
| 223 | cx_attr_nonnull_arg(1) | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
224 | cx_attr_export |
| 440 | 225 | void cxFree( |
| 226 | const CxAllocator *allocator, | |
| 227 | void *mem | |
| 228 | ); | |
| 229 | ||
| 230 | /** | |
| 231 | * Allocate @p n bytes of memory. | |
| 174 | 232 | * |
| 233 | * @param allocator the allocator | |
| 234 | * @param n the number of bytes | |
| 235 | * @return a pointer to the allocated memory | |
| 236 | */ | |
| 440 | 237 | cx_attr_nodiscard |
| 238 | cx_attr_nonnull | |
| 239 | cx_attr_malloc | |
| 240 | cx_attr_dealloc_ucx | |
| 241 | cx_attr_allocsize(2) | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
242 | cx_attr_export |
| 174 | 243 | void *cxMalloc( |
| 324 | 244 | const CxAllocator *allocator, |
| 174 | 245 | size_t n |
| 324 | 246 | ); |
| 174 | 247 | |
| 248 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
249 | * Reallocate the previously allocated block in @p mem, making the new block |
| 440 | 250 | * @p n bytes long. |
| 251 | * This function may return the same pointer that was passed to it, if moving | |
| 252 | * the memory was not necessary. | |
| 174 | 253 | * |
| 440 | 254 | * @note Re-allocating a block allocated by a different allocator is undefined. |
| 174 | 255 | * |
| 256 | * @param allocator the allocator | |
| 257 | * @param mem pointer to the previously allocated block | |
| 258 | * @param n the new size in bytes | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
259 | * @return a pointer to the reallocated memory |
| 174 | 260 | */ |
| 440 | 261 | cx_attr_nodiscard |
| 262 | cx_attr_nonnull_arg(1) | |
| 263 | cx_attr_dealloc_ucx | |
| 264 | cx_attr_allocsize(3) | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
265 | cx_attr_export |
| 174 | 266 | void *cxRealloc( |
| 324 | 267 | const CxAllocator *allocator, |
| 174 | 268 | void *mem, |
| 269 | size_t n | |
| 324 | 270 | ); |
| 174 | 271 | |
| 272 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
273 | * Reallocate the previously allocated block in @p mem, making the new block |
| 440 | 274 | * @p n bytes long. |
| 275 | * This function may return the same pointer that was passed to it, if moving | |
| 276 | * the memory was not necessary. | |
| 277 | * | |
| 278 | * The size is calculated by multiplying @p nemb and @p size. | |
| 279 | * If that multiplication overflows, this function returns @c NULL and @c errno | |
| 280 | * will be set. | |
| 281 | * | |
| 282 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 174 | 283 | * |
| 440 | 284 | * @param allocator the allocator |
| 285 | * @param mem pointer to the previously allocated block | |
| 286 | * @param nmemb the number of elements | |
| 287 | * @param size the size of each element | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
288 | * @return a pointer to the reallocated memory |
| 440 | 289 | */ |
| 290 | cx_attr_nodiscard | |
| 291 | cx_attr_nonnull_arg(1) | |
| 292 | cx_attr_dealloc_ucx | |
| 293 | cx_attr_allocsize(3, 4) | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
294 | cx_attr_export |
| 440 | 295 | void *cxReallocArray( |
| 296 | const CxAllocator *allocator, | |
| 297 | void *mem, | |
| 298 | size_t nmemb, | |
| 299 | size_t size | |
| 300 | ); | |
| 301 | ||
| 302 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
303 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 440 | 304 | * if necessary. |
| 305 | * This function acts like cxRealloc() using the pointer pointed to by @p mem. | |
| 174 | 306 | * |
| 440 | 307 | * @note Re-allocating a block allocated by a different allocator is undefined. |
| 308 | * | |
| 309 | * @par Error handling | |
| 310 | * @c errno will be set, if the underlying realloc function does so. | |
| 174 | 311 | * |
| 312 | * @param allocator the allocator | |
| 313 | * @param mem pointer to the pointer to allocated block | |
| 314 | * @param n the new size in bytes | |
| 440 | 315 | * @retval zero success |
| 316 | * @retval non-zero failure | |
| 174 | 317 | */ |
| 440 | 318 | cx_attr_nodiscard |
| 319 | cx_attr_nonnull | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
320 | cx_attr_export |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
321 | int cxReallocate_( |
| 324 | 322 | const CxAllocator *allocator, |
| 174 | 323 | void **mem, |
| 324 | size_t n | |
| 324 | 325 | ); |
| 174 | 326 | |
| 327 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
328 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 440 | 329 | * if necessary. |
| 330 | * This function acts like cxRealloc() using the pointer pointed to by @p mem. | |
| 331 | * | |
| 332 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 333 | * | |
| 334 | * @par Error handling | |
| 335 | * @c errno will be set, if the underlying realloc function does so. | |
| 336 | * | |
| 337 | * @param allocator (@c CxAllocator*) the allocator | |
| 338 | * @param mem (@c void**) pointer to the pointer to allocated block | |
| 339 | * @param n (@c size_t) the new size in bytes | |
| 340 | * @retval zero success | |
| 341 | * @retval non-zero failure | |
| 342 | */ | |
| 343 | #define cxReallocate(allocator, mem, n) \ | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
344 | cxReallocate_(allocator, (void**)(mem), n) |
| 440 | 345 | |
| 346 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
347 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 440 | 348 | * if necessary. |
| 349 | * This function acts like cxReallocArray() using the pointer pointed to | |
| 350 | * by @p mem. | |
| 351 | * | |
| 352 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 353 | * | |
| 354 | * @par Error handling | |
| 355 | * @c errno will be set, if the underlying realloc function does so or the | |
| 356 | * multiplication of @p nmemb and @p size overflows. | |
| 357 | * | |
| 358 | * @param allocator the allocator | |
| 359 | * @param mem pointer to the pointer to allocated block | |
| 360 | * @param nmemb the number of elements | |
| 361 | * @param size the size of each element | |
| 362 | * @retval zero success | |
| 363 | * @retval non-zero on failure | |
| 364 | */ | |
| 365 | cx_attr_nodiscard | |
| 366 | cx_attr_nonnull | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
367 | cx_attr_export |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
368 | int cxReallocateArray_( |
| 440 | 369 | const CxAllocator *allocator, |
| 370 | void **mem, | |
| 371 | size_t nmemb, | |
| 372 | size_t size | |
| 373 | ); | |
| 374 | ||
| 375 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
376 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 440 | 377 | * if necessary. |
| 378 | * This function acts like cxReallocArray() using the pointer pointed to | |
| 379 | * by @p mem. | |
| 380 | * | |
| 381 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 382 | * | |
| 383 | * @par Error handling | |
| 384 | * @c errno will be set, if the underlying realloc function does so or the | |
| 385 | * multiplication of @p nmemb and @p size overflows. | |
| 386 | * | |
| 387 | * @param allocator (@c CxAllocator*) the allocator | |
| 388 | * @param mem (@c void**) pointer to the pointer to allocated block | |
| 389 | * @param nmemb (@c size_t) the number of elements | |
| 390 | * @param size (@c size_t) the size of each element | |
| 391 | * @retval zero success | |
| 392 | * @retval non-zero failure | |
| 393 | */ | |
| 394 | #define cxReallocateArray(allocator, mem, nmemb, size) \ | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
395 | cxReallocateArray_(allocator, (void**) (mem), nmemb, size) |
| 440 | 396 | |
| 397 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
398 | * Allocate @p nmemb elements of @p n bytes each, all initialized to zero. |
| 174 | 399 | * |
| 400 | * @param allocator the allocator | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
401 | * @param nmemb the number of elements |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
402 | * @param size the size of each element in bytes |
| 174 | 403 | * @return a pointer to the allocated memory |
| 404 | */ | |
| 440 | 405 | cx_attr_nonnull_arg(1) |
| 406 | cx_attr_nodiscard | |
| 407 | cx_attr_malloc | |
| 408 | cx_attr_dealloc_ucx | |
| 409 | cx_attr_allocsize(2, 3) | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
410 | cx_attr_export |
| 174 | 411 | void *cxCalloc( |
| 324 | 412 | const CxAllocator *allocator, |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
413 | size_t nmemb, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
414 | size_t size |
| 324 | 415 | ); |
| 174 | 416 | |
| 417 | #ifdef __cplusplus | |
| 418 | } // extern "C" | |
| 419 | #endif | |
| 420 | ||
| 421 | #endif // UCX_ALLOCATOR_H |