Skip to content
Merged
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
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ jobs:

- name: Configure
# CMAKE_PREFIX_PATH so find_package(CURL) also looks in the conda env;
# it only searches system paths otherwise.
# it only searches system paths otherwise. Warnings are errors in CI
# only, so new compiler versions don't break downstream builds.
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_COMPILE_WARNING_AS_ERROR=ON \
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX" -DHDF5_ROOT="$CONDA_PREFIX"

- name: Build
Expand Down Expand Up @@ -112,6 +114,7 @@ jobs:
- name: Build the plugin
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_COMPILE_WARNING_AS_ERROR=ON \
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX" -DHDF5_ROOT="$CONDA_PREFIX" \
-DREMFILE_BUILD_PLUGIN=ON
cmake --build build --config Release -j 2
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ option(REMFILE_BUILD_PLUGIN "Build the dynamic HDF5 VFD plugin (requires HDF5 >=
find_package(HDF5 REQUIRED COMPONENTS C)
find_package(CURL REQUIRED)

# GNU-style warning flags; MSVC's cl.exe rejects these outright (D8021), so
# keep the list empty there rather than break downstream Windows builds.
if(NOT MSVC)
set(REMFILE_WARNING_FLAGS -Wall -Wextra -Wold-style-cast -Wsign-conversion)
endif()

# ---- Library ----

add_library(remfile src/remfile_vfd.cpp)
add_library(remfile::remfile ALIAS remfile)

target_compile_features(remfile PRIVATE cxx_std_17)
target_compile_options(remfile PRIVATE ${REMFILE_WARNING_FLAGS})

set_target_properties(remfile PROPERTIES
EXPORT_NAME remfile
Expand All @@ -44,6 +51,7 @@ target_include_directories(remfile
target_include_directories(remfile SYSTEM PUBLIC
"$<BUILD_INTERFACE:${HDF5_INCLUDE_DIRS}>"
)
target_include_directories(remfile SYSTEM PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(remfile
PUBLIC ${HDF5_C_LIBRARIES}
PRIVATE CURL::libcurl
Expand Down Expand Up @@ -95,6 +103,7 @@ endif()
if(REMFILE_BUILD_PLUGIN)
add_library(remfile_vfd_plugin MODULE src/remfile_vfd.cpp)
target_compile_features(remfile_vfd_plugin PRIVATE cxx_std_17)
target_compile_options(remfile_vfd_plugin PRIVATE ${REMFILE_WARNING_FLAGS})
target_compile_definitions(remfile_vfd_plugin PRIVATE REMFILE_VFD_BUILD_PLUGIN)
target_include_directories(remfile_vfd_plugin
PRIVATE "${PROJECT_SOURCE_DIR}/include"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ cmake --build build
cmake --install build --prefix /path/to/install
```

If HDF5 is installed in a custom location, you can specify its path using `-DHDF5_ROOT`:
```bash
cmake -B build -DCMAKE_BUILD_TYPE=Release -DHDF5_ROOT=/path/to/hdf5_install
```

## Using from CMake

```cmake
Expand Down
22 changes: 11 additions & 11 deletions src/remfile_vfd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr size_t kDefaultMaxChunkSize = 100 * 1024 * 1024;
constexpr int kNumRequestRetries = 8;

#if H5_VERSION_GE(1, 14, 0)
constexpr H5FD_class_value_t kRemFileVFDValue = (H5FD_class_value_t)566;
constexpr H5FD_class_value_t kRemFileVFDValue = static_cast<H5FD_class_value_t>(566);
#endif

hid_t g_driver_id = H5I_INVALID_HID;
Expand Down Expand Up @@ -88,7 +88,7 @@ size_t capture_headers(char *ptr, size_t size, size_t nmemb, void *userdata)
if (line.size() > sizeof(prefix) - 1) {
std::string lower = line;
for (auto &c : lower)
c = (char)tolower((unsigned char)c);
c = static_cast<char>(tolower(static_cast<unsigned char>(c)));
if (lower.compare(0, sizeof(prefix) - 1, prefix) == 0) {
size_t slash = line.rfind('/');
if (slash != std::string::npos)
Expand Down Expand Up @@ -234,7 +234,7 @@ bool fetch_content_length(RemFile *f, uint64_t *length_out)
* +0.5 term, so ordinary llround matches). */
uint64_t py_round(double x)
{
return (uint64_t)std::llround(x);
return static_cast<uint64_t>(std::llround(x));
}

/* Load the chunk at chunk_index, plus read-ahead.
Expand All @@ -249,14 +249,14 @@ uint64_t py_round(double x)
bool load_chunk(RemFile *f, uint64_t chunk_index, uint64_t chunks_needed)
{
if (f->chunks.count(chunk_index)) {
f->last_chunk_index_accessed = (int64_t)chunk_index;
f->last_chunk_index_accessed = static_cast<int64_t>(chunk_index);
return true;
}

const size_t min_chunk = f->config.min_chunk_size;
const uint64_t max_seq = f->config.max_chunk_size / min_chunk;

if ((int64_t)chunk_index == f->last_chunk_index_accessed + 1) {
if (static_cast<int64_t>(chunk_index) == f->last_chunk_index_accessed + 1) {
/* Sequential access: grow the request by a factor of 1.7. */
f->chunk_sequence_length = py_round(f->chunk_sequence_length * 1.7 + 0.5);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ bool load_chunk(RemFile *f, uint64_t chunk_index, uint64_t chunks_needed)
"remfile: loading %" PRIu64 " chunks starting at %" PRIu64
" (%.3f million bytes)\n",
f->chunk_sequence_length, chunk_index,
(double)(data_end - data_start + 1) / 1e6);
static_cast<double>(data_end - data_start + 1) / 1e6);

std::vector<uint8_t> data;
if (!fetch_bytes(f, data_start, data_end, data))
Expand All @@ -306,12 +306,12 @@ bool load_chunk(RemFile *f, uint64_t chunk_index, uint64_t chunks_needed)
size_t piece_start = i * min_chunk;
size_t piece_end = std::min(piece_start + min_chunk, data.size());
f->chunks[chunk_index + i] =
std::vector<uint8_t>(data.begin() + piece_start, data.begin() + piece_end);
std::vector<uint8_t>(data.begin() + static_cast<std::ptrdiff_t>(piece_start), data.begin() + static_cast<std::ptrdiff_t>(piece_end));
f->chunk_order.push_back(chunk_index + i);
}
}
f->last_chunk_index_accessed =
(int64_t)(chunk_index + f->chunk_sequence_length - 1);
static_cast<int64_t>(chunk_index + f->chunk_sequence_length - 1);
return true;
}

Expand Down Expand Up @@ -347,7 +347,7 @@ bool remfile_read_bytes(RemFile *f, uint64_t position, size_t size, void *buf)
size_t written = 0;
for (uint64_t ci = chunk_start_index; ci <= chunk_end_index; ci++) {
const std::vector<uint8_t> &chunk = f->chunks[ci];
size_t chunk_offset = (ci == chunk_start_index) ? (size_t)(position % min_chunk) : 0;
size_t chunk_offset = (ci == chunk_start_index) ? static_cast<size_t>(position % min_chunk) : 0;
size_t chunk_length = std::min(chunk.size() - chunk_offset, size - written);
memcpy(out + written, chunk.data() + chunk_offset, chunk_length);
written += chunk_length;
Expand Down Expand Up @@ -450,7 +450,7 @@ herr_t remfile_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr)
haddr_t remfile_get_eof(const H5FD_t *_file, H5FD_mem_t type)
{
(void)type;
return (haddr_t) reinterpret_cast<const RemFile *>(_file)->length;
return static_cast<haddr_t>(reinterpret_cast<const RemFile *>(_file)->length);
}

herr_t remfile_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
Expand All @@ -459,7 +459,7 @@ herr_t remfile_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
(void)type;
(void)dxpl_id;
auto *f = reinterpret_cast<RemFile *>(_file);
return remfile_read_bytes(f, (uint64_t)addr, size, buf) ? 0 : -1;
return remfile_read_bytes(f, static_cast<uint64_t>(addr), size, buf) ? 0 : -1;
}

herr_t remfile_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
Expand Down
Loading