Skip to content

Commit 093ec70

Browse files
author
Stephen Gutekanst
committed
use correct COM allocator on windows GNU targets
Signed-off-by: Stephen Gutekanst <[email protected]>
1 parent aa7c5db commit 093ec70

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

include/dxc/WinAdapter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
//===----------------------------------------------------------------------===//
5757
// Mach change start
5858
// #define C_ASSERT(expr) static_assert((expr), "")
59+
#define CoTaskMemRealloc realloc
5960
// Mach change end
6061
#define ATLASSERT assert
6162

lib/DxcSupport/WinAdapter.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,23 @@
2828

2929
//===--------------------------- CAllocator -------------------------------===//
3030

31+
// Mach change start
32+
// void *CAllocator::Reallocate(void *p, size_t nBytes) throw() {
33+
// return realloc(p, nBytes);
34+
// }
35+
// void *CAllocator::Allocate(size_t nBytes) throw() { return malloc(nBytes); }
36+
// void CAllocator::Free(void *p) throw() { free(p); }
37+
38+
// In ZigGNUWinAdapter we make use of CAllocator, and it needs to interop with the real
39+
// Windows COM API and use the same underlying allocator. So we redirect these allocations
40+
// to CoTaskMem* in all cases. On macOS/Linux these are just redirected to malloc/free
41+
// anyway in WinAdapter.h
3142
void *CAllocator::Reallocate(void *p, size_t nBytes) throw() {
32-
return realloc(p, nBytes);
43+
return CoTaskMemRealloc(p, nBytes);
3344
}
34-
void *CAllocator::Allocate(size_t nBytes) throw() { return malloc(nBytes); }
35-
void CAllocator::Free(void *p) throw() { free(p); }
45+
void *CAllocator::Allocate(size_t nBytes) throw() { return CoTaskMemAlloc(nBytes); }
46+
void CAllocator::Free(void *p) throw() { CoTaskMemFree(p); }
47+
// Mach change end
3648

3749
// Mach change start
3850
#ifndef _WIN32

0 commit comments

Comments
 (0)