MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / das_array_clear

Function das_array_clear

src/misc/daScriptC.cpp:1172–1189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1170}
1171
1172void 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
1191void * das_array_at ( das_array * arr, uint32_t index, uint32_t stride ) {
1192 return ((Array *)arr)->data + size_t(index) * size_t(stride);

Callers 3

test_capi_i64.cppFile · 0.85
mainFunction · 0.85

Calls 3

isLockedMethod · 0.80
throw_errorMethod · 0.80
freeMethod · 0.45

Tested by

no test coverage detected