[libcxx-commits] [PATCH] D138196: [libc++] Use aligned_alloc instead of posix_memalign for C++17
Alexander Richardson via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 17 03:29:21 PST 2022
arichardson created this revision.
arichardson added reviewers: libc++, michaelplatings.
Herald added a project: All.
arichardson requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.
C++17 defines the C11 aligned_alloc, so we can use that instead of
posix_memalign. This change allows building against picolibc without
defining _DEFAULT_SOURCE/_GNU_SOURCE.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138196
Files:
libcxx/include/new
Index: libcxx/include/new
===================================================================
--- libcxx/include/new
+++ libcxx/include/new
@@ -341,6 +341,8 @@
void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) {
#if defined(_LIBCPP_MSVCRT_LIKE)
return ::_aligned_malloc(__size, __alignment);
+#elif _LIBCPP_STD_VER > 14
+ return ::aligned_alloc(__alignment, __size);
#else
void* __result = nullptr;
(void)::posix_memalign(&__result, __alignment, __size);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138196.476076.patch
Type: text/x-patch
Size: 492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221117/4f13944f/attachment.bin>
More information about the libcxx-commits
mailing list