Skip to content

Commit

Permalink
use _mm_malloc/_mm_free on macOS if aligned_alloc is unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Nov 2, 2023
1 parent 8cb0f69 commit 605a311
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 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.3] - 2023-11-02
### Fixed
- use _mm_malloc/_mm_free on macOS if aligned_alloc is unsupported

## [2.2.2] - 2023-10-31
### Fixed
- fix compilation failure on macOS
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.2)
project(rapidfuzz LANGUAGES CXX VERSION 2.2.3)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(GNUInstallDirs)
Expand Down
10 changes: 9 additions & 1 deletion 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-11-01 00:20:18.570286
// Generated: 2023-11-02 10:29:38.300883
// ----------------------------------------------------------
// This file is an amalgamation of multiple different files.
// You probably shouldn't edit it directly.
Expand Down Expand Up @@ -1567,6 +1567,10 @@ constexpr void unroll(F&& f)

#include <vector>

#if defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)
# include <mm_malloc.h>
#endif

namespace rapidfuzz::detail {

template <typename InputIt1, typename InputIt2, typename InputIt3>
Expand Down Expand Up @@ -1633,6 +1637,8 @@ static inline void* rf_aligned_alloc(size_t alignment, size_t size)
{
#if defined(_WIN32)
return _aligned_malloc(size, alignment);
#elif defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)
return _mm_malloc(size, alignment);
#else
return aligned_alloc(alignment, size);
#endif
Expand All @@ -1642,6 +1648,8 @@ static inline void rf_aligned_free(void* ptr)
{
#if defined(_WIN32)
_aligned_free(ptr);
#elif defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)
_mm_free(ptr);
#else
free(ptr);
#endif
Expand Down
8 changes: 8 additions & 0 deletions rapidfuzz/details/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <rapidfuzz/details/types.hpp>
#include <vector>

#if defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)
# include <mm_malloc.h>
#endif

namespace rapidfuzz::detail {

template <typename InputIt1, typename InputIt2, typename InputIt3>
Expand Down Expand Up @@ -79,6 +83,8 @@ static inline void* rf_aligned_alloc(size_t alignment, size_t size)
{
#if defined(_WIN32)
return _aligned_malloc(size, alignment);
#elif defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)
return _mm_malloc(size, alignment);
#else
return aligned_alloc(alignment, size);
#endif
Expand All @@ -88,6 +94,8 @@ static inline void rf_aligned_free(void* ptr)
{
#if defined(_WIN32)
_aligned_free(ptr);
#elif defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)
_mm_free(ptr);
#else
free(ptr);
#endif
Expand Down

0 comments on commit 605a311

Please sign in to comment.