Add LfDArray inline dynamic array #1

Merged
fputs merged 1 commit from fputs/darray into master 2026-11-05 09:58:10 -08:00 AGit
Owner

Adds LfDArray, a growable buffer of trivially copyable structs. Vector stays a void * array.

init allocates two elements. Growth doubles through lf_reallocarray. A failed grow leaves length, capacity, the pointer, and the existing bytes unchanged. There is no per-element destructor. sort is ISO qsort over the element bytes, so the comparator sees the struct, not a void **.

Allocation failure is covered in test_alloc_fail: after two pushes, the next realloc inside push fails and the array is unchanged.

Tested with -DCMAKE_BUILD_TYPE=Debug -DFLINT_SANITIZE=ON -DCMAKE_C_EXTENSIONS=OFF. ctest --label-exclude slow: 26/26 passed.

Adds `LfDArray`, a growable buffer of trivially copyable structs. `Vector` stays a `void *` array. `init` allocates two elements. Growth doubles through `lf_reallocarray`. A failed grow leaves length, capacity, the pointer, and the existing bytes unchanged. There is no per-element destructor. `sort` is ISO `qsort` over the element bytes, so the comparator sees the struct, not a `void **`. Allocation failure is covered in `test_alloc_fail`: after two pushes, the next `realloc` inside `push` fails and the array is unchanged. Tested with `-DCMAKE_BUILD_TYPE=Debug -DFLINT_SANITIZE=ON -DCMAKE_C_EXTENSIONS=OFF`. `ctest --label-exclude slow`: 26/26 passed.
Add LfDArray inline dynamic array
All checks were successful
test / test (pull_request) Successful in 15s
test / sanitize (pull_request) Successful in 17s
fc416490e1
fputs force-pushed fputs/darray from fc416490e1
All checks were successful
test / test (pull_request) Successful in 15s
test / sanitize (pull_request) Successful in 17s
to 708e6412ba
All checks were successful
test / test (pull_request) Successful in 14s
test / sanitize (pull_request) Successful in 17s
2026-11-05 09:39:13 -08:00
Compare
fputs force-pushed fputs/darray from 708e6412ba
All checks were successful
test / test (pull_request) Successful in 14s
test / sanitize (pull_request) Successful in 17s
to f781872509
All checks were successful
test / test (pull_request) Successful in 15s
test / sanitize (pull_request) Successful in 18s
2026-11-05 09:56:48 -08:00
Compare
fputs merged commit ce40606d1d into master 2026-11-05 09:58:10 -08:00
fputs referenced this pull request from a commit 2026-11-05 09:58:10 -08:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
fputs/libflint!1
No description provided.