Using StackFallbackAllocator.get()
multiple times is a footgun.
#16344
Labels
bug
Observed behavior contradicts documented or intended behavior
standard library
This issue involves writing Zig code for the standard library.
Milestone
Zig Version
0.11.0-dev.3910+689f3163a
Steps to Reproduce and Observed Behavior
Calling
StackFallbackAllocator.get()
(re-)initializes the internalFixedBufferAllocator
.This means that calling
StackFallbackAllocator.get()
multiple times causes problematic behavior:This causes an assertion failure, meaning that both allocations returned the same pointer.
In actual code this is hard to debug because it leads to weird behavior.
For example in my code it messed up line wrapping and swallowed characters in text rendering.
Expected Behavior
The other allocators allow calling
.allocator()
multiple times without causing any trouble.I think this should also apply to
StackFallbackAllocator.get()
.I think the internal
FixedBufferAllocator
should be initialized only once, preferably in theheap.stackFallback(..)
function.Note: This would be a breaking change, that's why I'm hesitant to implement this myself. Existing code might be relying on
StackFallbackAllocator.get()
to initialize theFixedBufferAllocator
The text was updated successfully, but these errors were encountered: