Skip to content

Commit 609aea8

Browse files
authored
Merge pull request #3054 from compnerd/aligned-malloc-windows
Basic: support `_aligned_malloc` on Windows
2 parents 4cd1222 + 1aee71a commit 609aea8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

include/swift/Basic/Malloc.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,33 @@
2323

2424
namespace swift {
2525

26-
// FIXME: Use C11 aligned_alloc or Windows _aligned_malloc if available.
26+
// FIXME: Use C11 aligned_alloc if available.
2727
inline void *AlignedAlloc(size_t size, size_t align) {
2828
// posix_memalign only accepts alignments greater than sizeof(void*).
2929
//
3030
if (align < sizeof(void*))
3131
align = sizeof(void*);
3232

3333
void *r;
34+
#if defined(_WIN32)
35+
r = _aligned_malloc(size, align);
36+
assert(r && "_aligned_malloc failed");
37+
#else
3438
int res = posix_memalign(&r, align, size);
3539
assert(res == 0 && "posix_memalign failed");
3640
(void)res; // Silence the unused variable warning.
41+
#endif
3742
return r;
3843
}
39-
40-
// FIXME: Use Windows _aligned_free if available.
44+
4145
inline void AlignedFree(void *p) {
46+
#if defined(_WIN32)
47+
_aligned_free(p);
48+
#else
4249
free(p);
50+
#endif
4351
}
44-
52+
4553
} // end namespace swift
4654

4755
#endif // SWIFT_BASIC_MALLOC_H

0 commit comments

Comments
 (0)