[pkg-d-commits] [ldc] 01/12: use *W-functions if UNICODE #defined on windows

Matthias Klumpp mak at moszumanska.debian.org
Sun Apr 23 22:35:56 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v0.17.3
in repository ldc.

commit 5b0d93aecaa55972b92abac5ff811b8d81e1f4e7
Author: Rainer Schuetze <r.sagitario at gmx.de>
Date:   Tue Jun 28 08:15:34 2016 +0200

    use *W-functions if UNICODE #defined on windows
    
    (cherry picked from commit 9f85baee9051f45d89c9f433f38b0c5656c5f05c)
---
 driver/configfile.cpp | 17 +++++++++++++----
 driver/linker.cpp     | 11 ++++++++++-
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/driver/configfile.cpp b/driver/configfile.cpp
index 2418e91..88b5979 100644
--- a/driver/configfile.cpp
+++ b/driver/configfile.cpp
@@ -20,8 +20,10 @@
 #include <string>
 #if _WIN32
 #define WIN32_LEAN_AND_MEAN
+#include "llvm/Support/ConvertUTF.h"
 #include <windows.h>
 #include <shlobj.h>
+#include <tchar.h>
 // Prevent name clash with LLVM
 #undef GetCurrentDirectory
 #endif
@@ -55,16 +57,23 @@ static bool ReadPathFromRegistry(llvm::SmallString<128> &p) {
   HKEY hkey;
   bool res = false;
   // FIXME: Version number should be a define.
-  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\ldc-developers\\LDC\\0.11.0",
+  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\ldc-developers\\LDC\\0.11.0"),
                    NULL, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) {
     DWORD length;
-    if (RegGetValue(hkey, NULL, "Path", RRF_RT_REG_SZ, NULL, NULL, &length) ==
+    if (RegGetValue(hkey, NULL, _T("Path"), RRF_RT_REG_SZ, NULL, NULL, &length) ==
         ERROR_SUCCESS) {
-      char *data = static_cast<char *>(_alloca(length));
-      if (RegGetValue(hkey, NULL, "Path", RRF_RT_REG_SZ, NULL, data, &length) ==
+      TCHAR *data = static_cast<TCHAR *>(_alloca(length * sizeof(TCHAR)));
+      if (RegGetValue(hkey, NULL, _T("Path"), RRF_RT_REG_SZ, NULL, data, &length) ==
           ERROR_SUCCESS) {
+#if UNICODE
+        std::string out;
+        res = llvm::convertUTF16ToUTF8String(
+            llvm::ArrayRef<UTF16>(reinterpret_cast<UTF16 *>(data), length), out);
+        p = out;
+#else
         p = std::string(data);
         res = true;
+#endif
       }
     }
     RegCloseKey(hkey);
diff --git a/driver/linker.cpp b/driver/linker.cpp
index 6471162..7f2a7f5 100644
--- a/driver/linker.cpp
+++ b/driver/linker.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Support/Path.h"
 #if _WIN32
 #include "llvm/Support/SystemUtils.h"
+#include "llvm/Support/ConvertUTF.h"
 #include <Windows.h>
 #endif
 
@@ -348,9 +349,17 @@ int executeAndWait(const char *commandLine) {
 
   DWORD exitCode;
 
+#if UNICODE
+  std::wstring wcommandLine;
+  if (!llvm::ConvertUTF8toWide(commandLine, wcommandLine))
+    return -3;
+  auto cmdline = const_cast<wchar_t *>(wcommandLine.data());
+#else
+  auto cmdline = const_cast<char *>(commandLine);
+#endif
   // according to MSDN, only CreateProcessW (unicode) may modify the passed
   // command line
-  if (!CreateProcess(NULL, const_cast<char *>(commandLine), NULL, NULL, TRUE, 0,
+  if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0,
                      NULL, NULL, &si, &pi)) {
     exitCode = -1;
   } else {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list