From 0b8e75d9951d7f3b422f30e97cd6cf727fdc979c Mon Sep 17 00:00:00 2001 From: Oliver Schonrock Date: Sun, 8 Dec 2024 19:45:07 +0000 Subject: [PATCH 1/5] make compatible with FreeBSD fixes https://github.com/vimpunk/mio/issues/110 --- include/mio/detail/mmap.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mio/detail/mmap.ipp b/include/mio/detail/mmap.ipp index 716a171..1fec025 100644 --- a/include/mio/detail/mmap.ipp +++ b/include/mio/detail/mmap.ipp @@ -205,7 +205,7 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t char* mapping_start = static_cast(::mmap( 0, // Don't give hint as to where to map. length_to_map, - mode == access_mode::read ? PROT_READ : PROT_WRITE, + mode == access_mode::read ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, file_handle, aligned_offset)); From 565badb03f30cb6078227ac8e8b5d0c972035ba1 Mon Sep 17 00:00:00 2001 From: Oliver Schonrock Date: Fri, 13 Dec 2024 19:56:48 +0000 Subject: [PATCH 2/5] silence cmakes 3.31's warning < 3.10 is now deprecated --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54f8768..e53151b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.10) # # Here we check whether mio is being configured in isolation or as a component From 7fa954bddeae1fbc47aade91b402520fe356cb6d Mon Sep 17 00:00:00 2001 From: Oliver Schonrock Date: Fri, 13 Dec 2024 20:23:38 +0000 Subject: [PATCH 3/5] silencing -Wconversion and -Wsign-conversion warnings --- include/mio/detail/mmap.ipp | 16 +++++++++------- include/mio/page.hpp | 5 +++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/mio/detail/mmap.ipp b/include/mio/detail/mmap.ipp index 1fec025..d2a6126 100644 --- a/include/mio/detail/mmap.ipp +++ b/include/mio/detail/mmap.ipp @@ -26,6 +26,8 @@ #include "mio/detail/string_util.hpp" #include +#include +#include #ifndef _WIN32 # include @@ -155,7 +157,7 @@ inline size_t query_file_size(file_handle_type handle, std::error_code& error) error = detail::last_error(); return 0; } - return sbuf.st_size; + return static_cast(sbuf.st_size); #endif } @@ -172,7 +174,7 @@ struct mmap_context inline mmap_context memory_map(const file_handle_type file_handle, const int64_t offset, const int64_t length, const access_mode mode, std::error_code& error) { - const int64_t aligned_offset = make_offset_page_aligned(offset); + const int64_t aligned_offset = static_cast(make_offset_page_aligned(static_cast(offset))); const int64_t length_to_map = offset - aligned_offset + length; #ifdef _WIN32 const int64_t max_file_size = offset + length; @@ -204,7 +206,7 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t #else // POSIX char* mapping_start = static_cast(::mmap( 0, // Don't give hint as to where to map. - length_to_map, + static_cast(length_to_map), mode == access_mode::read ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, file_handle, @@ -345,8 +347,8 @@ void basic_mmap::map(const handle_type handle, return; } - const auto ctx = detail::memory_map(handle, offset, - length == map_entire_file ? (file_size - offset) : length, + const auto ctx = detail::memory_map(handle, static_cast(offset), + static_cast(length == map_entire_file ? (file_size - offset) : length), AccessMode, error); if(!error) { @@ -359,8 +361,8 @@ void basic_mmap::map(const handle_type handle, file_handle_ = handle; is_handle_internal_ = false; data_ = reinterpret_cast(ctx.data); - length_ = ctx.length; - mapped_length_ = ctx.mapped_length; + length_ = static_cast(ctx.length); + mapped_length_ = static_cast(ctx.mapped_length); #ifdef _WIN32 file_mapping_handle_ = ctx.file_mapping_handle; #endif diff --git a/include/mio/page.hpp b/include/mio/page.hpp index cae7377..4868128 100644 --- a/include/mio/page.hpp +++ b/include/mio/page.hpp @@ -21,6 +21,7 @@ #ifndef MIO_PAGE_HEADER #define MIO_PAGE_HEADER +#include #ifdef _WIN32 # include #else @@ -48,7 +49,7 @@ enum class access_mode */ inline size_t page_size() { - static const size_t page_size = [] + static const size_t page_size = static_cast([] { #ifdef _WIN32 SYSTEM_INFO SystemInfo; @@ -57,7 +58,7 @@ inline size_t page_size() #else return sysconf(_SC_PAGE_SIZE); #endif - }(); + }()); return page_size; } From 7a1d9bec47cb98bd3f1595f3ab462303a4193000 Mon Sep 17 00:00:00 2001 From: Oliver Schonrock Date: Fri, 13 Dec 2024 20:25:29 +0000 Subject: [PATCH 4/5] remove recursive include --- include/mio/detail/mmap.ipp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/mio/detail/mmap.ipp b/include/mio/detail/mmap.ipp index d2a6126..90adabb 100644 --- a/include/mio/detail/mmap.ipp +++ b/include/mio/detail/mmap.ipp @@ -21,7 +21,6 @@ #ifndef MIO_BASIC_MMAP_IMPL #define MIO_BASIC_MMAP_IMPL -#include "mio/mmap.hpp" #include "mio/page.hpp" #include "mio/detail/string_util.hpp" From 9d54db9c4477d8e9b2c8bf897e700236666cbe1c Mon Sep 17 00:00:00 2001 From: Oliver Schonrock Date: Tue, 17 Dec 2024 15:07:12 +0000 Subject: [PATCH 5/5] casts to remove warnings in WIN32 mode --- include/mio/detail/mmap.ipp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/mio/detail/mmap.ipp b/include/mio/detail/mmap.ipp index 90adabb..19cbb93 100644 --- a/include/mio/detail/mmap.ipp +++ b/include/mio/detail/mmap.ipp @@ -44,13 +44,13 @@ namespace win { /** Returns the 4 upper bytes of an 8-byte integer. */ inline DWORD int64_high(int64_t n) noexcept { - return n >> 32; + return static_cast(n >> 32); } /** Returns the 4 lower bytes of an 8-byte integer. */ inline DWORD int64_low(int64_t n) noexcept { - return n & 0xffffffff; + return static_cast(n & 0xffffffff); } inline std::wstring s_2_ws(const std::string& s) @@ -61,7 +61,7 @@ inline std::wstring s_2_ws(const std::string& s) ret.resize(s.size()); int wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), static_cast(s.size()), &ret[0], static_cast(s.size())); - ret.resize(wide_char_count); + ret.resize(static_cast(wide_char_count)); } return ret; } @@ -108,7 +108,7 @@ inline std::error_code last_error() noexcept { std::error_code error; #ifdef _WIN32 - error.assign(GetLastError(), std::system_category()); + error.assign(static_cast(GetLastError()), std::system_category()); #else error.assign(errno, std::system_category()); #endif @@ -148,7 +148,7 @@ inline size_t query_file_size(file_handle_type handle, std::error_code& error) error = detail::last_error(); return 0; } - return static_cast(file_size.QuadPart); + return static_cast(file_size.QuadPart); #else // POSIX struct stat sbuf; if(::fstat(handle, &sbuf) == -1) @@ -194,7 +194,7 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t mode == access_mode::read ? FILE_MAP_READ : FILE_MAP_WRITE, win::int64_high(aligned_offset), win::int64_low(aligned_offset), - length_to_map)); + static_cast(length_to_map))); if(mapping_start == nullptr) { // Close file handle if mapping it failed.