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 33d92a0  ARROW-2434: [Rust] Add windows support
33d92a0 is described below

commit 33d92a0ece934288bced6d11900de74fafd7679b
Author: Paddy <paddyho...@hotmail.com>
AuthorDate: Tue Apr 10 10:23:32 2018 +0200

    ARROW-2434: [Rust] Add windows support
    
    I'm not that familiar with JIRA but I believe that I do not have the 
permission to self-assign this issue.  @andygrove maybe you can assign to me on 
JIRA please (or let me know if I should be able to self-assign).
    
    I had to expose `_aligned_malloc` and `_aligned_free` but I'm thinking that 
this should be in _libc_.  This is just to get windows support building.  I'll 
submit a PR to libc and open another JIRA to clean things up.
    
    Author: Paddy <paddyho...@hotmail.com>
    
    Closes #1873 from paddyhoran/master and squashes the following commits:
    
    7385d31 <Paddy> Removing the use of `if cfg!` macro to fix non windows 
builds.
    35fa405 <Paddy> Fixed formatting issues.
    85ea7d9 <Paddy> Fixes ARROW-2434
---
 rust/src/buffer.rs  | 15 +++++++++++++++
 rust/src/builder.rs | 17 +++++++++++++++++
 rust/src/memory.rs  | 18 ++++++++++++++++++
 3 files changed, 50 insertions(+)

diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index 1cf004f..85f57f6 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 boundary
 pub 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.rs
index 9915a8b..1744b4e 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 method
 pub 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.rs
index e3bb786..0fc2fda 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();

-- 
To stop receiving notification emails like this one, please contact
u...@apache.org.

Reply via email to