houqp commented on a change in pull request #7480:
URL: https://github.com/apache/arrow/pull/7480#discussion_r443140804
##########
File path: rust/arrow/src/memory.rs
##########
@@ -150,25 +150,32 @@ pub fn allocate_aligned(size: usize) -> *mut u8 {
}
pub unsafe fn free_aligned(ptr: *mut u8, size: usize) {
- if size != 0x00 && ptr != BYPASS_PTR.as_ptr() {
+ if ptr != BYPASS_PTR.as_ptr() {
std::alloc::dealloc(ptr, Layout::from_size_align_unchecked(size,
ALIGNMENT));
}
}
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, new_size: usize) ->
*mut u8 {
if ptr == BYPASS_PTR.as_ptr() {
- allocate_aligned(new_size)
- } else {
- let new_ptr = std::alloc::realloc(
- ptr,
- Layout::from_size_align_unchecked(old_size, ALIGNMENT),
- new_size,
- );
- if !new_ptr.is_null() && new_size > old_size {
- new_ptr.add(old_size).write_bytes(0, new_size - old_size);
- }
- new_ptr
+ return allocate_aligned(new_size);
+ }
+
+ if new_size == 0 {
+ free_aligned(ptr, old_size);
+ return BYPASS_PTR.as_ptr();
Review comment:
At first i thought there is straightforward api from the global
allocator we can use to access memory allocation metadata. This turned out not
to be the case, which means we will either have to introduce valgrind or change
rust global allocator to a custom one for tests. Both approaches will expand
the scope of this PR too much, so scratch what I said, I think it's better to
be done as a separate PRs.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]