forked from surge-synthesizer/surge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macOS: Switch to C++17 (like the other platforms) (surge-synthesizer#…
…5124) Library support is spotty on our current deployment target 10.11 "El Capitan", but a consistent language level across platforms does make life easier for devs, especially those who aren't on Mac. C++17 also fixes under-aligned allocations on ARM Macs, potentially improving performance. To keep us pre-Mojave compatible, this implements aligned operators new/delete in a new library "surge-platform" that will also become home for other platform-specific code currently lurking between #ifdefs.
- Loading branch information
Showing
8 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# vi:set sw=2 et: | ||
project(surge-platform) | ||
|
||
if(APPLE) | ||
add_library(${PROJECT_NAME}) | ||
target_sources(${PROJECT_NAME} PRIVATE macos/cpp17-aligned-new.cpp) | ||
else() | ||
# no sources yet on other platforms | ||
add_library(${PROJECT_NAME} INTERFACE) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
** Surge Synthesizer is Free and Open Source Software | ||
** | ||
** Surge is made available under the Gnu General Public License, v3.0 | ||
** https://www.gnu.org/licenses/gpl-3.0.en.html | ||
** | ||
** Copyright 2004-2021 by various individuals as described by the Git transaction log | ||
** | ||
** All source at: https://github.com/surge-synthesizer/surge.git | ||
** | ||
** Surge was a commercial product from 2004-2018, with Copyright and ownership | ||
** in that period held by Claes Johanson at Vember Audio. Claes made Surge | ||
** open source in September 2018. | ||
*/ | ||
|
||
#include <cstdlib> | ||
#include <new> | ||
|
||
/* | ||
* Since C++17, new'ing objects respects their alignas() requirements. If the required alignment | ||
* exceeds that provided by operator new, alignment-aware overloads are called instead. On macOS, | ||
* these are only present on 10.14 "Mojave" and up, so we ship our own implementation. | ||
* | ||
* Relevant discussion in GitHub issues #171, #188, #3589 | ||
*/ | ||
|
||
void *operator new(std::size_t size, std::align_val_t align) | ||
{ | ||
void *result; | ||
if (posix_memalign(&result, std::size_t(align), size)) | ||
throw std::bad_alloc{}; | ||
return result; | ||
} | ||
|
||
void operator delete(void *p, std::align_val_t) noexcept { free(p); } |