You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2018/04/21 13:11:17 UTC
[arrow] branch master updated: ARROW-2481: [Rust] Move all calls to
free() into memory.rs
This is an automated email from the ASF dual-hosted git repository.
uwe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new c19b1f0 ARROW-2481: [Rust] Move all calls to free() into memory.rs
c19b1f0 is described below
commit c19b1f066e8673feccc7da87f1ff839051ef2beb
Author: Andy Grove <an...@gmail.com>
AuthorDate: Sat Apr 21 14:11:09 2018 +0100
ARROW-2481: [Rust] Move all calls to free() into memory.rs
Author: Andy Grove <an...@gmail.com>
Closes #1919 from andygrove/memory_refactor and squashes the following commits:
153d65d3 <Andy Grove> move calls to free memory to memory.rs
589ef71d <Andy Grove> Merge remote-tracking branch 'upstream/master'
bd4fbb55 <Andy Grove> Merge remote-tracking branch 'upstream/master'
9c8a10a4 <Andy Grove> Merge remote-tracking branch 'upstream/master'
05592f8c <Andy Grove> Merge remote-tracking branch 'upstream/master'
8c0e6982 <Andy Grove> Merge remote-tracking branch 'upstream/master'
31ef90ba <Andy Grove> Merge remote-tracking branch 'upstream/master'
2f87c703 <Andy Grove> Fix build - add missing import
---
rust/src/buffer.rs | 17 +----------------
rust/src/builder.rs | 19 +------------------
rust/src/memory.rs | 15 +++++++++++++++
3 files changed, 17 insertions(+), 34 deletions(-)
diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index df62a3d..cdfbfc9 100644
--- a/rust/src/buffer.rs
+++ b/rust/src/buffer.rs
@@ -22,12 +22,6 @@ use std::slice;
use super::memory::*;
-#[cfg(windows)]
-#[link(name = "msvcrt")]
-extern "C" {
- fn _aligned_free(prt: *const u8);
-}
-
/// Buffer<T> is essentially just a Vec<T> for fixed-width primitive types and the start of the
/// memory region is aligned at a 64-byte boundary
pub struct Buffer<T> {
@@ -82,19 +76,10 @@ impl<T> Buffer<T> {
}
impl<T> Drop for Buffer<T> {
- #[cfg(windows)]
fn drop(&mut self) {
unsafe {
let p = mem::transmute::<*const T, *const u8>(self.data);
- _aligned_free(p);
- }
- }
-
- #[cfg(not(windows))]
- fn drop(&mut self) {
- unsafe {
- let p = mem::transmute::<*const T, *mut libc::c_void>(self.data);
- libc::free(p);
+ free_aligned(p);
}
}
}
diff --git a/rust/src/builder.rs b/rust/src/builder.rs
index 69884cc..bb18d2e 100644
--- a/rust/src/builder.rs
+++ b/rust/src/builder.rs
@@ -24,12 +24,6 @@ use std::slice;
use super::buffer::*;
use super::memory::*;
-#[cfg(windows)]
-#[link(name = "msvcrt")]
-extern "C" {
- fn _aligned_free(prt: *const u8);
-}
-
/// Buffer builder with zero-copy build method
pub struct Builder<T> {
data: *mut T,
@@ -143,22 +137,11 @@ impl<T> Builder<T> {
}
impl<T> Drop for Builder<T> {
- #[cfg(windows)]
fn drop(&mut self) {
if !self.data.is_null() {
unsafe {
let p = mem::transmute::<*const T, *const u8>(self.data);
- _aligned_free(p);
- }
- }
- }
-
- #[cfg(not(windows))]
- fn drop(&mut self) {
- if !self.data.is_null() {
- unsafe {
- let p = mem::transmute::<*const T, *mut libc::c_void>(self.data);
- libc::free(p);
+ free_aligned(p);
}
}
}
diff --git a/rust/src/memory.rs b/rust/src/memory.rs
index 0fc2fda..a62fcb2 100644
--- a/rust/src/memory.rs
+++ b/rust/src/memory.rs
@@ -26,6 +26,7 @@ const ALIGNMENT: usize = 64;
#[link(name = "msvcrt")]
extern "C" {
fn _aligned_malloc(size: libc::size_t, alignment: libc::size_t) -> libc::size_t;
+ fn _aligned_free(prt: *const u8);
}
#[cfg(windows)]
@@ -53,6 +54,20 @@ pub fn allocate_aligned(size: i64) -> Result<*const u8, ArrowError> {
}
}
+#[cfg(windows)]
+pub fn free_aligned(p: *const u8) {
+ unsafe {
+ _aligned_free(p);
+ }
+}
+
+#[cfg(not(windows))]
+pub fn free_aligned(p: *const u8) {
+ unsafe {
+ libc::free(mem::transmute::<*const u8, *mut libc::c_void>(p));
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
--
To stop receiving notification emails like this one, please contact
uwe@apache.org.