Wed, 31 Dec 2025 16:41:16 +0100
update ucx to version 4.0
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
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 |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 852 | 29 | * @file allocator.h |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | * Interface for custom allocators. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #ifndef UCX_ALLOCATOR_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #define UCX_ALLOCATOR_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "common.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | * The class definition for an allocator. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | typedef struct { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | * The allocator's malloc() implementation. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | */ |
| 889 | 45 | void *(*malloc)(void *data, size_t n); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | * The allocator's realloc() implementation. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | */ |
| 889 | 50 | void *(*realloc)(void *data, void *mem, size_t n); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | * The allocator's calloc() implementation. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | */ |
| 889 | 55 | void *(*calloc)(void *data, size_t nmemb, size_t size); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | * The allocator's free() implementation. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | */ |
| 889 | 60 | void (*free)(void *data, void *mem); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | } cx_allocator_class; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | * Structure holding the data for an allocator. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | struct cx_allocator_s { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | * A pointer to the instance of the allocator class. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | cx_allocator_class *cl; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | * A pointer to the data this allocator uses. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | void *data; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | }; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | * High-Level type alias for the allocator type. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | typedef struct cx_allocator_s CxAllocator; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | /** |
| 886 | 83 | * A pre-defined allocator using standard library malloc() etc. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | */ |
| 889 | 85 | CX_EXPORT extern const CxAllocator * const cxStdlibAllocator; |
| 886 | 86 | |
| 87 | /** | |
| 88 | * The default allocator that is used by UCX. | |
| 89 | * Initialized with cxStdlibAllocator, but you may change it. | |
| 90 | */ | |
| 889 | 91 | CX_EXPORT extern const CxAllocator * cxDefaultAllocator; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | * Function pointer type for destructor functions. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | * A destructor function deallocates possible contents and MAY free the memory |
| 852 | 97 | * pointed to by @p memory. Read the documentation of the respective function |
| 98 | * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in | |
| 99 | * that particular implementation. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | * @param memory a pointer to the object to destruct |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | */ |
| 852 | 103 | typedef void (*cx_destructor_func)(void *memory); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | * Function pointer type for destructor functions. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | * A destructor function deallocates possible contents and MAY free the memory |
| 852 | 109 | * pointed to by @p memory. Read the documentation of the respective function |
| 110 | * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in | |
| 111 | * that particular implementation. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | * @param data an optional pointer to custom data |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | * @param memory a pointer to the object to destruct |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | */ |
| 889 | 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 | */ | |
| 891 | 141 | typedef void*(*cx_clone_func)(void *target, const void *source, |
| 889 | 142 | const CxAllocator *allocator, void *data); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | /** |
| 891 | 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. | |
| 775 | 149 | * |
| 891 | 150 | * @return the system's memory page size in bytes |
| 151 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
152 | CX_EXTERN CX_NODISCARD |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
153 | unsigned long cx_system_page_size(void); |
| 891 | 154 | |
| 155 | /** | |
| 156 | * Reallocate a previously allocated block. | |
| 886 | 157 | * |
| 891 | 158 | * Internal function - do not use. |
| 775 | 159 | * |
| 160 | * @param mem pointer to the pointer to allocated block | |
| 161 | * @param n the new size in bytes | |
| 852 | 162 | * @retval zero success |
| 163 | * @retval non-zero failure | |
| 164 | * @see cx_reallocatearray() | |
| 775 | 165 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
166 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
167 | int cx_reallocate_(void **mem, size_t n); |
| 852 | 168 | |
| 169 | /** | |
| 891 | 170 | * Reallocate a previously allocated block. |
| 852 | 171 | * |
| 891 | 172 | * Internal function - do not use. |
| 852 | 173 | * |
| 174 | * @param mem pointer to the pointer to allocated block | |
| 175 | * @param nmemb the number of elements | |
| 176 | * @param size the size of each element | |
| 177 | * @retval zero success | |
| 178 | * @retval non-zero failure | |
| 179 | * @see cx_reallocate() | |
| 180 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
181 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
182 | int cx_reallocatearray_(void **mem, size_t nmemb, size_t size); |
| 775 | 183 | |
| 184 | /** | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
185 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 852 | 186 | * if necessary. |
| 187 | * | |
| 886 | 188 | * @note This will use stdlib reallocate and @em not the cxDefaultAllocator. |
| 189 | * | |
| 852 | 190 | * @par Error handling |
| 191 | * @c errno will be set by realloc() on failure. | |
| 192 | * | |
| 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() | |
| 198 | */ | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
199 | #define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n) |
| 852 | 200 | |
| 201 | /** | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
202 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 852 | 203 | * if necessary. |
| 204 | * | |
| 205 | * The size is calculated by multiplying @p nemb and @p size. | |
| 206 | * | |
| 886 | 207 | * @note This will use stdlib reallocate and @em not the cxDefaultAllocator. |
| 208 | * | |
| 852 | 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. | |
| 212 | * | |
| 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 | |
| 218 | */ | |
| 219 | #define cx_reallocatearray(mem, nmemb, size) \ | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
220 | cx_reallocatearray_((void**)(mem), nmemb, size) |
| 852 | 221 | |
| 222 | /** | |
| 886 | 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 | /** | |
| 852 | 231 | * Free a block allocated by this allocator. |
| 232 | * | |
| 233 | * @note Freeing a block of a different allocator is undefined. | |
| 234 | * | |
| 235 | * @param allocator the allocator | |
| 236 | * @param mem a pointer to the block to free | |
| 237 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
238 | CX_EXTERN CX_NONNULL_ARG(1) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
239 | void cxFree(const CxAllocator *allocator, void *mem); |
| 852 | 240 | |
| 241 | /** | |
| 242 | * Allocate @p n bytes of memory. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | * @param allocator the allocator |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | * @param n the number of bytes |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | * @return a pointer to the allocated memory |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
248 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
249 | CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
250 | void *cxMalloc(const CxAllocator *allocator, size_t n); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | /** |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
253 | * Reallocate the previously allocated block in @p mem, making the new block |
| 852 | 254 | * @p n bytes long. |
| 889 | 255 | * This function may return the same pointer passed to it if moving |
| 852 | 256 | * the memory was not necessary. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | * |
| 852 | 258 | * @note Re-allocating a block allocated by a different allocator is undefined. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | * |
| 891 | 260 | * @attention This function is bug-prone. Consider using cxReallocate(). |
| 261 | * | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | * @param allocator the allocator |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | * @param mem pointer to the previously allocated block |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | * @param n the new size in bytes |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
265 | * @return a pointer to the reallocated memory |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
267 | CX_EXTERN CX_NODISCARD CX_NONNULL_ARG(1) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
268 | CX_DEALLOC_UCX CX_ALLOCSIZE(3) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
269 | void *cxRealloc(const CxAllocator *allocator, void *mem, size_t n); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | /** |
| 891 | 272 | * Reallocate the previously allocated block in @p mem. |
| 273 | * | |
| 889 | 274 | * This function may return the same pointer passed to it if moving |
| 852 | 275 | * the memory was not necessary. |
| 276 | * | |
| 277 | * The size is calculated by multiplying @p nemb and @p size. | |
| 889 | 278 | * If that multiplication overflows, this function returns @c NULL, and @c errno |
| 852 | 279 | * will be set. |
| 280 | * | |
| 281 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | * |
| 891 | 283 | * @attention This function is bug-prone. Consider using cxReallocateArray(). |
| 284 | * | |
| 852 | 285 | * @param allocator the allocator |
| 286 | * @param mem pointer to the previously allocated block | |
| 287 | * @param nmemb the number of elements | |
| 288 | * @param size the size of each element | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
289 | * @return a pointer to the reallocated memory |
| 852 | 290 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
291 | CX_EXTERN CX_NODISCARD CX_NONNULL_ARG(1) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
292 | CX_DEALLOC_UCX CX_ALLOCSIZE(3, 4) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
293 | void *cxReallocArray(const CxAllocator *allocator, |
| 889 | 294 | void *mem, size_t nmemb, size_t size); |
| 852 | 295 | |
| 296 | /** | |
| 891 | 297 | * Reallocate a previously allocated block. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | * |
| 891 | 299 | * Internal function - do not use. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | * @param allocator the allocator |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | * @param mem pointer to the pointer to allocated block |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | * @param n the new size in bytes |
| 852 | 304 | * @retval zero success |
| 305 | * @retval non-zero failure | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
307 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
308 | int cxReallocate_(const CxAllocator *allocator, void **mem, size_t n); |
| 852 | 309 | |
| 310 | /** | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
311 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 852 | 312 | * if necessary. |
| 313 | * This function acts like cxRealloc() using the pointer pointed to by @p mem. | |
| 314 | * | |
| 315 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 316 | * | |
| 317 | * @par Error handling | |
| 889 | 318 | * @c errno will be set if the underlying realloc function does so. |
| 852 | 319 | * |
| 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 | |
| 325 | */ | |
| 326 | #define cxReallocate(allocator, mem, n) \ | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
327 | cxReallocate_(allocator, (void**)(mem), n) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | /** |
| 891 | 330 | * Reallocate a previously allocated block. |
| 852 | 331 | * |
| 891 | 332 | * Internal function - do not use. |
| 852 | 333 | * |
| 334 | * @param allocator the allocator | |
| 335 | * @param mem pointer to the pointer to allocated block | |
| 336 | * @param nmemb the number of elements | |
| 337 | * @param size the size of each element | |
| 338 | * @retval zero success | |
| 339 | * @retval non-zero on failure | |
| 340 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
341 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
342 | int cxReallocateArray_(const CxAllocator *allocator, |
| 889 | 343 | void **mem, size_t nmemb, size_t size); |
| 852 | 344 | |
| 345 | /** | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
346 | * Reallocate a previously allocated block and changes the pointer in-place, |
| 852 | 347 | * if necessary. |
| 348 | * This function acts like cxReallocArray() using the pointer pointed to | |
| 349 | * by @p mem. | |
| 350 | * | |
| 351 | * @note Re-allocating a block allocated by a different allocator is undefined. | |
| 352 | * | |
| 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. | |
| 356 | * | |
| 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) \ | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
365 | cxReallocateArray_(allocator, (void**) (mem), nmemb, size) |
| 852 | 366 | |
| 367 | /** | |
| 891 | 368 | * Allocate @p nmemb elements of @p size bytes each, all initialized to zero. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | * @param allocator the allocator |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
371 | * @param nmemb the number of elements |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
372 | * @param size the size of each element in bytes |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | * @return a pointer to the allocated memory |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
375 | CX_EXTERN CX_NONNULL_ARG(1) CX_NODISCARD |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
376 | CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2, 3) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
377 | void *cxCalloc(const CxAllocator *allocator, size_t nmemb, size_t size); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | |
| 886 | 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 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
386 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
387 | CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
388 | void *cxZalloc(const CxAllocator *allocator, size_t n); |
| 886 | 389 | |
| 390 | /** | |
| 891 | 391 | * Allocate @p n bytes of memory. |
| 392 | * | |
| 886 | 393 | * Convenience macro that invokes cxMalloc() with the cxDefaultAllocator. |
| 891 | 394 | * |
| 395 | * @param n (@c size_t) the number of bytes | |
| 396 | * @return (@c void*) a pointer to the allocated memory | |
| 886 | 397 | */ |
| 891 | 398 | #define cxMallocDefault(n) cxMalloc(cxDefaultAllocator, n) |
| 399 | ||
| 886 | 400 | /** |
| 891 | 401 | * Allocate @p n bytes of memory and sets every byte to zero. |
| 402 | * | |
| 886 | 403 | * Convenience macro that invokes cxZalloc() with the cxDefaultAllocator. |
| 891 | 404 | * |
| 405 | * @param n (@c size_t) the number of bytes | |
| 406 | * @return (@c void*) a pointer to the allocated memory | |
| 886 | 407 | */ |
| 891 | 408 | #define cxZallocDefault(n) cxZalloc(cxDefaultAllocator, n) |
| 409 | ||
| 886 | 410 | /** |
| 891 | 411 | * Allocate @p nmemb elements of @p size bytes each, all initialized to zero. |
| 412 | * | |
| 886 | 413 | * Convenience macro that invokes cxCalloc() with the cxDefaultAllocator. |
| 891 | 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 | |
| 886 | 418 | */ |
| 891 | 419 | #define cxCallocDefault(nmemb, size) cxCalloc(cxDefaultAllocator, nmemb, size) |
| 420 | ||
| 886 | 421 | /** |
| 891 | 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 | * | |
| 886 | 427 | * Convenience macro that invokes cxRealloc() with the cxDefaultAllocator. |
| 891 | 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 | |
| 886 | 434 | */ |
| 891 | 435 | #define cxReallocDefault(mem, n) cxRealloc(cxDefaultAllocator, mem, n) |
| 436 | ||
| 886 | 437 | /** |
| 891 | 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 | * | |
| 886 | 442 | * Convenience macro that invokes cxReallocate() with the cxDefaultAllocator. |
| 891 | 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 | |
| 886 | 453 | */ |
| 891 | 454 | #define cxReallocateDefault(mem, n) cxReallocate(cxDefaultAllocator, mem, n) |
| 455 | ||
| 886 | 456 | /** |
| 891 | 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 | |
| 886 | 475 | */ |
| 891 | 476 | #define cxReallocateArrayDefault(mem, nmemb, size) \ |
| 477 | cxReallocateArray(cxDefaultAllocator, mem, nmemb, size) | |
| 478 | ||
| 886 | 479 | /** |
| 891 | 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 | |
| 886 | 499 | */ |
| 891 | 500 | #define cxReallocArrayDefault(mem, nmemb, size) cxReallocArray(cxDefaultAllocator, mem, nmemb, size) |
| 501 | ||
| 502 | /** | |
| 503 | * Free a block of memory. | |
| 504 | * | |
| 505 | * Convenience function that invokes cxFree() with the cxDefaultAllocator. | |
| 506 | * | |
| 507 | * @param mem the memory to deallocate | |
| 508 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
509 | CX_EXTERN |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
510 | void cxFreeDefault(void *mem); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | #endif // UCX_ALLOCATOR_H |