Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 9a25bb3

Browse files
authored
Merge e8a1a23 into 99842ba
2 parents 99842ba + e8a1a23 commit 9a25bb3

7 files changed

Lines changed: 63 additions & 43 deletions

File tree

‎include/dxc/Support/dxcapi.use.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DxcDllSupport {
2828
::dlclose(handle);
2929
}
3030
HMODULE LoadLibraryW(LPCWSTR name) {
31-
return ::dlopen(CW2A(name).c_str(), RTLD_LAZY);
31+
return ::dlopen(CW2A(name).m_psz, RTLD_LAZY);
3232
}
3333
HMODULE GetProcAddress(HMODULE dll, LPCSTR fnName) {
3434
return ::dlsym(dll, fnName);

‎include/llvm/Support/WinMacros.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
#define vsprintf_s vsprintf
112112
#define strcat_s strcat
113113

114-
#define OutputDebugStringW(msg) fprintf(stdout, CW2A(msg).c_str())
114+
#define OutputDebugStringW(msg) fprintf(stdout, CW2A(msg).m_psz)
115115
#define OutputDebugFormatA(...) fprintf(stdout, __VA_ARGS__)
116116

117117
// Note: This will *disable* the CRITICAL_SECTION structures in the code.

‎include/llvm/Support/WinTypes.h‎

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -433,28 +433,69 @@ class CSimpleArray : public std::vector<T> {
433433
#define IsEqualIID(a, b) a==b
434434
#define IsEqualCLSID(a, b) !memcmp(&a, &b, sizeof(GUID))
435435

436-
class CW2A {
437-
public:
438-
CW2A(const wchar_t *wide, uint32_t utf = 0) {
439-
(void)utf;
440-
size_t len = wcslen(wide) + 1; // +1 for '\0'
441-
m_psz = (char*) malloc(len * sizeof(char));
442-
wcstombs(m_psz, wide, len);
443-
m_psz[len-1] = '\0';
444-
}
445-
~CW2A() {
446-
free(m_psz);
436+
template< int t_nBufferLength = 128 >
437+
class CW2AEX
438+
{
439+
public:
440+
CW2AEX( LPCWSTR psz , UINT nCodePage = CP_UTF8)
441+
{
442+
if (nCodePage != CP_UTF8) {
443+
// you have reached the limits of this half-assed implementation. So sorry.
444+
m_psz = NULL;
445+
return;
446+
}
447+
448+
if (!psz) {
449+
m_psz = NULL;
450+
return;
451+
}
452+
453+
int len = wcslen(psz)*4;
454+
m_psz = new char[len];
455+
std::wcstombs(m_psz, psz, len);
447456
}
448-
const char* c_str() const { return m_psz; }
449-
operator const char*() const { return m_psz; }
450457

451-
public:
458+
~CW2AEX() { delete [] m_psz; }
459+
460+
operator LPSTR() const { return m_psz; }
461+
452462
char *m_psz;
463+
char m_szBuffer[t_nBufferLength]; // dunno what this is for
464+
465+
};
466+
typedef CW2AEX<> CW2A;
467+
468+
template< int t_nBufferLength = 128 >
469+
class CA2WEX
470+
{
471+
public:
472+
CA2WEX( LPCSTR psz, UINT nCodePage = CP_UTF8 )
473+
{
474+
if (nCodePage != CP_UTF8) {
475+
// you have reached the limits of this half-assed implementation. So sorry.
476+
m_psz = NULL;
477+
return;
478+
}
479+
480+
if (!psz) {
481+
m_psz = NULL;
482+
return;
483+
}
484+
485+
int len = strlen(psz) + 1;
486+
m_psz = new wchar_t[len];
487+
std::mbstowcs(m_psz, psz, len);
488+
}
489+
490+
~CA2WEX() { delete [] m_psz; }
491+
492+
operator LPWSTR() const { return m_psz; }
493+
494+
wchar_t *m_psz;
495+
wchar_t m_szBuffer[t_nBufferLength];
453496

454-
private:
455-
CW2A operator=(const CW2A&) = delete;
456-
CW2A(const CW2A&) = delete;
457497
};
498+
typedef CA2WEX<> CA2W;
458499

459500
template <class T, class Allocator = CAllocator>
460501
class CHeapPtrBase

‎lib/DxcSupport/FileIOHelper.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void ReadBinaryFile(IMalloc *pMalloc, LPCWSTR pFileName, void **ppData,
130130

131131
#else
132132
// Open file
133-
std::ifstream ifs(CW2A(pFileName).c_str(), std::ios::binary|std::ios::ate);
133+
std::ifstream ifs(CW2A(pFileName).m_psz, std::ios::binary|std::ios::ate);
134134
if(ifs.fail()) {
135135
fprintf(stderr, "The system cannot file the file specified:");
136136
throw ::hlsl::Exception(GetLastError());

‎lib/DxcSupport/dxcapi.use.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void WriteBlobToFile(_In_opt_ IDxcBlob *pBlob, _In_ LPCWSTR pFileName) {
118118
IFT_Data(HRESULT_FROM_WIN32(GetLastError()), pFileName);
119119
}
120120
#else
121-
std::ofstream outputFile (CW2A(pFileName).c_str(), std::ios::out | std::ios::binary);
121+
std::ofstream outputFile (CW2A(pFileName).m_psz, std::ios::out | std::ios::binary);
122122
void *file = static_cast<void*>(&outputFile);
123123
#endif
124124
WriteBlobToHandle(pBlob, file, pFileName);

‎tools/clang/lib/Sema/SemaHLSL.cpp‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,21 +2203,9 @@ class IntrinsicTableDefIter
22032203

22042204
_firstChecked = true;
22052205

2206-
#ifdef LLVM_ON_WIN32 // SPIRV change
22072206
// TODO: review this - this will allocate at least once per string
22082207
CA2WEX<> typeName(_typeName.str().c_str(), CP_UTF8);
22092208
CA2WEX<> functionName(_functionName.str().c_str(), CP_UTF8);
2210-
// SPIRV change starts
2211-
#else
2212-
// Need to use mbstowcs as we don'thave CA2WEX.
2213-
const char* typeNameUtf8 = _typeName.str().c_str();
2214-
const char* functionNameUtf8 = _functionName.str().c_str();
2215-
wchar_t typeName[80];
2216-
wchar_t functionName[80];
2217-
std::mbstowcs(typeName, typeNameUtf8, strlen(typeNameUtf8) + 1);
2218-
std::mbstowcs(functionName, functionNameUtf8, strlen(functionNameUtf8) + 1);
2219-
#endif
2220-
// SPIRV change ends
22212209

22222210
if (FAILED(_tables[_tableIndex]->LookupIntrinsic(
22232211
typeName, functionName, &_tableIntrinsic, &_tableLookupCookie))) {
@@ -3490,17 +3478,8 @@ class HLSLExternalSource : public ExternalSemaSource {
34903478
const HLSL_INTRINSIC *pIntrinsic = nullptr;
34913479
const HLSL_INTRINSIC *pPrior = nullptr;
34923480
UINT64 lookupCookie = 0;
3493-
#ifdef LLVM_ON_WIN32 // SPIRV change
34943481
CA2W wideTypeName(typeName);
34953482
HRESULT found = table->LookupIntrinsic(wideTypeName, L"*", &pIntrinsic, &lookupCookie);
3496-
// SPIRV change starts
3497-
#else
3498-
// Need to use mbstowcs as we don'thave CA2WEX.
3499-
wchar_t wideTypeName[80];
3500-
std::mbstowcs(wideTypeName, typeName, strlen(typeName) + 1);
3501-
HRESULT found = table->LookupIntrinsic(wideTypeName, L"*", &pIntrinsic, &lookupCookie);
3502-
#endif
3503-
// SPIRV change ends
35043483
while (pIntrinsic != nullptr && SUCCEEDED(found)) {
35053484
if (!AreIntrinsicTemplatesEquivalent(pIntrinsic, pPrior)) {
35063485
AddObjectIntrinsicTemplate(recordDecl, startDepth, pIntrinsic);

‎tools/clang/tools/dxc/dxc.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ void DxcContext::WriteHeader(IDxcBlobEncoding *pDisassembly, IDxcBlob *pCode,
939939
IFT_Data(HRESULT_FROM_WIN32(GetLastError()), pFileName);
940940
}
941941
#else
942-
std::ofstream outputFile (CW2A(pFileName).c_str(), std::ios::out | std::ios::binary);
942+
std::ofstream outputFile (CW2A(pFileName).m_psz, std::ios::out | std::ios::binary);
943943
void *file = static_cast<void*>(&outputFile);
944944
#endif
945945

0 commit comments

Comments
 (0)