Skip to content

Commit

Permalink
fix compilation failure on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Oct 31, 2023
1 parent 5bb1b06 commit 8cb0f69
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 92 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

## [2.2.2] - 2023-10-31
### Fixed
- fix compilation failure on macOS

## [2.2.1] - 2023-10-31
### Fixed
- fix wraparound issue in simd implementation of Jaro and Jaro Winkler
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
endif()

project(rapidfuzz LANGUAGES CXX VERSION 2.2.1)
project(rapidfuzz LANGUAGES CXX VERSION 2.2.2)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(GNUInstallDirs)
Expand Down
36 changes: 25 additions & 11 deletions extras/rapidfuzz_amalgamated.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// RapidFuzz v1.0.2
// Generated: 2023-10-31 11:48:55.108653
// Generated: 2023-11-01 00:20:18.570286
// ----------------------------------------------------------
// This file is an amalgamation of multiple different files.
// You probably shouldn't edit it directly.
Expand Down Expand Up @@ -1629,6 +1629,24 @@ size_t remove_common_suffix(Range<InputIt1>& s1, Range<InputIt2>& s2);
template <typename InputIt, typename CharT = iter_value_t<InputIt>>
SplittedSentenceView<InputIt> sorted_split(InputIt first, InputIt last);

static inline void* rf_aligned_alloc(size_t alignment, size_t size)
{
#if defined(_WIN32)
return _aligned_malloc(size, alignment);
#else
return aligned_alloc(alignment, size);
#endif
}

static inline void rf_aligned_free(void* ptr)
{
#if defined(_WIN32)
_aligned_free(ptr);
#else
free(ptr);
#endif
}

/**@}*/

} // namespace rapidfuzz::detail
Expand Down Expand Up @@ -5823,15 +5841,12 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
assert(static_cast<size_t>(s2.size()) > sizeof(VecType) * 8);

struct AlignedAlloc {
AlignedAlloc(size_t size)
{
// work around compilation failure in msvc
memory = operator new[](size, std::align_val_t(native_simd<VecType>::alignment));
}
AlignedAlloc(size_t size) : memory(rf_aligned_alloc(native_simd<VecType>::alignment, size))
{}

~AlignedAlloc()
{
::operator delete[](memory, std::align_val_t(native_simd<VecType>::alignment));
rf_aligned_free(memory);
}

void* memory = nullptr;
Expand Down Expand Up @@ -6199,15 +6214,14 @@ struct MultiJaro : public detail::MultiSimilarityBase<MultiJaro<MaxLen>, double,
/* align for avx2 so we can directly load into avx2 registers */
str_lens_size = result_count();

// work around compilation failure in msvc
str_lens = static_cast<VecType*>(operator new[](sizeof(VecType) * str_lens_size,
std::align_val_t(get_vec_alignment())));
str_lens = static_cast<VecType*>(
detail::rf_aligned_alloc(get_vec_alignment(), sizeof(VecType) * str_lens_size));
std::fill(str_lens, str_lens + str_lens_size, VecType(0));
}

~MultiJaro()
{
::operator delete[](str_lens, std::align_val_t(get_vec_alignment()));
detail::rf_aligned_free(str_lens);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions rapidfuzz/details/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ size_t remove_common_suffix(Range<InputIt1>& s1, Range<InputIt2>& s2);
template <typename InputIt, typename CharT = iter_value_t<InputIt>>
SplittedSentenceView<InputIt> sorted_split(InputIt first, InputIt last);

static inline void* rf_aligned_alloc(size_t alignment, size_t size)
{
#if defined(_WIN32)
return _aligned_malloc(size, alignment);
#else
return aligned_alloc(alignment, size);
#endif
}

static inline void rf_aligned_free(void* ptr)
{
#if defined(_WIN32)
_aligned_free(ptr);
#else
free(ptr);
#endif
}


/**@}*/

} // namespace rapidfuzz::detail
Expand Down
5 changes: 2 additions & 3 deletions rapidfuzz/distance/Jaro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,15 @@ struct MultiJaro : public detail::MultiSimilarityBase<MultiJaro<MaxLen>, double,
/* align for avx2 so we can directly load into avx2 registers */
str_lens_size = result_count();

// work around compilation failure in msvc
str_lens = static_cast<VecType*>(
operator new[](sizeof(VecType) * str_lens_size, std::align_val_t(get_vec_alignment()))
detail::rf_aligned_alloc(get_vec_alignment(), sizeof(VecType) * str_lens_size)
);
std::fill(str_lens, str_lens + str_lens_size, VecType(0));
}

~MultiJaro()
{
::operator delete[] (str_lens, std::align_val_t(get_vec_alignment()));
detail::rf_aligned_free(str_lens);
}

/**
Expand Down
Loading

0 comments on commit 8cb0f69

Please sign in to comment.