Sun, 07 Dec 2025 19:20:48 +0100
implement radiobutton (Client)
| 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 | ||
| 29 | #include "cx/allocator.h" | |
| 30 | ||
| 440 | 31 | #include <errno.h> |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
32 | #include <string.h> |
| 440 | 33 | |
| 174 | 34 | static void *cx_malloc_stdlib( |
| 440 | 35 | cx_attr_unused void *d, |
| 174 | 36 | size_t n |
| 37 | ) { | |
| 38 | return malloc(n); | |
| 39 | } | |
| 40 | ||
| 41 | static void *cx_realloc_stdlib( | |
| 440 | 42 | cx_attr_unused void *d, |
| 174 | 43 | void *mem, |
| 44 | size_t n | |
| 45 | ) { | |
| 46 | return realloc(mem, n); | |
| 47 | } | |
| 48 | ||
| 49 | static void *cx_calloc_stdlib( | |
| 440 | 50 | cx_attr_unused void *d, |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
51 | 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
|
52 | size_t size |
| 174 | 53 | ) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
54 | return calloc(nmemb, size); |
| 174 | 55 | } |
| 56 | ||
| 57 | static void cx_free_stdlib( | |
| 440 | 58 | cx_attr_unused void *d, |
| 174 | 59 | void *mem |
| 60 | ) { | |
| 61 | free(mem); | |
| 62 | } | |
| 63 | ||
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
64 | static cx_allocator_class cx_stdlib_allocator_class = { |
| 174 | 65 | cx_malloc_stdlib, |
| 66 | cx_realloc_stdlib, | |
| 67 | cx_calloc_stdlib, | |
| 68 | cx_free_stdlib | |
| 69 | }; | |
| 70 | ||
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
71 | struct cx_allocator_s cx_stdlib_allocator = { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
72 | &cx_stdlib_allocator_class, |
| 174 | 73 | NULL |
| 74 | }; | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
75 | const CxAllocator * const cxStdlibAllocator = &cx_stdlib_allocator; |
| 845 | 76 | const CxAllocator * cxDefaultAllocator = &cx_stdlib_allocator; |
| 174 | 77 | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
78 | int cx_reallocate_( |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
79 | void **mem, |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
80 | size_t n |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
81 | ) { |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
82 | void *nmem = realloc(*mem, n); |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
83 | if (nmem == NULL) { |
| 440 | 84 | return 1; // LCOV_EXCL_LINE |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
85 | } else { |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
86 | *mem = nmem; |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
87 | return 0; |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
88 | } |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
89 | } |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
90 | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
91 | int cx_reallocatearray_( |
| 440 | 92 | void **mem, |
| 93 | size_t nmemb, | |
| 94 | size_t size | |
| 95 | ) { | |
| 96 | size_t n; | |
| 97 | if (cx_szmul(nmemb, size, &n)) { | |
| 98 | errno = EOVERFLOW; | |
| 99 | return 1; | |
| 100 | } else { | |
| 101 | void *nmem = realloc(*mem, n); | |
| 102 | if (nmem == NULL) { | |
| 103 | return 1; // LCOV_EXCL_LINE | |
| 104 | } else { | |
| 105 | *mem = nmem; | |
| 106 | return 0; | |
| 107 | } | |
| 108 | } | |
| 109 | } | |
| 110 | ||
| 174 | 111 | // IMPLEMENTATION OF HIGH LEVEL API |
| 112 | ||
| 113 | void *cxMalloc( | |
| 324 | 114 | const CxAllocator *allocator, |
| 174 | 115 | size_t n |
| 116 | ) { | |
| 117 | return allocator->cl->malloc(allocator->data, n); | |
| 118 | } | |
| 119 | ||
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
120 | void *cxZalloc( |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
121 | const CxAllocator *allocator, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
122 | size_t n |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
123 | ) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
124 | void *mem = allocator->cl->malloc(allocator->data, n); |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
125 | if (mem != NULL) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
126 | memset(mem, 0, n); |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
127 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
128 | return mem; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
129 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
130 | |
| 174 | 131 | void *cxRealloc( |
| 324 | 132 | const CxAllocator *allocator, |
| 174 | 133 | void *mem, |
| 134 | size_t n | |
| 135 | ) { | |
| 136 | return allocator->cl->realloc(allocator->data, mem, n); | |
| 137 | } | |
| 138 | ||
| 440 | 139 | void *cxReallocArray( |
| 140 | const CxAllocator *allocator, | |
| 141 | void *mem, | |
| 142 | size_t nmemb, | |
| 143 | size_t size | |
| 144 | ) { | |
| 145 | size_t n; | |
| 146 | if (cx_szmul(nmemb, size, &n)) { | |
| 147 | errno = EOVERFLOW; | |
| 148 | return NULL; | |
| 149 | } else { | |
| 150 | return allocator->cl->realloc(allocator->data, mem, n); | |
| 151 | } | |
| 152 | } | |
| 153 | ||
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
154 | int cxReallocate_( |
| 324 | 155 | const CxAllocator *allocator, |
| 174 | 156 | void **mem, |
| 157 | size_t n | |
| 158 | ) { | |
| 159 | void *nmem = allocator->cl->realloc(allocator->data, *mem, n); | |
| 160 | if (nmem == NULL) { | |
| 440 | 161 | return 1; // LCOV_EXCL_LINE |
| 162 | } else { | |
| 163 | *mem = nmem; | |
| 164 | return 0; | |
| 165 | } | |
| 166 | } | |
| 167 | ||
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
168 | int cxReallocateArray_( |
| 440 | 169 | const CxAllocator *allocator, |
| 170 | void **mem, | |
| 171 | size_t nmemb, | |
| 172 | size_t size | |
| 173 | ) { | |
| 174 | void *nmem = cxReallocArray(allocator, *mem, nmemb, size); | |
| 175 | if (nmem == NULL) { | |
| 176 | return 1; // LCOV_EXCL_LINE | |
| 174 | 177 | } else { |
| 178 | *mem = nmem; | |
| 179 | return 0; | |
| 180 | } | |
| 181 | } | |
| 182 | ||
| 183 | void *cxCalloc( | |
| 324 | 184 | 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
|
185 | 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
|
186 | size_t size |
| 174 | 187 | ) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
188 | return allocator->cl->calloc(allocator->data, nmemb, size); |
| 174 | 189 | } |
| 190 | ||
| 191 | void cxFree( | |
| 324 | 192 | const CxAllocator *allocator, |
| 174 | 193 | void *mem |
| 194 | ) { | |
| 195 | allocator->cl->free(allocator->data, mem); | |
| 196 | } |