Skip to content

Commit 341c8fb

Browse files
committed
compile
1 parent 9068cc8 commit 341c8fb

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/common/io.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
22
* Copyright 2019-2023, by XGBoost Contributors
33
*/
4+
#if !defined(NOMINMAX) && defined(_WIN32)
5+
#define NOMINMAX
6+
#endif // !defined(NOMINMAX)
7+
48
#if defined(__unix__) || defined(__APPLE__)
59
#include <fcntl.h> // for open, O_RDONLY
610
#include <sys/mman.h> // for mmap, mmap64, munmap
@@ -162,8 +166,18 @@ std::string FileExtension(std::string fname, bool lower) {
162166
}
163167
}
164168

169+
std::size_t GetPageSize() {
170+
#if defined(_MSC_VER)
171+
SYSTEM_INFO sys_info;
172+
GetSystemInfo(&sys_info);
173+
return sys_info.dwPageSize;
174+
#else
175+
return getpagesize();
176+
#endif
177+
}
178+
165179
std::size_t PadPageForMmap(std::size_t file_bytes, dmlc::Stream* fo) {
166-
decltype(file_bytes) page_size = getpagesize();
180+
decltype(file_bytes) page_size = GetPageSize();
167181
CHECK(page_size != 0 && page_size % 2 == 0) << "Failed to get page size on the current system.";
168182
CHECK_NE(file_bytes, 0) << "Empty page encountered.";
169183
auto n_pages = file_bytes / page_size + !!(file_bytes % page_size != 0);
@@ -195,9 +209,9 @@ void* PrivateMmapStream::Open(std::string path, bool read_only, std::size_t offs
195209
CHECK_NE(fd, INVALID_HANDLE_VALUE) << "Failed to open:" << path;
196210
#else
197211
auto fd = open(path.c_str(), O_RDONLY);
198-
#endif
199212
CHECK_GE(fd, 0) << "Failed to open:" << path << ". " << strerror(errno);
200-
handle_ = std::make_unique<MMAPFile>(fd, std::move(path));
213+
#endif
214+
handle_.reset(new MMAPFile{fd, std::move(path)});
201215

202216
void* ptr{nullptr};
203217
#if defined(__linux__) || defined(__GLIBC__)
@@ -212,7 +226,9 @@ void* PrivateMmapStream::Open(std::string path, bool read_only, std::size_t offs
212226
DWORD access = read_only ? PAGE_READONLY : PAGE_READWRITE;
213227
auto map_file = CreateFileMapping(handle_->fd, nullptr, access, 0, file_size, nullptr);
214228
access = read_only ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS;
215-
ptr = MapViewOfFile(map_file, access, 0, offset, length);
229+
std::uint32_t loff = static_cast<std::uint32_t>(offset);
230+
std::uint32_t hoff = offset >> 32;
231+
ptr = MapViewOfFile(map_file, access, hoff, loff, length);
216232
CHECK_NE(ptr, nullptr) << "Failed to map: " << handle_->path << ". " << GetLastError();
217233
#else
218234
CHECK_LE(offset, std::numeric_limits<off_t>::max())

src/data/sparse_page_source.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class SparsePageSource : public SparsePageSourceImpl<SparsePage> {
261261
iter_{iter}, proxy_{proxy} {
262262
if (!cache_info_->written) {
263263
iter_.Reset();
264-
CHECK_EQ(iter_.Next(), 1) << "Must have at least 1 batch.";
264+
CHECK(iter_.Next()) << "Must have at least 1 batch.";
265265
}
266266
this->Fetch();
267267
}

0 commit comments

Comments
 (0)