Skip to content

mem: various arena fixes#10

Merged
tspader merged 1 commit into
mainfrom
mem/arena-fixes
Jun 12, 2026
Merged

mem: various arena fixes#10
tspader merged 1 commit into
mainfrom
mem/arena-fixes

Conversation

@tspader

@tspader tspader commented Jun 11, 2026

Copy link
Copy Markdown
Owner

The allocator interface now requires a size for realloc() and free(). This was always an error; sp_sys_free() required a size, and all of our allocators implemented headers to track allocation sizes. The glue between them, the interface, simply omitted it.

In doing this, we were able to get rid of the headers that all the allocators had to implement. This drastically simplified the arena allocator, as well as fixed most of the longstanding issues that I have had with it. Likewise for the page allocator.

I also added some small things:

  • test: Updated the tracking allocator used for leak testing to now verify what was actually allocated and find mismatches
  • io: Added sp_io_dyn_mem_writer_take_str(), which reallocates the buffer so its length and capacity match, allowing it to be returned as a string which can be freed without the writer.
  • io: sp_io_read_file() shrinks the buffer when a file reads short
  • mem: Unrelated overflow checks in the arena
  • mem: Arenas no longer crash on OOM
  • test: Rewrote arena tests declaratively
  • test: Added tests for the fixed allocator

The allocator interface now requires a size for realloc() and free().
This was always an error; sp_sys_free() required a size, and all of
our allocators implemented headers to track allocation sizes. The
glue between them, the interface, simply omitted it.

In doing this, we were able to get rid of the headers that all the
allocators had to implement. This drastically simplified the arena
allocator, as well as fixed most of the longstanding issues that I
have had with it. Likewise for the page allocator.

I also added some small things:
- test: Updated the tracking allocator used for leak testing to now verify
what was actually allocated and find mismatches
- io: Added sp_io_dyn_mem_writer_take_str(), which reallocates the
buffer so its length and capacity match, allowing it to be returned
as a string which can be freed without the writer.
- io: sp_io_read_file() shrinks the buffer when a file reads short
- mem: Unrelated overflow checks in the arena
- mem: Arenas no longer crash on OOM
- test: Rewrote arena tests declaratively
- test: Added tests for the fixed allocator
@tspader tspader merged commit c1cb311 into main Jun 12, 2026
14 checks passed
@tspader tspader deleted the mem/arena-fixes branch June 12, 2026 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant