From 78ea641c5d4a41341efb0cf2544e557f7619aa28 Mon Sep 17 00:00:00 2001 From: Narek Galstyan Date: Sun, 14 Jan 2024 03:46:17 +0000 Subject: [PATCH 1/3] Add move construction tests and fix an issue caused by them --- cpp/test.cpp | 11 +++++++++-- include/usearch/index_plugins.hpp | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cpp/test.cpp b/cpp/test.cpp index d32e2986..aa9b0c56 100644 --- a/cpp/test.cpp +++ b/cpp/test.cpp @@ -209,7 +209,14 @@ void test_cosine(std::size_t collection_size, std::size_t dimensions) { metric_punned_t metric(dimensions, metric_kind_t::cos_k, scalar_kind()); index_dense_config_t config(connectivity); config.multi = multi; - index_t index = index_t::make(metric, config); + index_t index; + { + index_t index_tmp1 = index_t::make(metric, config); + // move construction + index_t index_tmp2 = std::move(index_tmp1); + // move assignment + index = std::move(index_tmp2); + } test_cosine(index, matrix); } } @@ -313,4 +320,4 @@ int main(int, char**) { test_tanimoto(dimensions, connectivity); return 0; -} \ No newline at end of file +} diff --git a/include/usearch/index_plugins.hpp b/include/usearch/index_plugins.hpp index 061fc5f5..660d9d52 100644 --- a/include/usearch/index_plugins.hpp +++ b/include/usearch/index_plugins.hpp @@ -1819,7 +1819,8 @@ class flat_hash_multi_set_gt { } // Reset populated slots count - std::memset(data_, 0, buckets_ * bytes_per_bucket()); + if (data_) + std::memset(data_, 0, buckets_ * bytes_per_bucket()); populated_slots_ = 0; } From aafff91bf52e4e151e0b1487724113d38aa4729a Mon Sep 17 00:00:00 2001 From: Narek Galstyan Date: Tue, 9 Jan 2024 03:30:16 +0000 Subject: [PATCH 2/3] Only consider zero length IO an error if input buffer was larger than zero --- include/usearch/index.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/usearch/index.hpp b/include/usearch/index.hpp index 86e523ea..e5616c15 100644 --- a/include/usearch/index.hpp +++ b/include/usearch/index.hpp @@ -1362,7 +1362,7 @@ class output_file_t { serialization_result_t write(void const* begin, std::size_t length) noexcept { serialization_result_t result; std::size_t written = std::fwrite(begin, length, 1, file_); - if (!written) + if (length && !written) return result.failed(std::strerror(errno)); return result; } @@ -1404,7 +1404,7 @@ class input_file_t { serialization_result_t read(void* begin, std::size_t length) noexcept { serialization_result_t result; std::size_t read = std::fread(begin, length, 1, file_); - if (!read) + if (length && !read) return result.failed(std::feof(file_) ? "End of file reached!" : std::strerror(errno)); return result; } From 3731149c9d7d680181addd2bc283c513a9272b11 Mon Sep 17 00:00:00 2001 From: Narek Galstyan Date: Thu, 11 Jan 2024 04:15:25 +0000 Subject: [PATCH 3/3] Move option-override policy opt-in before policy definitions so overrides actually take effect --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dde10cc9..d058470a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,11 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(USEARCH_IS_MAIN_PROJECT ON) endif () +# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory +if (POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif () + # Options option(USEARCH_INSTALL "Install CMake targets" OFF) @@ -31,11 +36,6 @@ option(USEARCH_BUILD_WOLFRAM "Compile Wolfram Language bindings" OFF) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) include(ExternalProject) -# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory -if (POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif () - # Configuration include(GNUInstallDirs) set(USEARCH_TARGET_NAME ${PROJECT_NAME})