We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Odin: dev-2025-02-nightly:748a771 OS: Windows 11 Professional (version: 24H2), build 26100.3194 CPU: 13th Gen Intel(R) Core(TM) i5-1335U RAM: 16107 MiB Backend: LLVM 18.1.8
Calling the heap_allocator proc with .Resize doesn't copy over old data.
Old data is not copied over after .Resize call.
The following code reproduces the issue for me. I am assuming test^ == 5 after the realloc call.
context.allocator = runtime.heap_allocator(); bytes, allocator_error := runtime.heap_allocator_proc(context.allocator.data, .Alloc, 64, align_of(rawptr), nil, 0); assert(allocator_error == runtime.Allocator_Error.None && bytes != nil); test := cast(^u64)raw_data(bytes); test^ = 5; test2 := test; assert(test^ == 5); bytes, allocator_error = runtime.heap_allocator_proc(context.allocator.data, .Resize, auto_cast 256, align_of(rawptr)*2, raw_data(bytes), 0); assert(allocator_error == runtime.Allocator_Error.None && bytes != nil); test = cast(^u64)raw_data(bytes); assert(test2 != test); assert(test^ == 5); // code fails here
.... main.odin(193:2) runtime assertion: test^ == 5
The text was updated successfully, but these errors were encountered:
I am not sure if the following is correct in https://github.com/odin-lang/Odin/blob/master/base/runtime/heap_allocator.odin I would think if force_copy = true, we resize instead of alloc.
force_copy := old_ptr != nil && alignment > align_of(rawptr)
if old_ptr != nil && !force_copy { original_old_ptr := ([^]rawptr)(old_ptr)[-1] allocated_mem = heap_resize(original_old_ptr, space) } else { allocated_mem = heap_alloc(space, zero_memory) }
Sorry, something went wrong.
When you're resizing you're telling it the old size is 0 not 64. So it thinks there's nothing to copy over.
No branches or pull requests
Context
Odin: dev-2025-02-nightly:748a771
OS: Windows 11 Professional (version: 24H2), build 26100.3194
CPU: 13th Gen Intel(R) Core(TM) i5-1335U
RAM: 16107 MiB
Backend: LLVM 18.1.8
Expected Behavior
Calling the heap_allocator proc with .Resize doesn't copy over old data.
Current Behavior
Old data is not copied over after .Resize call.
Failure Information (for bugs)
Steps to Reproduce
The following code reproduces the issue for me. I am assuming test^ == 5 after the realloc call.
Failure Logs
.... main.odin(193:2) runtime assertion: test^ == 5
The text was updated successfully, but these errors were encountered: