-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
allocator ownSlice fails - workaround adding print to test!!! #11114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
On line 264 you're taking the address of a local variable and returning it. Adding the prints messes with the stack just enough to make it work properly. |
Vexu refers to this:
where I thought I was passing the memory provided by the testing allocator to the fixed buffer allocator. |
You are doing that but you're also creating a temporary |
So save |
I need to save something like the allocator somewhere so I can free the value later. |
Yup, this used to cause #591 but then the allocator interface was changed and now it's less obvious that you're taking a pointer to a temporary stack variable. |
OK, I found it in the code in zig/std/heap.zig for FixedBufferAllocator - it passes a * FixedBufferAllocator to Allocator.init. I can't make the code quite as generic as I wanted, but maybe I'm seeing that I don't need to.... Subtle! Thanks for the help understanding this. |
FWIW this will become a compile error once stack temporaries are changed to be implicitly const. |
Zig Version
0.10.0-dev.1091+7fc8dd66
Steps to Reproduce
Pull Zag-Research/Zag-Smalltalk@00bddf0 and comment/uncomment the print at the end of heap.zig. Then
zig test heap.zig
With the print in, everything is cool.
With the print commented, the allocator fails a sanity check for "ownsSlice".
This is on:
Darwin MacBook-Pro-2.local 18.7.0 Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64 x86_64
Expected Behavior
Pretty sure there's no error in that part of the code.
Very weird that a print in a test can make the allocator happy!
Actual Behavior
The text was updated successfully, but these errors were encountered: