| 1170 | } |
| 1171 | |
| 1172 | void das_array_clear ( das_context * context, das_array * arr, uint32_t stride ) { |
| 1173 | auto * a = (Array *)arr; |
| 1174 | if ( a->isLocked() ) { |
| 1175 | ((Context *)context)->throw_error("can't clear locked array"); |
| 1176 | return; |
| 1177 | } |
| 1178 | if ( a->data ) { |
| 1179 | // capacity*stride is the byte size to free. capacity>0 is a runtime |
| 1180 | // invariant when data!=null, so the only way to reach a zero free size |
| 1181 | // is stride==0 — a caller bug. Throw before passing 0 to the heap. |
| 1182 | if ( !stride ) { |
| 1183 | ((Context *)context)->throw_error("das_array_clear: stride must be non-zero for non-empty array"); |
| 1184 | return; |
| 1185 | } |
| 1186 | ((Context *)context)->free(a->data, a->capacity * stride, nullptr); |
| 1187 | } |
| 1188 | memset(a, 0, sizeof(Array)); |
| 1189 | } |
| 1190 | |
| 1191 | void * das_array_at ( das_array * arr, uint32_t index, uint32_t stride ) { |
| 1192 | return ((Array *)arr)->data + size_t(index) * size_t(stride); |
no test coverage detected