diff --git a/rstsr-common/src/alloc_vec.rs b/rstsr-common/src/alloc_vec.rs index 130c8ae..e6785a2 100644 --- a/rstsr-common/src/alloc_vec.rs +++ b/rstsr-common/src/alloc_vec.rs @@ -15,11 +15,24 @@ use core::ptr::NonNull; /// This is not a very good function, since `set_len` on uninitialized memory is /// undefined-behavior (UB). /// Nevertheless, if `T` is some type of `MaybeUninit`, then this will not UB. +/// +/// # OS system dependent +/// +/// Current implementation of aligned allocation may be UB on Windows. We will disable aligned +/// allocation on platforms other than Linux and MacOS until we find a better solution. +/// +/// See also . pub unsafe fn uninitialized_vec(size: usize) -> Result> { - #[cfg(not(feature = "aligned_alloc"))] + #[cfg(all(not(target_os = "linux"), not(target_os = "macos")))] return unaligned_uninitialized_vec(size); - #[cfg(feature = "aligned_alloc")] - return aligned_uninitialized_vec::(size, 64); + + #[cfg(any(target_os = "linux", target_os = "macos"))] + { + #[cfg(not(feature = "aligned_alloc"))] + return unaligned_uninitialized_vec(size); + #[cfg(feature = "aligned_alloc")] + return aligned_uninitialized_vec::(size, 64); + } } /// Create an unaligned uninitialized vector with the given size. @@ -57,8 +70,6 @@ pub fn aligned_alloc(numbytes: usize, alignment: usize) -> Result