Skip to content

Commit

Permalink
Fix: A lot of compile warnings on various platforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jun 23, 2024
1 parent f04fd9e commit 898b53e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions src-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions src-rust/build.rs
Original file line number Diff line number Diff line change
@@ -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\"");
}
}
3 changes: 1 addition & 2 deletions src-rust/src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ mod tests {
structs::params::{BufferAllocatorSettings, BufferSearchSettings},
utilities::cached::get_sys_info,
};
use std;

#[cfg(not(target_os = "macos"))]
#[test]
Expand Down Expand Up @@ -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,
));
Expand Down
2 changes: 1 addition & 1 deletion src-rust/src/internal/buffer_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions src-rust/src/internal/memory_mapped_file_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions src-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src-rust/src/structs/private_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand Down
1 change: 0 additions & 1 deletion src-rust/src/utilities/map_parser_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: MemoryMapEntryTrait>(regions: &[T]) -> Vec<MemoryMapEntry> {
let mut last_end_address: usize = 0;
Expand Down

0 comments on commit 898b53e

Please sign in to comment.