Skip to content

C: Extract hb_allocator_T#1287

Merged
marcoroth merged 1 commit intomainfrom
hb_allocator_T
Mar 3, 2026
Merged

C: Extract hb_allocator_T#1287
marcoroth merged 1 commit intomainfrom
hb_allocator_T

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Mar 3, 2026

This pull request extracts a hb_allocator_T for providing an interface for allocating memory in the lexer and parser. In this pull request we implement both a malloc-based and a hb_arena_T-based allocator.

Additionally, this updates all call-sites and functions to accept a new allocator that can later be swapped to use the hb_arena_T-based allocator in #726.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 3, 2026

npx https://pkg.pr.new/@herb-tools/formatter@1287
npx https://pkg.pr.new/@herb-tools/language-server@1287
npx https://pkg.pr.new/@herb-tools/linter@1287

commit: 85defcf

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit 85defcf


✅ Preview deployment has been cleaned up.

@marcoroth marcoroth merged commit d988957 into main Mar 3, 2026
32 checks passed
@marcoroth marcoroth deleted the hb_allocator_T branch March 3, 2026 20:38
marcoroth added a commit that referenced this pull request Mar 4, 2026
This pull request introduces arena allocation for the lexer and parser,
replacing "per-object" `malloc`/`free` calls with bulk allocation from a
memory arena.

All allocated AST nodes, tokens, and internal strings are placed into a
single arena that is freed in one shot after the parse tree has been
converted to the binding's native objects.

The arena is accessed through `hb_allocator_T`, a vtable-based allocator
abstraction introduced in #1287. This pull request switches the default
backend from `malloc` to `hb_arena_T` across all bindings and the CLI.

The `malloc` backend remains available as a fallback. The intent is to
validate the arena approach in production and then, once confident,
simplify the abstraction away and use `hb_arena_T` directly.

The `hb_allocator_T` interface was extended with a `destroy` function
pointer and a high-level `hb_allocator_init(allocator, type)`
constructor that takes an `hb_allocator_type_T` enum
(`HB_ALLOCATOR_ARENA`, `HB_ALLOCATOR_MALLOC`).

A separate `hb_allocator_init_with_size` variant accepts a custom
initial arena size for edge cases. The default arena size is controlled
by a compile-time `HB_ALLOCATOR_DEFAULT_ARENA_SIZE` flag.

The extract API (`herb_extract`, `herb_extract_ruby_*`,
`herb_extract_html_*`) was also updated to accept an `hb_allocator_T*`.

Depends on #1287
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant