This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new fb174ba fix(arrow/memory/internal/cgoalloc): Remove usage of
reflect.SliceHeader (#194)
fb174ba is described below
commit fb174ba36a631eb2a947f5aa60cd31ef050f1d0c
Author: Matt Topol <[email protected]>
AuthorDate: Thu Nov 21 18:39:53 2024 -0500
fix(arrow/memory/internal/cgoalloc): Remove usage of reflect.SliceHeader
(#194)
### Rationale for this change
Removing deprecated usage of `reflect.SliceHeader` and using
`unsafe.SliceData` and `unsafe.Slice` instead.
### Are these changes tested?
yes
### Are there any user-facing changes?
No
Fixes #40
---
arrow/memory/internal/cgoalloc/allocator.go | 21 ++++-----------------
1 file changed, 4 insertions(+), 17 deletions(-)
diff --git a/arrow/memory/internal/cgoalloc/allocator.go
b/arrow/memory/internal/cgoalloc/allocator.go
index 48f34d8..e7cc049 100644
--- a/arrow/memory/internal/cgoalloc/allocator.go
+++ b/arrow/memory/internal/cgoalloc/allocator.go
@@ -25,7 +25,6 @@ package cgoalloc
// #include "allocator.h"
import "C"
import (
- "reflect"
"unsafe"
)
@@ -35,20 +34,14 @@ type CGOMemPool = C.ArrowMemoryPool
// CgoPoolAlloc allocates a block of memory of length 'size' using the memory
// pool that is passed in.
func CgoPoolAlloc(pool CGOMemPool, size int) []byte {
- var ret []byte
if size == 0 {
- return ret
+ return []byte{}
}
var out *C.uint8_t
C.arrow_pool_allocate(pool, C.int64_t(size),
(**C.uint8_t)(unsafe.Pointer(&out)))
- s := (*reflect.SliceHeader)(unsafe.Pointer(&ret))
- s.Data = uintptr(unsafe.Pointer(out))
- s.Len = size
- s.Cap = size
-
- return ret
+ return unsafe.Slice((*byte)(unsafe.Pointer(out)), size)
}
// CgoPoolRealloc calls 'reallocate' on the block of memory passed in which
must
@@ -59,16 +52,10 @@ func CgoPoolRealloc(pool CGOMemPool, size int, b []byte)
[]byte {
}
oldSize := C.int64_t(len(b))
- data := (*C.uint8_t)(unsafe.Pointer(&b[0]))
+ data := (*C.uint8_t)(unsafe.SliceData(b))
C.arrow_pool_reallocate(pool, oldSize, C.int64_t(size), &data)
- var ret []byte
- s := (*reflect.SliceHeader)(unsafe.Pointer(&ret))
- s.Data = uintptr(unsafe.Pointer(data))
- s.Len = size
- s.Cap = size
-
- return ret
+ return unsafe.Slice((*byte)(unsafe.Pointer(data)), size)
}
// CgoPoolFree uses the indicated memory pool to free a block of memory. The