[ 
https://issues.apache.org/jira/browse/ARROW-2434?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16431910#comment-16431910
 ] 

ASF GitHub Bot commented on ARROW-2434:
---------------------------------------

xhochy closed pull request #1873: ARROW-2434: [Rust] Add windows support
URL: https://github.com/apache/arrow/pull/1873
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index 1cf004fb1..85f57f68c 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 9915a8b52..1744b4eeb 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 e3bb786bc..0fc2fda3b 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();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Rust] Add windows support
> --------------------------
>
>                 Key: ARROW-2434
>                 URL: https://issues.apache.org/jira/browse/ARROW-2434
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Rust
>            Reporter: Paddy Horan
>            Assignee: Paddy Horan
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.10.0
>
>
> Currently `cargo test` fails on windows OS.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to