From 898b53e2b75241e7acb488a89b6d95eab8c55e27 Mon Sep 17 00:00:00 2001 From: Sewer56 Date: Mon, 24 Jun 2024 00:49:01 +0100 Subject: [PATCH] Fix: A lot of compile warnings on various platforms. --- src-rust/Cargo.toml | 1 + src-rust/build.rs | 11 +++++++++++ src-rust/src/buffers.rs | 3 +-- src-rust/src/internal/buffer_allocator.rs | 2 +- src-rust/src/internal/memory_mapped_file_windows.rs | 4 ++-- src-rust/src/lib.rs | 3 +++ src-rust/src/structs/private_allocation.rs | 4 ++-- src-rust/src/utilities/map_parser_utilities.rs | 1 - 8 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 src-rust/build.rs diff --git a/src-rust/Cargo.toml b/src-rust/Cargo.toml index 1955342..27c05bd 100644 --- a/src-rust/Cargo.toml +++ b/src-rust/Cargo.toml @@ -19,6 +19,7 @@ no_format = [] # Removes string formatting (less detailed errors) for binary siz all_private = [] # No memory mapped files, memory is not shared. size_opt = ["nightly"] nightly = [] # Optimizations for nightly builds. +mmap-rs = [] # Uses mmap-rs for memory mapping. This is auto activated during build. [dependencies] concat-string = "1.0.1" diff --git a/src-rust/build.rs b/src-rust/build.rs new file mode 100644 index 0000000..09908c0 --- /dev/null +++ b/src-rust/build.rs @@ -0,0 +1,11 @@ +fn main() { + // This defines a fallback to mmap-rs if one of the explicit memory mapped file implementations + // is not available. + if !cfg!(any( + target_os = "macos", + target_os = "windows", + target_os = "linux" + )) { + println!("cargo:rustc-cfg=feature=\"mmap-rs\""); + } +} diff --git a/src-rust/src/buffers.rs b/src-rust/src/buffers.rs index 5129a45..f8983be 100644 --- a/src-rust/src/buffers.rs +++ b/src-rust/src/buffers.rs @@ -234,7 +234,6 @@ mod tests { structs::params::{BufferAllocatorSettings, BufferSearchSettings}, utilities::cached::get_sys_info, }; - use std; #[cfg(not(target_os = "macos"))] #[test] @@ -418,7 +417,7 @@ mod tests { } let item = Buffers::get_buffer(&BufferSearchSettings::from_proximity( - std::i32::MAX as usize, + i32::MAX as usize, base_address, SIZE, )); diff --git a/src-rust/src/internal/buffer_allocator.rs b/src-rust/src/internal/buffer_allocator.rs index 0d4b933..4c34a04 100644 --- a/src-rust/src/internal/buffer_allocator.rs +++ b/src-rust/src/internal/buffer_allocator.rs @@ -22,7 +22,7 @@ pub fn allocate( return crate::internal::buffer_allocator_osx::allocate_osx(settings); // Fallback for non-hot-path OSes. - #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))] + #[cfg(feature = "mmap-rs")] crate::internal::buffer_allocator_mmap_rs::allocate_mmap_rs(settings) } diff --git a/src-rust/src/internal/memory_mapped_file_windows.rs b/src-rust/src/internal/memory_mapped_file_windows.rs index 19289ad..567e954 100644 --- a/src-rust/src/internal/memory_mapped_file_windows.rs +++ b/src-rust/src/internal/memory_mapped_file_windows.rs @@ -92,12 +92,12 @@ mod tests { let file_length = get_sys_info().allocation_granularity as usize; let mmf = WindowsMemoryMappedFile::new(&file_name, file_length); - assert_eq!(mmf.already_existed, false); + assert!(!mmf.already_existed); assert_eq!(mmf.length, file_length); // Assert the file can be opened again (i.e., it exists) let mmf_existing = WindowsMemoryMappedFile::new(&file_name, file_length); - assert_eq!(mmf_existing.already_existed, true); + assert!(mmf_existing.already_existed); } #[test] diff --git a/src-rust/src/lib.rs b/src-rust/src/lib.rs index bae3de9..dbb844f 100644 --- a/src-rust/src/lib.rs +++ b/src-rust/src/lib.rs @@ -132,7 +132,10 @@ pub(crate) mod utilities { pub mod address_range; pub mod cached; pub mod icache_clear; + + #[cfg(any(target_os = "linux", feature = "mmap-rs"))] pub mod map_parser_utilities; + pub mod mathematics; pub mod wrappers; diff --git a/src-rust/src/structs/private_allocation.rs b/src-rust/src/structs/private_allocation.rs index 5cf8dcd..30f3348 100644 --- a/src-rust/src/structs/private_allocation.rs +++ b/src-rust/src/structs/private_allocation.rs @@ -165,7 +165,7 @@ impl PrivateAllocation { } /// Frees the allocated memory when the `PrivateAllocation` instance is dropped. - #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))] + #[cfg(feature = "mmap-rs")] pub(crate) fn drop_mmap_rs(&mut self) { use mmap_rs_with_map_from_existing::MmapOptions; let _map = unsafe { @@ -193,7 +193,7 @@ impl Drop for PrivateAllocation { return PrivateAllocation::drop_macos(self); // non-hot-path-os - #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))] + #[cfg(feature = "mmap-rs")] return PrivateAllocation::drop_mmap_rs(self); } } diff --git a/src-rust/src/utilities/map_parser_utilities.rs b/src-rust/src/utilities/map_parser_utilities.rs index cbfd949..f7d7b53 100644 --- a/src-rust/src/utilities/map_parser_utilities.rs +++ b/src-rust/src/utilities/map_parser_utilities.rs @@ -44,7 +44,6 @@ impl MemoryMapEntryTrait for MemoryMapEntry { /// # Arguments /// /// * `regions` - A slice of MemoryMapEntry that contains the regions. - #[cfg_attr(feature = "size_opt", optimize(size))] pub fn get_free_regions(regions: &[T]) -> Vec { let mut last_end_address: usize = 0;