Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 16 additions & 15 deletions include/mio/detail/mmap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#ifndef MIO_BASIC_MMAP_IMPL
#define MIO_BASIC_MMAP_IMPL

#include "mio/mmap.hpp"
#include "mio/page.hpp"
#include "mio/detail/string_util.hpp"

#include <algorithm>
#include <cstddef>
#include <cstdint>

#ifndef _WIN32
# include <unistd.h>
Expand All @@ -43,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<DWORD>(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<DWORD>(n & 0xffffffff);
}

inline std::wstring s_2_ws(const std::string& s)
Expand All @@ -60,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<int>(s.size()), &ret[0], static_cast<int>(s.size()));
ret.resize(wide_char_count);
ret.resize(static_cast<std::size_t>(wide_char_count));
}
return ret;
}
Expand Down Expand Up @@ -107,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<int>(GetLastError()), std::system_category());
#else
error.assign(errno, std::system_category());
#endif
Expand Down Expand Up @@ -147,15 +148,15 @@ inline size_t query_file_size(file_handle_type handle, std::error_code& error)
error = detail::last_error();
return 0;
}
return static_cast<int64_t>(file_size.QuadPart);
return static_cast<size_t>(file_size.QuadPart);
#else // POSIX
struct stat sbuf;
if(::fstat(handle, &sbuf) == -1)
{
error = detail::last_error();
return 0;
}
return sbuf.st_size;
return static_cast<size_t>(sbuf.st_size);
#endif
}

Expand All @@ -172,7 +173,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<int64_t>(make_offset_page_aligned(static_cast<size_t>(offset)));
const int64_t length_to_map = offset - aligned_offset + length;
#ifdef _WIN32
const int64_t max_file_size = offset + length;
Expand All @@ -193,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<size_t>(length_to_map)));
if(mapping_start == nullptr)
{
// Close file handle if mapping it failed.
Expand All @@ -204,8 +205,8 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t
#else // POSIX
char* mapping_start = static_cast<char*>(::mmap(
0, // Don't give hint as to where to map.
length_to_map,
mode == access_mode::read ? PROT_READ : PROT_WRITE,
static_cast<size_t>(length_to_map),
mode == access_mode::read ? PROT_READ : PROT_READ | PROT_WRITE,
MAP_SHARED,
file_handle,
aligned_offset));
Expand Down Expand Up @@ -345,8 +346,8 @@ void basic_mmap<AccessMode, ByteT>::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<int64_t>(offset),
static_cast<int64_t>(length == map_entire_file ? (file_size - offset) : length),
AccessMode, error);
if(!error)
{
Expand All @@ -359,8 +360,8 @@ void basic_mmap<AccessMode, ByteT>::map(const handle_type handle,
file_handle_ = handle;
is_handle_internal_ = false;
data_ = reinterpret_cast<pointer>(ctx.data);
length_ = ctx.length;
mapped_length_ = ctx.mapped_length;
length_ = static_cast<size_t>(ctx.length);
mapped_length_ = static_cast<size_t>(ctx.mapped_length);
#ifdef _WIN32
file_mapping_handle_ = ctx.file_mapping_handle;
#endif
Expand Down
5 changes: 3 additions & 2 deletions include/mio/page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef MIO_PAGE_HEADER
#define MIO_PAGE_HEADER

#include <cstddef>
#ifdef _WIN32
# include <windows.h>
#else
Expand Down Expand Up @@ -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<size_t>([]
{
#ifdef _WIN32
SYSTEM_INFO SystemInfo;
Expand All @@ -57,7 +58,7 @@ inline size_t page_size()
#else
return sysconf(_SC_PAGE_SIZE);
#endif
}();
}());
return page_size;
}

Expand Down