Add arena_copy and lfstr_copy_arena #8

Merged
fputs merged 1 commit from fputs/arena-copy into master 2026-11-05 09:33:18 -08:00 AGit
Owner

Adds arena_copy and lfstr_copy_arena.

arena_copy copies n bytes into a fresh arena block. n == 0 copies nothing and still returns a non-NULL pointer. arena_malloc(0) does not advance the bump pointer, so a zero-length copy reserves one byte and must not be read.

lfstr_copy_arena is declared in lfstring.h and defined in src/string.c. It copies s.n bytes even when a NUL sits in the middle, then writes one trailing NUL that is not counted in n. Failure leaves *out unchanged.

The test uses arena_init_buf with a slab too small for the second copy. arena_free does not free that caller-owned slab.

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

Adds `arena_copy` and `lfstr_copy_arena`. `arena_copy` copies `n` bytes into a fresh arena block. `n == 0` copies nothing and still returns a non-NULL pointer. `arena_malloc(0)` does not advance the bump pointer, so a zero-length copy reserves one byte and must not be read. `lfstr_copy_arena` is declared in `lfstring.h` and defined in `src/string.c`. It copies `s.n` bytes even when a NUL sits in the middle, then writes one trailing NUL that is not counted in `n`. Failure leaves `*out` unchanged. The test uses `arena_init_buf` with a slab too small for the second copy. `arena_free` does not free that caller-owned slab. Tested with `-DCMAKE_BUILD_TYPE=Debug -DFLINT_SANITIZE=ON -DCMAKE_C_EXTENSIONS=OFF`. `ctest --label-exclude slow`: 25/25 passed.
Add arena_copy and lfstr_copy_arena
All checks were successful
test / test (pull_request) Successful in 14s
test / sanitize (pull_request) Successful in 17s
a55846268c
fputs merged commit d2188c79f1 into master 2026-11-05 09:33:18 -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!8
No description provided.