Skip to content

Commit

Permalink
WinAdapter: Export symbols for CoTaskMem{Alloc,Free}
Browse files Browse the repository at this point in the history
Some functions return lists allocated with CoTaskMemAlloc.  Applications
using libdxcompiler.so currently have to look into the code to
understand that these should be deallocated with free() instead of
delete[].  Export the CoTaskMemFree function so that there is no
guesswork involved anymore: the application can now call this function
and always free it in the right way.
  • Loading branch information
MarijnS95 committed May 22, 2021
1 parent 9200fff commit 3c42468
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/dxc/Support/WinAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
#define C_ASSERT(expr) static_assert((expr), "")
#define ATLASSERT assert

#define CoTaskMemAlloc malloc
#define CoTaskMemFree free

#define ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))

#define _countof(a) (sizeof(a) / sizeof(*(a)))
Expand Down Expand Up @@ -946,6 +943,11 @@ extern "C" DXC_API_IMPORT BSTR __stdcall SysAllocStringLen(const OLECHAR *strIn,
extern "C" DXC_API_IMPORT UINT __stdcall SysStringByteLen(BSTR bstr);
extern "C" DXC_API_IMPORT UINT __stdcall SysStringLen(BSTR pbstr);

//===-------------------------- CoTask Allocation -------------------------===//

extern "C" DXC_API_IMPORT LPVOID __stdcall CoTaskMemAlloc(SIZE_T cb);
extern "C" DXC_API_IMPORT void __stdcall CoTaskMemFree(LPVOID pv);

//===--------------------- UTF-8 Related Types ----------------------------===//

// Code Page
Expand Down
6 changes: 6 additions & 0 deletions lib/DxcSupport/WinAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ DXC_API_IMPORT UINT __stdcall SysStringLen(BSTR pbstr) {
return SysStringByteLen(pbstr) / 4;
}

//===-------------------------- CoTask Allocation -------------------------===//

DXC_API_IMPORT LPVOID __stdcall CoTaskMemAlloc(SIZE_T cb) { return malloc(cb); }

DXC_API_IMPORT void __stdcall CoTaskMemFree(LPVOID pv) { free(pv); }

//===---------------------- Char converstion ------------------------------===//

const char *CPToLocale(uint32_t CodePage) {
Expand Down

0 comments on commit 3c42468

Please sign in to comment.