]> git.sesse.net Git - stockfish/commitdiff
Improve compatibility
authorMaxim Masiutin <maxim@masiutin.com>
Sun, 12 Mar 2023 13:16:51 +0000 (15:16 +0200)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Sat, 1 Apr 2023 13:36:08 +0000 (15:36 +0200)
this makes it easier to compile under MSVC, even though we recommend gcc/clang for production compiles at the moment.

In Win32 API, by default, most null-terminated character strings arguments are of wchar_t (UTF16, formerly UCS16-LE) type, i.e. 2 bytes (at least) per character. So, src/misc.cpp should have proper type. Respectively, for src/syzygy/tbprobe.cpp, in Widows, file paths should be std::wstring rather than std::string. However, this requires a very big number of changes, since the config files are also keeping the 8-bit-per-character std::string strings. Therefore, just one change of using 8-byte-per-character CreateFileA make it compile under MSVC.

closes https://github.com/official-stockfish/Stockfish/pull/4438

No functional change

src/misc.cpp
src/syzygy/tbprobe.cpp

index c22126afe2de45a195ead46b9369e27231dddf8f..6469c5cf9eca24edbd8b9579951bce9d9b07bf84 100644 (file)
@@ -605,7 +605,7 @@ static int best_node(size_t idx) {
   DWORD byteOffset = 0;
 
   // Early exit if the needed API is not available at runtime
-  HMODULE k32 = GetModuleHandle("Kernel32.dll");
+  HMODULE k32 = GetModuleHandle(TEXT("Kernel32.dll"));
   auto fun1 = (fun1_t)(void(*)())GetProcAddress(k32, "GetLogicalProcessorInformationEx");
   if (!fun1)
       return -1;
@@ -675,7 +675,7 @@ void bindThisThread(size_t idx) {
       return;
 
   // Early exit if the needed API are not available at runtime
-  HMODULE k32 = GetModuleHandle("Kernel32.dll");
+  HMODULE k32 = GetModuleHandle(TEXT("Kernel32.dll"));
   auto fun2 = (fun2_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
   auto fun3 = (fun3_t)(void(*)())GetProcAddress(k32, "SetThreadGroupAffinity");
   auto fun4 = (fun4_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMask2");
index b594ac3714e5cf3e853289ebd09f0be03f1bd22b..9cb0bfdbc0fa4f1e416c2c0cb3ad240d66a00461 100644 (file)
@@ -234,7 +234,7 @@ public:
         }
 #else
         // Note FILE_FLAG_RANDOM_ACCESS is only a hint to Windows and as such may get ignored.
-        HANDLE fd = CreateFile(fname.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
+        HANDLE fd = CreateFileA(fname.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
                                OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, nullptr);
 
         if (fd == INVALID_HANDLE_VALUE)