Apache DataFusion SQL Query Engine
ARROW-2434: [Rust] Add windows support
Paddye6f16b1c9c42
diff --git a/rust/src/buffer.rs b/rust/src/buffer.rsindex 1cf004fb1b..85f57f68c3 100644--- a/rust/src/buffer.rs+++ b/rust/src/buffer.rs@@ -22,6 +22,12 @@ 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 boundarypub struct Buffer<T> {@@ -73,6 +79,15 @@ 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);diff --git a/rust/src/builder.rs b/rust/src/builder.rsindex 9915a8b52c..1744b4eeb4 100644--- a/rust/src/builder.rs+++ b/rust/src/builder.rs@@ -23,6 +23,12 @@ 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 methodpub struct Builder<T> {data: *mut T,@@ -98,6 +104,17 @@ 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 {diff --git a/rust/src/memory.rs b/rust/src/memory.rsindex e3bb786bc3..0fc2fda3b2 100644--- a/rust/src/memory.rs+++ b/rust/src/memory.rs@@ -22,6 +22,24 @@ use super::error::ArrowError;const ALIGNMENT: usize = 64;+#[cfg(windows)]+#[link(name = "msvcrt")]+extern "C" {+ fn _aligned_malloc(size: libc::size_t, alignment: libc::size_t) -> libc::size_t;+}++#[cfg(windows)]+pub fn allocate_aligned(size: i64) -> Result<*const u8, ArrowError> {+ let page = unsafe { _aligned_malloc(size as libc::size_t, ALIGNMENT as libc::size_t) };+ match page {+ 0 => Err(ArrowError::MemoryError(+ "Failed to allocate memory".to_string(),+ )),+ _ => Ok(unsafe { mem::transmute::<libc::size_t, *const u8>(page) }),+ }+}++#[cfg(not(windows))]pub fn allocate_aligned(size: i64) -> Result<*const u8, ArrowError> {unsafe {let mut page: *mut libc::c_void = mem::uninitialized();