From 4b23645c1ccff7cbd4d8bb8e01fb950efd295ad2 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Tue, 25 Dec 2018 22:15:51 +0100 Subject: [PATCH 01/26] Protect buffer underflow Path could be shorted than 4 chars eventually... --- platforms/win32/vm/sqWin32Directory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/win32/vm/sqWin32Directory.c b/platforms/win32/vm/sqWin32Directory.c index a015172dca..29ade7a49a 100644 --- a/platforms/win32/vm/sqWin32Directory.c +++ b/platforms/win32/vm/sqWin32Directory.c @@ -49,7 +49,7 @@ static void read_permissions(sqInt *posixPermissions, WCHAR* path, sqInt pathLen if (attr & FILE_ATTRIBUTE_DIRECTORY) { *posixPermissions |= S_IXUSR | (S_IXUSR>>3) | (S_IXUSR>>6); } - else if (path && path[pathLength - 4] == L'.') { + else if (path && pathLength > 3 && path[pathLength - 4] == L'.') { WCHAR *ext = &path[pathLength - 3]; if (!_wcsicmp (ext, L"COM")) { *posixPermissions |= S_IXUSR | (S_IXUSR>>3) | (S_IXUSR>>6); From e9bfeefc03b7a908b2925a9c474a59b9b9ad7d1b Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Tue, 25 Dec 2018 22:18:28 +0100 Subject: [PATCH 02/26] Make icon setting 64bits compatible Casting the icon handle (size of a pointer) to LONG (32 bits) is not 64bits friendly --- .../win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c b/platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c index c9d0af6ff9..880a81e3f4 100644 --- a/platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c +++ b/platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c @@ -423,7 +423,7 @@ sqInt ioSetIconOfWindow(sqInt windowIndex, char * iconPath, sqInt sizeOfPath) { HICON hIcon = (HICON)LoadImage(NULL, iconPath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); if (hIcon == 0) return -2; - SendMessage(hwnd, WM_SETICON, ICON_BIG, (LONG)hIcon); + SendMessage(hwnd, WM_SETICON, ICON_BIG, (LONG_PTR)hIcon); return 0; } From 8df05ee8a333d24e76d7956a9ef4d73bd120b4bb Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Tue, 25 Dec 2018 22:23:39 +0100 Subject: [PATCH 03/26] remove a warning about a control path not returning a value --- platforms/Cross/plugins/B3DAcceleratorPlugin/sqOpenGLRenderer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/platforms/Cross/plugins/B3DAcceleratorPlugin/sqOpenGLRenderer.c b/platforms/Cross/plugins/B3DAcceleratorPlugin/sqOpenGLRenderer.c index 19590c3e0c..099cac0ce8 100644 --- a/platforms/Cross/plugins/B3DAcceleratorPlugin/sqOpenGLRenderer.c +++ b/platforms/Cross/plugins/B3DAcceleratorPlugin/sqOpenGLRenderer.c @@ -119,6 +119,7 @@ print3Dlog(char *fmt, ...) va_end(args); if (forceFlush) /* from sqOpenGLRenderer.h */ fflush(logfile); + return 0; } /*****************************************************************************/ From b2a8bd8d8beddebbcb128c5b39740e8a94c16763 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Tue, 25 Dec 2018 23:50:49 +0100 Subject: [PATCH 04/26] Use TEXT macro for generic (ASCII or WIDE) string method We should either use - explicit ASCII variant with ASCII String constant `CertOpenSystemStoreA(0 , "MY")` - explicit WIDE variant with Wide String constant `CertOpenSystemStoreW(0 , L"MY")` - generic variant with generic TEXT constant `CertOpenSystemStore(0 , TEXT("MY"))` But we should not mix usage of whatever variant function with whatever variant String.
See https://docs.microsoft.com/en-us/windows/desktop/api/winnt/nf-winnt-text Otherwise, in absence of `-DUNICODE`compiler flag, the compiler barks: ../../platforms/win32/plugins/SqueakSSL/sqWin32SSL.c:176:35: warning: incompatible pointer types passing 'unsigned short [3]' to parameter of type 'LPCSTR' (aka 'const char *') [-Wincompatible-pointer-types] hStore = CertOpenSystemStore(0, L"MY"); ^~~~~ /usr/x86_64-w64-mingw32/sys-root/mingw/include/wincrypt.h:4432:83: note: passing argument to parameter 'szSubsystemProtocol' here WINIMPM HCERTSTORE WINAPI CertOpenSystemStoreA (HCRYPTPROV_LEGACY hProv, LPCSTR szSubsystemProtocol); --- platforms/win32/plugins/SqueakSSL/sqWin32SSL.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platforms/win32/plugins/SqueakSSL/sqWin32SSL.c b/platforms/win32/plugins/SqueakSSL/sqWin32SSL.c index 2fc543f55c..79eb870e3d 100644 --- a/platforms/win32/plugins/SqueakSSL/sqWin32SSL.c +++ b/platforms/win32/plugins/SqueakSSL/sqWin32SSL.c @@ -173,7 +173,7 @@ static sqInt sqSetupCert(sqSSL *ssl, char *certName, int server) { char bFriendlyName[MAX_NAME_SIZE]; if(certName) { - hStore = CertOpenSystemStore(0, L"MY"); + hStore = CertOpenSystemStore(0, TEXT("MY")); if(!hStore) { if(ssl->loglevel) printf("sqSetupCert: CertOpenSystemStore failed\n"); return 0; @@ -923,7 +923,7 @@ static sqInt sqAddPfxCertToStore(char *pfxData, sqInt pfxLen, char *passData, sq if(!pfxStore) return 0; /* And copy the certificates to MY store */ - myStore = CertOpenSystemStore(0, L"MY"); + myStore = CertOpenSystemStore(0, TEXT("MY")); pContext = NULL; while(pContext = CertEnumCertificatesInStore(pfxStore, pContext)) { CertAddCertificateContextToStore(myStore, pContext, CERT_STORE_ADD_REPLACE_EXISTING, NULL); From a08c1fec2bd75375e5c389eb5e0b706eaa62c82f Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Wed, 26 Dec 2018 00:13:56 +0100 Subject: [PATCH 05/26] Provides a high resolution clock for MSVC See https://msdn.microsoft.com/en-us/library/ms644904(v=VS.85).aspx --- platforms/win32/vm/sqWin32Heartbeat.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platforms/win32/vm/sqWin32Heartbeat.c b/platforms/win32/vm/sqWin32Heartbeat.c index 707c4474f1..42ad5a6e47 100644 --- a/platforms/win32/vm/sqWin32Heartbeat.c +++ b/platforms/win32/vm/sqWin32Heartbeat.c @@ -65,6 +65,11 @@ sqLong ioHighResClock(void) { : "=a" (value) : : "rdx"); +#elif defined(_MSC_VER) + LARGE_INTEGER aux; + aux.QuadPart = 0; + QueryPerformanceCounter(&aux); + value = aux.QuadPart; #else # error "no high res clock defined" #endif From 57d09aebf6b45f6b2cce6659f70946e8c9a38d2c Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Wed, 26 Dec 2018 00:27:23 +0100 Subject: [PATCH 06/26] Define some UNIX constants in sqWin32Directory.c, MSVC oblige the unix constants S_IRUSR are not defined in MSVC. Pick the workaround from platforms/minheadless/windows/sqWin32Directory.c --- platforms/win32/vm/sqWin32Directory.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/platforms/win32/vm/sqWin32Directory.c b/platforms/win32/vm/sqWin32Directory.c index 29ade7a49a..e41b625304 100644 --- a/platforms/win32/vm/sqWin32Directory.c +++ b/platforms/win32/vm/sqWin32Directory.c @@ -19,6 +19,17 @@ # include # include +/** + * Posix permissions are not defined in Windows, except when using + * Mingw or Cygwin. Since these constants are just standard, we define + * them for our purpose of emulating permissions. + */ +#ifndef S_IRUSR +#define S_IRUSR 0400 +#define S_IWUSR 0200 +#define S_IXUSR 0100 +#endif + extern struct VirtualMachine *interpreterProxy; #define FAIL() { return interpreterProxy->primitiveFail(); } From ad71bd01659a5b909a2f744361a660c6a53a00b3 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Wed, 26 Dec 2018 01:39:00 +0100 Subject: [PATCH 07/26] Remove a few printf warnings --- platforms/win32/plugins/SqueakSSL/sqWin32SSL.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/platforms/win32/plugins/SqueakSSL/sqWin32SSL.c b/platforms/win32/plugins/SqueakSSL/sqWin32SSL.c index 79eb870e3d..580235674f 100644 --- a/platforms/win32/plugins/SqueakSSL/sqWin32SSL.c +++ b/platforms/win32/plugins/SqueakSSL/sqWin32SSL.c @@ -102,7 +102,7 @@ static void sqPrintSBD(char *title, SecBufferDesc sbd) { printf("%s\n", title); for(i=0; iBufferType, buf->cbBuffer, (int)buf->pvBuffer); + printf("\tbuf[%d]: %d (%d bytes) ptr=%"PRIxSQPTR"\n", i,buf->BufferType, buf->cbBuffer, (sqIntptr_t)buf->pvBuffer); } } @@ -505,7 +505,7 @@ sqInt sqConnectSSL(sqInt handle, char* srcBuf, sqInt srcLen, char *dstBuf, sqInt if (!ssl->dataBuf) return SQSSL_OUT_OF_MEMORY; } if(ssl->loglevel) - printf("sqConnectSSL: input token %d bytes\n", srcLen); + printf("sqConnectSSL: input token %" PRIdSQINT " bytes\n", srcLen); memcpy(ssl->dataBuf + ssl->dataLen, srcBuf, srcLen); ssl->dataLen += srcLen; @@ -737,7 +737,7 @@ sqInt sqEncryptSSL(sqInt handle, char* srcBuf, sqInt srcLen, char *dstBuf, sqInt if(ssl == NULL || ssl->state != SQSSL_CONNECTED) return SQSSL_INVALID_STATE; - if(ssl->loglevel) printf("sqEncryptSSL: Encrypting %d bytes\n", srcLen); + if(ssl->loglevel) printf("sqEncryptSSL: Encrypting %" PRIdSQINT " bytes\n", srcLen); if(srcLen > (int)ssl->sslSizes.cbMaximumMessage) return SQSSL_INPUT_TOO_LARGE; @@ -810,7 +810,7 @@ sqInt sqDecryptSSL(sqInt handle, char* srcBuf, sqInt srcLen, char *dstBuf, sqInt ssl->dataBuf = realloc(ssl->dataBuf, ssl->dataMax); if(!ssl->dataBuf) return SQSSL_OUT_OF_MEMORY; } - if(ssl->loglevel) printf("sqDecryptSSL: Input data %d bytes\n", srcLen); + if(ssl->loglevel) printf("sqDecryptSSL: Input data %" PRIdSQINT " bytes\n", srcLen); memcpy(ssl->dataBuf + ssl->dataLen, srcBuf, srcLen); ssl->dataLen += srcLen; @@ -847,7 +847,7 @@ sqInt sqDecryptSSL(sqInt handle, char* srcBuf, sqInt srcLen, char *dstBuf, sqInt int buftype = ssl->inbuf[i].BufferType; int count = ssl->inbuf[i].cbBuffer; char *buffer = ssl->inbuf[i].pvBuffer; - if(ssl->loglevel) printf("buf[%d]: %d (%d bytes) ptr=%x\n", i,buftype, count, (int)buffer); + if(ssl->loglevel) printf("buf[%d]: %d (%d bytes) ptr=%"PRIxSQPTR"\n", i,buftype, count, (sqIntptr_t)buffer); if(buftype == SECBUFFER_DATA) { if(count > dstLen) return SQSSL_BUFFER_TOO_SMALL; memcpy(dstBuf, buffer, count); @@ -1014,7 +1014,7 @@ sqInt sqSetIntPropertySSL(sqInt handle, sqInt propID, sqInt propValue) { switch(propID) { case SQSSL_PROP_LOGLEVEL: ssl->loglevel = propValue; break; default: - if(ssl->loglevel) printf("sqSetIntPropertySSL: Unknown property ID %d\n", propID); + if(ssl->loglevel) printf("sqSetIntPropertySSL: Unknown property ID %" PRIdSQINT "\n", propID); return 0; } return 1; From 8c04d9af6c308207399849a516aaf91d1b5f33e8 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Wed, 26 Dec 2018 02:06:35 +0100 Subject: [PATCH 08/26] Prefer DirectX8 in MSVC Note that support for DirectX-7 is not available after 2007 SDK!!! https://blogs.msdn.microsoft.com/chuckw/2012/08/21/directx-sdks-of-a-certain-age/ We are showing our age... cygwin still provide support files for DirectX-7, but DirectX-8 does not compile out of the box, so stick to 7 outside MSVC. --- platforms/win32/vm/sqWin32DirectInput.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platforms/win32/vm/sqWin32DirectInput.c b/platforms/win32/vm/sqWin32DirectInput.c index 864e331d63..d6d01ee792 100755 --- a/platforms/win32/vm/sqWin32DirectInput.c +++ b/platforms/win32/vm/sqWin32DirectInput.c @@ -23,7 +23,11 @@ #ifndef NO_DIRECTINPUT #ifndef DIRECTINPUT_VERSION -#define DIRECTINPUT_VERSION 0x700 /* restrict to DX7 */ +#ifdef _MSC_VER +#define DIRECTINPUT_VERSION 0x800 /* DX8 */ +#else +#define DIRECTINPUT_VERSION 0x700 /* use DX7 via mingw/cygwin */ +#endif #endif #include From e0d70a91864eca8f72947fe36d1865785482ed2e Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 12:10:34 +0100 Subject: [PATCH 09/26] Workaround S_ISFIFO to let MSVC compile FilePlugin Note: there is a possibility to create named pipe in windows https://docs.microsoft.com/en-us/windows/desktop/ipc/named-pipes But named pipes cannot be intermixed with regular files. They are mounted on special named pipe file system (NPFS) https://stackoverflow.com/questions/21139790/where-on-windows-a-named-pipe-file-is-stored So I think that answering false to the query is a good solution. --- platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c b/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c index 0f2d6feb46..df604fb65e 100755 --- a/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c +++ b/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c @@ -40,6 +40,12 @@ #include #include +#ifdef _MSC_VER +#ifndef S_ISFIFO +#define S_ISFIFO(x) 0 +#endif +#endif + #include "sqMemoryAccess.h" #include "FilePlugin.h" /* must be included after sq.h */ From 9aea67d0dd63a191e80f69c6e760aadaf72de763 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 14:10:39 +0100 Subject: [PATCH 10/26] Backport Unicode compatibility patches from minheadless variant --- platforms/win32/vm/sqWin32Backtrace.c | 24 ++++++++++++------------ platforms/win32/vm/sqWin32Threads.c | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/platforms/win32/vm/sqWin32Backtrace.c b/platforms/win32/vm/sqWin32Backtrace.c index a67d1d80cf..86a69bc188 100644 --- a/platforms/win32/vm/sqWin32Backtrace.c +++ b/platforms/win32/vm/sqWin32Backtrace.c @@ -261,14 +261,14 @@ get_modules(void) { DWORD moduleCount2, i; HANDLE me = GetCurrentProcess(); - HANDLE hPsApi = LoadLibrary("psapi.dll"); + HANDLE hPsApi = LoadLibraryA("psapi.dll"); HMODULE *modules; EnumProcessModules = (void*)GetProcAddress(hPsApi, "EnumProcessModules"); GetModuleInformation=(void*)GetProcAddress(hPsApi, "GetModuleInformation"); if (!EnumProcessModules(me, (HMODULE *)&modules, sizeof(modules), &moduleCount)) { - printLastError("EnumProcessModules 1"); + printLastError(TEXT("EnumProcessModules 1")); return; } modules = malloc(moduleCount); @@ -280,14 +280,14 @@ get_modules(void) all_exports = calloc(moduleCount / sizeof(HMODULE) + EXTRAMODULES, sizeof(dll_exports)); if (!modules || !all_exports) { - printLastError("get_modules out of memory"); + printLastError(TEXT("get_modules out of memory")); if (modules) free(modules); return; } if (!EnumProcessModules(me, modules, moduleCount, &moduleCount2)) { - printLastError("EnumProcessModules 2"); + printLastError(TEXT("EnumProcessModules 2")); free(modules); return; } @@ -295,10 +295,10 @@ get_modules(void) for (i = 0; i < moduleCount; i++) { all_exports[i].module = modules[i]; - if (!GetModuleFileName(modules[i], all_exports[i].name, MAX_PATH)) - printLastError("GetModuleFileName"); + if (!GetModuleFileNameA(modules[i], all_exports[i].name, MAX_PATH)) + printLastError(TEXT("GetModuleFileName")); if (!GetModuleInformation(me, modules[i], &all_exports[i].info, sizeof(MODULEINFO))) - printLastError("GetModuleInformation"); + printLastError(TEXT("GetModuleInformation")); all_exports[i].find_symbol = find_in_dll; } free(modules); @@ -447,19 +447,19 @@ compute_exe_symbols(dll_exports *exports) strcpy(strrchr(filename,'.')+1,"map"); if (!(f = fopen(filename,"r"))) { - printLastError("fopen"); + printLastError(TEXT("fopen")); return; } fseek(f,0,SEEK_END); len = ftell(f); fseek(f,0,SEEK_SET); if (!(contents = malloc(len))) { - printLastError("malloc"); + printLastError(TEXT("malloc")); fclose(f); return; } if (fread(contents, sizeof(char), len, f) != len) { - printLastError("fread"); + printLastError(TEXT("fread")); fclose(f); return; } @@ -476,7 +476,7 @@ compute_exe_symbols(dll_exports *exports) if (!(exports->functions = calloc(nlines,sizeof(ulong))) || !(exports->u.funcNames = calloc(nlines,sizeof(char *)))) { - printLastError("malloc"); + printLastError(TEXT("malloc")); fclose(f); return; } @@ -559,7 +559,7 @@ compute_dll_symbols(dll_exports *exports) functions = (ulong *)(dllbase + pExportDir->AddressOfFunctions); if (!(exports->sorted_ordinals = calloc(pExportDir->NumberOfNames, sizeof(int)))) { - printLastError("compute_dll_symbols calloc"); + printLastError(TEXT("compute_dll_symbols calloc")); return; } exports->functions = functions; diff --git a/platforms/win32/vm/sqWin32Threads.c b/platforms/win32/vm/sqWin32Threads.c index 4f0d6af602..5ee2844c1b 100644 --- a/platforms/win32/vm/sqWin32Threads.c +++ b/platforms/win32/vm/sqWin32Threads.c @@ -78,7 +78,7 @@ duplicateAndSetThreadHandleForCurrentThread(void) return 0; } lastError = GetLastError(); - printLastError("DuplicateHandle"); + printLastError(TEXT("DuplicateHandle")); return lastError; } From f6d2d56b091be1b25310128b228c48c968114d60 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 14:12:13 +0100 Subject: [PATCH 11/26] Yet another printLastError Unicode compatibility fix in SoundPlugin --- platforms/win32/plugins/SoundPlugin/sqWin32Sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c b/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c index b014452eaa..712136a60b 100644 --- a/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c +++ b/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c @@ -279,7 +279,7 @@ snd_Start(sqInt frameCount, sqInt samplesPerSec, sqInt stereo, sqInt semaIndex) DPRINTF(("# Creating playback thread\n")); hPlayThread = CreateThread(NULL, 0, playCallback, NULL, 0, &threadID); if(hPlayThread == 0) { - printLastError("sndStart: CreateThread failed"); + printLastError(TEXT("sndStart: CreateThread failed")); snd_StopPlaying(); return 0; } From 67980fcf86460ac508b2beaf4a39cef58040ccdf Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 14:32:16 +0100 Subject: [PATCH 12/26] Fix another bunch of usage of printLastError uncompatible with Unicode --- platforms/win32/vm/sqWin32PluginSupport.c | 22 +++++++++++----------- platforms/win32/vm/sqWin32Threads.c | 2 +- platforms/win32/vm/sqWin32Window.c | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/platforms/win32/vm/sqWin32PluginSupport.c b/platforms/win32/vm/sqWin32PluginSupport.c index 07d38956f6..a076bcecc2 100644 --- a/platforms/win32/vm/sqWin32PluginSupport.c +++ b/platforms/win32/vm/sqWin32PluginSupport.c @@ -352,19 +352,19 @@ void pluginGetURLRequest(int id, void* urlIndex, int urlSize, SetLastError(0); ok = WriteFile(hBrowserPipe, &urlSize, 4, &dwWritten, NULL); if(!ok || dwWritten != 4) - printLastError("Failed to write url size"); + printLastError(TEXT("Failed to write url size")); if(urlSize > 0) { ok = WriteFile(hBrowserPipe, urlIndex, urlSize, &dwWritten, NULL); if(!ok || dwWritten != urlSize) - printLastError("Failed to write url request"); + printLastError(TEXT("Failed to write url request")); } ok = WriteFile(hBrowserPipe, &targetSize, 4, &dwWritten, NULL); if(!ok || dwWritten != 4) - printLastError("Failed to write target size"); + printLastError(TEXT("Failed to write target size")); if(targetSize > 0) { ok = WriteFile(hBrowserPipe, targetIndex, targetSize, &dwWritten, NULL); if(!ok || dwWritten != targetSize) - printLastError("Failed to write url request"); + printLastError(TEXT("Failed to write url request")); } } @@ -386,29 +386,29 @@ void pluginPostURLRequest(int id, void* urlIndex, int urlSize, SetLastError(0); ok = WriteFile(hBrowserPipe, &urlSize, 4, &dwWritten, NULL); if(!ok || dwWritten != 4) - printLastError("Failed to write url size"); + printLastError(TEXT("Failed to write url size")); if(urlSize > 0) { ok = WriteFile(hBrowserPipe, urlIndex, urlSize, &dwWritten, NULL); if(!ok || dwWritten != urlSize) - printLastError("Failed to write url request"); + printLastError(TEXT("Failed to write url request")); } ok = WriteFile(hBrowserPipe, &targetSize, 4, &dwWritten, NULL); if(!ok || dwWritten != 4) - printLastError("Failed to write url size"); + printLastError(TEXT("Failed to write url size")); if(targetSize > 0) { ok = WriteFile(hBrowserPipe, targetIndex, targetSize, &dwWritten, NULL); if(!ok || dwWritten != targetSize) - printLastError("Failed to write target request"); + printLastError(TEXT("Failed to write target request")); } ok = WriteFile(hBrowserPipe, &postDataSize, 4, &dwWritten, NULL); if(!ok || dwWritten != 4) - printLastError("Failed to write post data size"); + printLastError(TEXT("Failed to write post data size")); if(postDataSize > 0) { ok = WriteFile(hBrowserPipe, postDataIndex, postDataSize, &dwWritten, NULL); if(!ok || dwWritten != postDataSize) - printLastError("Failed to write data request"); + printLastError(TEXT("Failed to write data request")); } } @@ -428,7 +428,7 @@ void pluginSetBrowserPipe(MSG *msg) if(hBrowserPipe) CloseHandle(hBrowserPipe); hBrowserPipe = (HANDLE) msg->lParam; if(!CreatePipe(&hClientReadEnd, &hClientWriteEnd, NULL, 4096)) - printLastError("CreatePipe failed"); + printLastError(TEXT("CreatePipe failed")); /* And pass our the write end back to the plugin */ PostMessage(browserWindow, g_WM_CLIENT_PIPE, (WPARAM) GetCurrentProcess(), (LPARAM) hClientWriteEnd); diff --git a/platforms/win32/vm/sqWin32Threads.c b/platforms/win32/vm/sqWin32Threads.c index 5ee2844c1b..15028f42dc 100644 --- a/platforms/win32/vm/sqWin32Threads.c +++ b/platforms/win32/vm/sqWin32Threads.c @@ -197,7 +197,7 @@ ioNewOSSemaphore(sqOSSemaphore *sem) LONG_MAX, /* sky's the limit */ 0 /* don't need no stinkin' name */); if (!*sem) - printLastError("ioNewOSSemaphore CreateSemaphore"); + printLastError(TEXT("ioNewOSSemaphore CreateSemaphore")); return *sem ? 0 : GetLastError(); } diff --git a/platforms/win32/vm/sqWin32Window.c b/platforms/win32/vm/sqWin32Window.c index f556e3a1b4..0bb6c9073e 100644 --- a/platforms/win32/vm/sqWin32Window.c +++ b/platforms/win32/vm/sqWin32Window.c @@ -3246,7 +3246,7 @@ void ShowSplashScreen(void) { if(!hSplashDIB) { /* ignore the common case but print failures for the others */ if(GetLastError() != ERROR_FILE_NOT_FOUND) - printLastError("LoadImage failed"); + printLastError(TEXT("LoadImage failed")); return; } GetObject(hSplashDIB, sizeof(bm), &bm); From b52caab76f7f6b91c1f16d9037e0b0a43d968176 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 16:45:05 +0100 Subject: [PATCH 13/26] Fix sqWin32Security.c UNICODE problems We cannot pass a TCHAR * to a function expecting a WCHAR *, or the compiler logically barks. `isAccessiblePathName` takes a WCHAR * parameter `fromSqueak` answers a TCHAR *, which is currently a char * (because UNICODE is undefined). We want to be able to query internationalized path name, then the best (portable) thing to do is stick to UTF-8. We thus now interpret the pathName/fileName as UTF8-encoded in the authorization query primitives. NOTE: no effort is attempted to handle long path names here. --- .../plugins/SecurityPlugin/sqWin32Security.c | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/platforms/win32/plugins/SecurityPlugin/sqWin32Security.c b/platforms/win32/plugins/SecurityPlugin/sqWin32Security.c index f8a801b488..bae6199cce 100644 --- a/platforms/win32/plugins/SecurityPlugin/sqWin32Security.c +++ b/platforms/win32/plugins/SecurityPlugin/sqWin32Security.c @@ -108,30 +108,43 @@ static int isAccessiblePathName(WCHAR *pathName, int writeFlag) { return 0; } +static int isAccessibleUTF8PathName(char *pathName, int pathLen , int writeFlag) { + DWORD success; + WCHAR widePath[MAX_PATH]; + widePath[MAX_PATH - 1] = 0; + success = MultiByteToWideChar(CP_UTF8, 0, pathName, pathLen, widePath, MAX_PATH-1); + if (! success) return 0; /* if conversion fails, then it's not accessible */ + return isAccessiblePathName(widePath, writeFlag); +} + static int isAccessibleFileName(WCHAR *fileName, int writeFlag) { return isAccessiblePathName(fileName, writeFlag); } +static int isAccessibleUTF8FileName(char *fileName, int fileLen, int writeFlag) { + return isAccessibleUTF8PathName(fileName, fileLen , writeFlag); +} + /* directory access */ int ioCanCreatePathOfSize(char* pathString, int pathStringLength) { if(allowFileAccess) return 1; - return isAccessiblePathName(fromSqueak(pathString, pathStringLength), 1); + return isAccessibleUTF8PathName(pathString, pathStringLength, 1); } int ioCanListPathOfSize(char* pathString, int pathStringLength) { if(allowFileAccess) return 1; - return isAccessiblePathName(fromSqueak(pathString, pathStringLength), 0); + return isAccessibleUTF8PathName(pathString, pathStringLength, 0); } int ioCanDeletePathOfSize(char* pathString, int pathStringLength) { if(allowFileAccess) return 1; - return isAccessiblePathName(fromSqueak(pathString, pathStringLength), 1); + return isAccessibleUTF8PathName(pathString, pathStringLength, 1); } /* file access */ int ioCanOpenFileOfSizeWritable(char* pathString, int pathStringLength, int writeFlag) { if(allowFileAccess) return 1; - return isAccessibleFileName(fromSqueak(pathString, pathStringLength), writeFlag); + return isAccessibleUTF8FileName(pathString, pathStringLength, writeFlag); } int ioCanOpenAsyncFileOfSizeWritable(char* pathString, int pathStringLength, int writeFlag) { @@ -139,12 +152,12 @@ int ioCanOpenAsyncFileOfSizeWritable(char* pathString, int pathStringLength, int } int ioCanDeleteFileOfSize(char* pathString, int pathStringLength) { if(allowFileAccess) return 1; - return isAccessibleFileName(fromSqueak(pathString, pathStringLength), 1); + return isAccessibleUTF8FileName(pathString, pathStringLength, 1); } int ioCanRenameFileOfSize(char* pathString, int pathStringLength) { if(allowFileAccess) return 1; - return isAccessibleFileName(fromSqueak(pathString, pathStringLength), 1); + return isAccessibleUTF8FileName(pathString, pathStringLength, 1); } From 28cf9c626ee5eb0fce7bad34b8a87753fd974417 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 21:47:30 +0100 Subject: [PATCH 14/26] Fix TEXT(VMOPTION('foo")) TEXT is a macro that prepend a L, like TEXT("foo") => L"foo". It does not work for concatenated constants: TEXT("foo" "bar") => L"foo" "bar". VMOPTION concatenates a "-". Therefore we need a specific TVMOPTION macro. --- platforms/win32/vm/sqWin32Window.c | 51 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/platforms/win32/vm/sqWin32Window.c b/platforms/win32/vm/sqWin32Window.c index 0bb6c9073e..3b5eb72658 100644 --- a/platforms/win32/vm/sqWin32Window.c +++ b/platforms/win32/vm/sqWin32Window.c @@ -3308,6 +3308,7 @@ void HideSplashScreen(void) { /****************************************************************************/ # define VMOPTION(arg) "-"arg +# define TVMOPTION(arg) TEXT("-") TEXT(arg) /* print usage with different output levels */ int printUsage(int level) @@ -3320,43 +3321,43 @@ int printUsage(int level) abortMessage(TEXT("%s\n"), TEXT("Usage: ") TEXT(VM_NAME) TEXT(" [vmOptions] imageFile [imageOptions]\n\n") TEXT("vmOptions:") - TEXT("\n\t") TEXT(VMOPTION("service:")) TEXT(" ServiceName \t(install VM as NT service)") - TEXT("\n\t") TEXT(VMOPTION("headless")) TEXT(" \t\t(force VM to run headless)") - TEXT("\n\t") TEXT(VMOPTION("timephases")) TEXT(" \t\t(print start load and run times)") - TEXT("\n\t") TEXT(VMOPTION("log:")) TEXT(" LogFile \t\t(use LogFile for VM messages)") - TEXT("\n\t") TEXT(VMOPTION("memory:")) TEXT(" megaByte \t(set memory to megaByte MB)") + TEXT("\n\t") TVMOPTION("service:") TEXT(" ServiceName \t(install VM as NT service)") + TEXT("\n\t") TVMOPTION("headless") TEXT(" \t\t(force VM to run headless)") + TEXT("\n\t") TVMOPTION("timephases") TEXT(" \t\t(print start load and run times)") + TEXT("\n\t") TVMOPTION("log:") TEXT(" LogFile \t\t(use LogFile for VM messages)") + TEXT("\n\t") TVMOPTION("memory:") TEXT(" megaByte \t(set memory to megaByte MB)") #if STACKVM || NewspeakVM - TEXT("\n\t") TEXT(VMOPTION("breaksel:")) TEXT(" string \t(call warning on send of sel for debug)") + TEXT("\n\t") TVMOPTION("breaksel:") TEXT(" string \t(call warning on send of sel for debug)") #endif /* STACKVM || NewspeakVM */ #if STACKVM - TEXT("\n\t") TEXT(VMOPTION("breakmnu:")) TEXT(" string \t(call warning on MNU of sel for debug)") - TEXT("\n\t") TEXT(VMOPTION("leakcheck:")) TEXT(" n \t\t(leak check on GC (1=full,2=incr,3=both))") - TEXT("\n\t") TEXT(VMOPTION("eden:")) TEXT(" bytes \t\t(set eden memory size to bytes)") - TEXT("\n\t") TEXT(VMOPTION("stackpages:")) TEXT(" n \t\t(use n stack pages)") - TEXT("\n\t") TEXT(VMOPTION("numextsems:")) TEXT(" n \t\t(allow up to n external semaphores)") - TEXT("\n\t") TEXT(VMOPTION("checkpluginwrites")) TEXT(" \t(check for writes past end of object in plugins") - TEXT("\n\t") TEXT(VMOPTION("noheartbeat")) TEXT(" \t\t(no heartbeat for debug)") + TEXT("\n\t") TVMOPTION("breakmnu:") TEXT(" string \t(call warning on MNU of sel for debug)") + TEXT("\n\t") TVMOPTION("leakcheck:") TEXT(" n \t\t(leak check on GC (1=full,2=incr,3=both))") + TEXT("\n\t") TVMOPTION("eden:") TEXT(" bytes \t\t(set eden memory size to bytes)") + TEXT("\n\t") TVMOPTION("stackpages:") TEXT(" n \t\t(use n stack pages)") + TEXT("\n\t") TVMOPTION("numextsems:") TEXT(" n \t\t(allow up to n external semaphores)") + TEXT("\n\t") TVMOPTION("checkpluginwrites") TEXT(" \t(check for writes past end of object in plugins") + TEXT("\n\t") TVMOPTION("noheartbeat") TEXT(" \t\t(no heartbeat for debug)") #endif /* STACKVM */ #if STACKVM || NewspeakVM # if COGVM - TEXT("\n\t") TEXT(VMOPTION("trace")) TEXT("[=num]\t\tenable tracing (optionally to a specific value)") + TEXT("\n\t") TVMOPTION("trace") TEXT("[=num]\t\tenable tracing (optionally to a specific value)") # else - TEXT("\n\t") TEXT(VMOPTION("sendtrace")) TEXT(" \t\t(trace sends to stdout for debug)") + TEXT("\n\t") TVMOPTION("sendtrace") TEXT(" \t\t(trace sends to stdout for debug)") # endif - TEXT("\n\t") TEXT(VMOPTION("warnpid")) TEXT(" \t\t(print pid in warnings)") - TEXT("\n\t") TEXT(VMOPTION("[no]failonffiexception")) TEXT(" \t\t([never]always catch exceptions in FFI calls)") + TEXT("\n\t") TVMOPTION("warnpid") TEXT(" \t\t(print pid in warnings)") + TEXT("\n\t") TVMOPTION("[no]failonffiexception") TEXT(" \t\t([never]always catch exceptions in FFI calls)") #endif #if COGVM - TEXT("\n\t") TEXT(VMOPTION("codesize:")) TEXT(" bytes \t(set machine-code memory size to bytes)") - TEXT("\n\t") TEXT(VMOPTION("cogmaxlits:")) TEXT(" n \t\t(set max number of literals for methods to be compiled to machine code)") - TEXT("\n\t") TEXT(VMOPTION("cogminjumps:")) TEXT(" n \t(set min number of backward jumps for interpreted methods to be considered for compilation to machine code)") - TEXT("\n\t") TEXT(VMOPTION("tracestores")) TEXT(" \t\t(assert-check stores for debug)") - TEXT("\n\t") TEXT(VMOPTION("reportheadroom")) TEXT(" \t(report unused stack headroom on exit)") - TEXT("\n\t") TEXT(VMOPTION("dpcso:")) TEXT(" bytes \t\t(stack offset for prim calls for debug)") + TEXT("\n\t") TVMOPTION("codesize:") TEXT(" bytes \t(set machine-code memory size to bytes)") + TEXT("\n\t") TVMOPTION("cogmaxlits:") TEXT(" n \t\t(set max number of literals for methods to be compiled to machine code)") + TEXT("\n\t") TVMOPTION("cogminjumps:") TEXT(" n \t(set min number of backward jumps for interpreted methods to be considered for compilation to machine code)") + TEXT("\n\t") TVMOPTION("tracestores") TEXT(" \t\t(assert-check stores for debug)") + TEXT("\n\t") TVMOPTION("reportheadroom") TEXT(" \t(report unused stack headroom on exit)") + TEXT("\n\t") TVMOPTION("dpcso:") TEXT(" bytes \t\t(stack offset for prim calls for debug)") #endif /* COGVM */ #if SPURVM - TEXT("\n\t") TEXT(VMOPTION("maxoldspace:")) TEXT(" bytes \t(set max size of old space memory to bytes)") - TEXT("\n\t") TEXT(VMOPTION("logscavenge")) TEXT(" \t\t(log scavenging to scavenge.log)") + TEXT("\n\t") TVMOPTION("maxoldspace:") TEXT(" bytes \t(set max size of old space memory to bytes)") + TEXT("\n\t") TVMOPTION("logscavenge") TEXT(" \t\t(log scavenging to scavenge.log)") #endif TEXT("\n") TEXT("Options begin with single -, but -- prefix is silently accepted") TEXT("\n") TEXT("Options with arguments -opt:n are also accepted with separators -opt n") From 9e82899e688d01935a7157b27fa885329e98d143 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 22:10:51 +0100 Subject: [PATCH 15/26] Concatenate TEXT constants rather than TEXT concatenated constants TEXT("foo" "bar") => L"foo" "bar" => error concatenating wide string and ascii string TEXT("foo") TEXT("bar") => L"foo" L"bar" => compile OK --- .../win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c | 2 +- platforms/win32/vm/sqWin32Window.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c b/platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c index 880a81e3f4..d65368fe94 100644 --- a/platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c +++ b/platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c @@ -306,7 +306,7 @@ sqInt ioShowDisplayOnWindow(unsigned char* dispBits, sqInt width, if(lines == 0) { printLastError(TEXT("SetDIBitsToDevice failed")); - warnPrintf(TEXT("width=%" PRIdSQINT ",height=%" PRIdSQINT ",bits=%" PRIXSQPTR ",dc=%" PRIXSQPTR "\n"), + warnPrintf(TEXT("width=%") TEXT(PRIdSQINT) TEXT(",height=%") TEXT(PRIdSQINT) TEXT(",bits=%") TEXT(PRIXSQPTR) TEXT(",dc=%") TEXT(PRIXSQPTR) TEXT("\n"), width, height, (usqIntptr_t)dispBits, (usqIntptr_t)dc); } /* reverse the image bits if necessary */ diff --git a/platforms/win32/vm/sqWin32Window.c b/platforms/win32/vm/sqWin32Window.c index 3b5eb72658..b3e1b24025 100644 --- a/platforms/win32/vm/sqWin32Window.c +++ b/platforms/win32/vm/sqWin32Window.c @@ -2587,7 +2587,7 @@ sqInt ioShowDisplay(sqInt dispBits, sqInt width, sqInt height, sqInt depth, if(lines == 0) { printLastError(TEXT("SetDIBitsToDevice failed")); - warnPrintf(TEXT("width=%" PRIdSQINT ",height=%" PRIdSQINT ",bits=%" PRIXSQINT ",dc=%" PRIXSQPTR "\n"), + warnPrintf(TEXT("width=%") TEXT(PRIdSQINT) TEXT(",height=%") TEXT(PRIdSQINT) TEXT(",bits=%") TEXT(PRIXSQINT) TEXT(",dc=%") TEXT(PRIXSQPTR) TEXT("\n"), width, height, dispBits,(usqIntptr_t)dc); } /* reverse the image bits if necessary */ From 4e947dac58a702889adb281377708f897b0fc8c4 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 22:17:31 +0100 Subject: [PATCH 16/26] printLastError & warnPrintf take a TCHAR *, not a char * --- platforms/win32/plugins/SoundPlugin/sqWin32Sound.c | 2 +- platforms/win32/vm/sqWin32Alloc.c | 14 +++++++------- platforms/win32/vm/sqWin32PluginSupport.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c b/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c index 712136a60b..2b14003fc4 100644 --- a/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c +++ b/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c @@ -408,7 +408,7 @@ snd_StartRecording(sqInt samplesPerSec, sqInt stereo, sqInt semaIndex) { recSemaphore = semaIndex; hRecThread = CreateThread(NULL, 0, recCallback, NULL, 0, &threadID); if(hRecThread == 0) { - printLastError("snd_StartRec: CreateThread failed"); + printLastError(TEXT("snd_StartRec: CreateThread failed")); snd_StopRecording(); return 0; } diff --git a/platforms/win32/vm/sqWin32Alloc.c b/platforms/win32/vm/sqWin32Alloc.c index 99a1df518b..a3b51dd364 100644 --- a/platforms/win32/vm/sqWin32Alloc.c +++ b/platforms/win32/vm/sqWin32Alloc.c @@ -99,19 +99,19 @@ void *sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) int sqGrowMemoryBy(int oldLimit, int delta) { /* round delta UP to page size */ if(fShowAllocations) { - warnPrintf("Growing memory by %d...", delta); + warnPrintf(TEXT("Growing memory by %d..."), delta); } delta = (delta + pageSize) & pageMask; if(!VirtualAlloc(pageLimit, delta, MEM_COMMIT, PAGE_READWRITE)) { if(fShowAllocations) { - warnPrintf("failed\n"); + warnPrintf(TEXT("failed\n")); } /* failed to grow */ return oldLimit; } /* otherwise, expand pageLimit and return new top limit */ if(fShowAllocations) { - warnPrintf("okay\n"); + warnPrintf(TEXT("okay\n")); } pageLimit += delta; usedMemory += delta; @@ -124,26 +124,26 @@ int sqGrowMemoryBy(int oldLimit, int delta) { int sqShrinkMemoryBy(int oldLimit, int delta) { /* round delta DOWN to page size */ if(fShowAllocations) { - warnPrintf("Shrinking by %d...",delta); + warnPrintf(TEXT("Shrinking by %d..."),delta); } #ifdef DO_NOT_SHRINK { /* Experimental - do not unmap memory and avoid OGL crashes */ - if(fShowAllocations) warnPrintf(" - ignored\n"); + if(fShowAllocations) warnPrintf(TEXT(" - ignored\n")); return oldLimit; } #endif delta &= pageMask; if(!VirtualFree(pageLimit-delta, delta, MEM_DECOMMIT)) { if(fShowAllocations) { - warnPrintf("failed\n"); + warnPrintf(TEXT("failed\n")); } /* failed to shrink */ return oldLimit; } /* otherwise, shrink pageLimit and return new top limit */ if(fShowAllocations) { - warnPrintf("okay\n"); + warnPrintf(TEXT("okay\n")); } pageLimit -= delta; usedMemory -= delta; diff --git a/platforms/win32/vm/sqWin32PluginSupport.c b/platforms/win32/vm/sqWin32PluginSupport.c index a076bcecc2..c5a7548eda 100644 --- a/platforms/win32/vm/sqWin32PluginSupport.c +++ b/platforms/win32/vm/sqWin32PluginSupport.c @@ -342,7 +342,7 @@ void pluginGetURLRequest(int id, void* urlIndex, int urlSize, DWORD dwWritten; if(!hBrowserPipe) { - warnPrintf("Cannot submit URL request -- there is no connection to a browser\n"); + warnPrintf(TEXT("Cannot submit URL request -- there is no connection to a browser\n")); return; } @@ -376,7 +376,7 @@ void pluginPostURLRequest(int id, void* urlIndex, int urlSize, DWORD dwWritten; if(!hBrowserPipe) { - warnPrintf("Cannot submit URL post request -- there is no connection to a browser\n"); + warnPrintf(TEXT("Cannot submit URL post request -- there is no connection to a browser\n")); return; } From 3227fcf750b035281697da052df88f60b5c391d6 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Thu, 27 Dec 2018 22:43:47 +0100 Subject: [PATCH 17/26] DPRINTF takes a TCHAR * when it is a warnPrintf in disguise thus, it requires usage of a TEXT macro to enable -DUNICODE compilation --- .../win32/plugins/SoundPlugin/sqWin32Sound.c | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c b/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c index 2b14003fc4..b6d19fcc24 100644 --- a/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c +++ b/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c @@ -72,7 +72,7 @@ soundInit(void) { sqInt soundShutdown(void) { - DPRINTF(("soundShutDown\n")); + DPRINTF((TEXT("soundShutDown\n"))); snd_StopPlaying(); snd_StopRecording(); CloseHandle(hPlayEvent); @@ -84,7 +84,7 @@ sqInt snd_StopPlaying(void) { playTerminate = 0; if(lpdPlayBuffer) { - DPRINTF(("Shutting down DSound\n")); + DPRINTF((TEXT("Shutting down DSound\n"))); IDirectSoundBuffer_Stop(lpdPlayBuffer); IDirectSoundBuffer_Release(lpdPlayBuffer); lpdPlayBuffer = NULL; @@ -115,7 +115,7 @@ playCallback( LPVOID ignored ) { if(WaitForSingleObject(hPlayEvent, INFINITE) == WAIT_OBJECT_0) { if(playTerminate) { hPlayThread = NULL; - DPRINTF(("playCallback shutdown\n")); + DPRINTF((TEXT("playCallback shutdown\n"))); snd_StopPlaying(); return 0; /* done playing */ } @@ -170,7 +170,7 @@ snd_PlaySamplesFromAtLength(sqInt frameCount, void* srcBufPtr, if(bytesWritten < playBufferSize) return 0; - DPRINTF(("[%d", frameCount)); + DPRINTF((TEXT("[%d"), frameCount)); hRes = IDirectSoundBuffer_Lock(lpdPlayBuffer, playBufferSize * playBufferIndex, @@ -179,7 +179,7 @@ snd_PlaySamplesFromAtLength(sqInt frameCount, void* srcBufPtr, NULL, NULL, 0); if(FAILED(hRes)) { - DPRINTF(("snd_Play: IDirectSoundBuffer_Lock failed (errCode: %x)\n", hRes)); + DPRINTF((TEXT("snd_Play: IDirectSoundBuffer_Lock failed (errCode: %x)\n"), hRes)); return 0; } /* mix in stuff */ @@ -188,13 +188,13 @@ snd_PlaySamplesFromAtLength(sqInt frameCount, void* srcBufPtr, short *shortSrc = (short*)(((char*)srcBufPtr)+startIndex); short *shortDst = (short*)dstPtr; dstLen /=2; - DPRINTF(("|%d", dstLen)); + DPRINTF((TEXT("|%d"), dstLen)); for(i=0;i Date: Fri, 28 Dec 2018 02:03:30 +0100 Subject: [PATCH 18/26] Splash file and title may use Unicode variant We could also have used GetPrivateProfileStringA as a workaround, but let's not insult the future (internationalization) --- platforms/win32/vm/sqWin32Window.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platforms/win32/vm/sqWin32Window.c b/platforms/win32/vm/sqWin32Window.c index b3e1b24025..6c3874b62d 100644 --- a/platforms/win32/vm/sqWin32Window.c +++ b/platforms/win32/vm/sqWin32Window.c @@ -3221,21 +3221,21 @@ static LRESULT CALLBACK SplashWndProcA(HWND hwnd, void ShowSplashScreen(void) { WNDCLASS wc; - char splashFile[1024]; - char splashTitle[1024]; + TCHAR splashFile[1024]; + TCHAR splashTitle[1024]; BITMAP bm; RECT wa, rSplash; /* Look if we have a splash file somewhere */ - GetPrivateProfileString("Global", "SplashScreen", "Splash.bmp", + GetPrivateProfileString(TEXT("Global"), TEXT("SplashScreen"), TEXT("Splash.bmp"), splashFile, 1024, squeakIniName); /* Also get the title for the splash window */ - GetPrivateProfileString("Global", "SplashTitle", VM_NAME"!", + GetPrivateProfileString(TEXT("Global"), TEXT("SplashTitle"), TEXT(VM_NAME) TEXT("!"), splashTitle, 1024, squeakIniName); /* Look for the mimimum splash time to use */ - splashTime = GetPrivateProfileInt("Global", "SplashTime", + splashTime = GetPrivateProfileInt(TEXT("Global"), TEXT("SplashTime"), 1000, squeakIniName); if(!splashFile[0]) return; /* no splash file */ From 0eeffa0d7e337e92b0f01dcd74698667c168d835 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Fri, 28 Dec 2018 02:36:38 +0100 Subject: [PATCH 19/26] windowTitle is not a TCHAR *, it is a UTF8 encoded char * --- platforms/win32/vm/sqWin32.h | 2 +- platforms/win32/vm/sqWin32Prefs.c | 9 +++++++++ platforms/win32/vm/sqWin32Window.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/platforms/win32/vm/sqWin32.h b/platforms/win32/vm/sqWin32.h index 070692ec51..e48fcfd04d 100644 --- a/platforms/win32/vm/sqWin32.h +++ b/platforms/win32/vm/sqWin32.h @@ -263,7 +263,7 @@ extern char imageName[]; /* full path and name to image */ extern TCHAR imagePath[]; /* full path to image */ extern TCHAR vmPath[]; /* full path to interpreter's directory */ extern TCHAR vmName[]; /* name of the interpreter's executable */ -extern TCHAR windowTitle[]; /* window title string */ +extern char windowTitle[]; /* window title string */ extern char vmBuildString[]; /* the vm build string */ extern TCHAR windowClassName[]; /* class name for the window */ diff --git a/platforms/win32/vm/sqWin32Prefs.c b/platforms/win32/vm/sqWin32Prefs.c index 2a571c5a6e..14b906011a 100644 --- a/platforms/win32/vm/sqWin32Prefs.c +++ b/platforms/win32/vm/sqWin32Prefs.c @@ -207,8 +207,17 @@ void LoadPreferences() } /* get window title from ini file */ +#ifdef UNICODE + { + TCHAR windowTitleT[MAX_PATH]; + GetPrivateProfileString(U_GLOBAL, TEXT("WindowTitle"), + TEXT(""), windowTitleT, MAX_PATH, squeakIniName); + WideCharToMultiByte(CP_UTF8, 0, windowTitleT, -1, windowTitle, MAX_PATH, NULL, NULL); + } +#else GetPrivateProfileString(U_GLOBAL, TEXT("WindowTitle"), TEXT(""), windowTitle, MAX_PATH, squeakIniName); +#endif /* get the window class name from the ini file */ GetPrivateProfileString(U_GLOBAL, TEXT("WindowClassName"), diff --git a/platforms/win32/vm/sqWin32Window.c b/platforms/win32/vm/sqWin32Window.c index 6c3874b62d..76d95880e1 100644 --- a/platforms/win32/vm/sqWin32Window.c +++ b/platforms/win32/vm/sqWin32Window.c @@ -62,7 +62,7 @@ char imageName[MAX_PATH+1]; /* full path and name to image */ TCHAR imagePath[MAX_PATH+1]; /* full path to image */ TCHAR vmPath[MAX_PATH+1]; /* full path to interpreter's directory */ TCHAR vmName[MAX_PATH+1]; /* name of the interpreter's executable */ -TCHAR windowTitle[MAX_PATH]; /* what should we display in the title? */ +char windowTitle[MAX_PATH]; /* what should we display in the title? */ TCHAR squeakIniName[MAX_PATH+1]; /* full path and name to ini file */ TCHAR windowClassName[MAX_PATH+1]; /* Window class name */ From 3d55c5d4a6396772719230fc56e5b11b7faafe0b Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Fri, 28 Dec 2018 10:25:07 +0100 Subject: [PATCH 20/26] make win23OpenGL UNICODE friendly CreateWindow is the generic call that can switch to CreateWindowA or CreateWindowW It must take TCHAR * arguments. --- platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c b/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c index 1bf235913f..c393e34e0a 100644 --- a/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c +++ b/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c @@ -123,7 +123,7 @@ static HWND glCreateClientWindow(HWND parentWindow, int x, int y, int w, int h) { WNDCLASS windowClass; HINSTANCE hInstance; - const char *className = "Squeak-OpenGLWindow"; + const TCHAR *className = TEXT("Squeak-OpenGLWindow"); if(!parentWindow) return NULL; hInstance = (HINSTANCE) GetWindowLongPtr((HWND)parentWindow,GWLP_HINSTANCE); @@ -138,7 +138,7 @@ static HWND glCreateClientWindow(HWND parentWindow, int x, int y, int w, int h) windowClass.lpszMenuName = NULL; windowClass.lpszClassName = className; RegisterClass(&windowClass); - return CreateWindow(className,"", + return CreateWindow(className,TEXT(""), WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |WS_VISIBLE, x,y,w,h, (HWND) parentWindow, From 001d21af530cfd2255e43d4f20b3df84ac735cbe Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Fri, 28 Dec 2018 10:38:07 +0100 Subject: [PATCH 21/26] Invoke LoadLibraryA when there's no point to internationalize library name Most library names are dumb ASCII strings, so encoding them in UTF-16 has no added value. --- platforms/win32/plugins/CroquetPlugin/sqWin32CroquetPlugin.c | 2 +- platforms/win32/vm/sqWin32Main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platforms/win32/plugins/CroquetPlugin/sqWin32CroquetPlugin.c b/platforms/win32/plugins/CroquetPlugin/sqWin32CroquetPlugin.c index a4be144ac9..5c903130b4 100644 --- a/platforms/win32/plugins/CroquetPlugin/sqWin32CroquetPlugin.c +++ b/platforms/win32/plugins/CroquetPlugin/sqWin32CroquetPlugin.c @@ -8,7 +8,7 @@ static BOOLEAN (__stdcall *RtlGenRandom)(PVOID, ULONG) = NULL; int ioGatherEntropy(char *bufPtr, int bufSize) { if(!loaded) { loaded = 1; - hAdvApi32 = LoadLibrary("advapi32.dll"); + hAdvApi32 = LoadLibraryA("advapi32.dll"); RtlGenRandom = (void*)GetProcAddress(hAdvApi32, "SystemFunction036"); } if(!RtlGenRandom) return 0; diff --git a/platforms/win32/vm/sqWin32Main.c b/platforms/win32/vm/sqWin32Main.c index 8b4c3320c3..7f292669eb 100644 --- a/platforms/win32/vm/sqWin32Main.c +++ b/platforms/win32/vm/sqWin32Main.c @@ -540,7 +540,7 @@ void gatherSystemInfo(void) { { - HANDLE hUser = LoadLibrary( "user32.dll" ); + HANDLE hUser = LoadLibraryA( "user32.dll" ); pfnEnumDisplayDevices pEnumDisplayDevices = (pfnEnumDisplayDevices) GetProcAddress(hUser, "EnumDisplayDevicesA"); ZeroMemory(&gDev, sizeof(gDev)); From 616cacb0048b76385e265230406782db341e4a98 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Fri, 28 Dec 2018 10:44:31 +0100 Subject: [PATCH 22/26] GetProcAddress takes simple byte string procedure name Until now, there's no such thing as internationalized procedure names. Probably because low level languages do not support non ASCII identifiers. --- platforms/win32/vm/sqWin32ExternalPrims.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/platforms/win32/vm/sqWin32ExternalPrims.c b/platforms/win32/vm/sqWin32ExternalPrims.c index ac18cf5c3c..3c05397ba5 100644 --- a/platforms/win32/vm/sqWin32ExternalPrims.c +++ b/platforms/win32/vm/sqWin32ExternalPrims.c @@ -69,19 +69,11 @@ ioFindExternalFunctionInAccessorDepthInto(char *lookupName, void *moduleHandle, void *f; char buffer[256]; -# ifdef UNICODE - f = GetProcAddress(moduleHandle, toUnicode(lookupName)); -# else f = GetProcAddress(moduleHandle, lookupName); -# endif if (f && accessorDepthPtr) { void *accessorDepthVarPtr; snprintf(buffer,256,"%sAccessorDepth",lookupName); -# ifdef UNICODE - accessorDepthVarPtr = GetProcAddress(moduleHandle, toUnicode(buffer)); -# else accessorDepthVarPtr = GetProcAddress(moduleHandle, buffer); -# endif /* The Slang machinery assumes accessor depth defaults to -1, which * means "no accessor depth". It saves space not outputting -1 depths. */ @@ -95,11 +87,7 @@ ioFindExternalFunctionInAccessorDepthInto(char *lookupName, void *moduleHandle, void * ioFindExternalFunctionIn(char *lookupName, void *moduleHandle) { -# ifdef UNICODE - return GetProcAddress((HANDLE)moduleHandle, toUnicode(lookupName)); -# else return GetProcAddress((HANDLE)moduleHandle, lookupName); -# endif } #endif /* SPURVM */ From 4b328037903d7eb1b9e0da5ef325693040831c4a Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Fri, 28 Dec 2018 11:03:22 +0100 Subject: [PATCH 23/26] Use GetLocaleInfoA rather than generic version This is the least change that makes the plugin compile correctly with -DUNICODE But this is maybe not the right thing. If the answer contains a character that is not available in the code page, then it will be replaced by a question mark. https://docs.microsoft.com/en-us/windows/desktop/api/winnls/nf-winnls-getlocaleinfow The right thing would be to go thru GetLocaleInfoW and WideCharToMultiByte dance to answer an UTF-8 encoded string. --- .../plugins/LocalePlugin/sqWin32Locale.c | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/platforms/win32/plugins/LocalePlugin/sqWin32Locale.c b/platforms/win32/plugins/LocalePlugin/sqWin32Locale.c index 6b0e6f7630..67fce210ab 100644 --- a/platforms/win32/plugins/LocalePlugin/sqWin32Locale.c +++ b/platforms/win32/plugins/LocalePlugin/sqWin32Locale.c @@ -36,7 +36,7 @@ void sqLocGetCountryInto(char * str) { char currString[6]; int length; - length = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME,currString, 6); + length = GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME,currString, 6); strncpy(str, currString, length-1); } @@ -49,7 +49,7 @@ void sqLocGetLanguageInto(char * str) { char currString[6]; int length; - length = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO639LANGNAME,currString, 6); + length = GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SISO639LANGNAME,currString, 6); strncpy(str, currString, length-1); } @@ -59,7 +59,7 @@ void sqLocGetLanguageInto(char * str) { *currency amount */ sqInt sqLocCurrencyNotation(void) { DWORD icurrency; - if (GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_ICURRENCY | LOCALE_RETURN_NUMBER,(char *)&icurrency, sizeof(icurrency)/sizeof(TCHAR)) != 0){ + if (GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_ICURRENCY | LOCALE_RETURN_NUMBER,(char *)&icurrency, sizeof(icurrency)/sizeof(TCHAR)) != 0){ return((icurrency % 2) == 0); } return 0; @@ -68,14 +68,14 @@ sqInt sqLocCurrencyNotation(void) { /* return the length in chars of the curency symbol string */ sqInt sqLocCurrencySymbolSize(void) { char currString[6]; - return GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SCURRENCY,currString, 6)-1; + return GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SCURRENCY,currString, 6)-1; } /* write the currency symbol into the string ptr */ void sqLocGetCurrencySymbolInto(char * str) { char currString[6]; int length; - length = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SCURRENCY,currString, 6); + length = GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SCURRENCY,currString, 6); strncpy(str, currString, length-1); @@ -88,7 +88,7 @@ void sqLocGetCurrencySymbolInto(char * str) { * (USA is about it) */ sqInt sqLocMeasurementMetric(void) { char resultString[2]; - if (GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_IMEASURE,resultString, 2) != 0){ + if (GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_IMEASURE,resultString, 2) != 0){ if (strcmp (resultString,"0")) return false; else return true; } @@ -99,7 +99,7 @@ sqInt sqLocMeasurementMetric(void) { * Usually this is . or , as in 1,000,000 */ void sqLocGetDigitGroupingSymbolInto(char * str) { char groupString[4]; - GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STHOUSAND,groupString, 4); + GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_STHOUSAND,groupString, 4); strncpy(str, groupString, 1); } @@ -107,7 +107,7 @@ void sqLocGetDigitGroupingSymbolInto(char * str) { * Usually this is . or , */ void sqLocGetDecimalSymbolInto(char * str) { char deciString[4]; - GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SDECIMAL, deciString, 4); + GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SDECIMAL, deciString, 4); strncpy(str, deciString, 1); } @@ -142,7 +142,7 @@ sqInt sqLocDaylightSavings(void) { static char longDateFormat[] = "dddd dd mmmm yy"; /* return the size in chars of the long date format string */ sqInt sqLocLongDateFormatSize(void) { - return GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SLONGDATE, NULL, 0)-1; + return GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SLONGDATE, NULL, 0)-1; } /*Write the string describing the long date formatting into string ptr. @@ -155,14 +155,14 @@ sqInt sqLocLongDateFormatSize(void) { void sqLocGetLongDateFormatInto(char * str) { char dateString[80]; int length; - length = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SLONGDATE, dateString, 80); + length = GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SLONGDATE, dateString, 80); strncpy(str, dateString, length-1); } static char shortDateFormat[] = "dd/mm/yy"; /* return the size in chars of the short date format string */ sqInt sqLocShortDateFormatSize(void) { - return GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE, NULL, 0)-1; + return GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE, NULL, 0)-1; } /*Write the string describing the short date formatting into string ptr. @@ -174,14 +174,14 @@ sqInt sqLocShortDateFormatSize(void) { void sqLocGetShortDateFormatInto(char * str) { char dateString[80]; int length; - length = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE, dateString, 80); + length = GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE, dateString, 80); strncpy(str, dateString, length-1); } static char timeFormat[] = "h:m:s"; /* return the size in chars of the time format string */ sqInt sqLocTimeFormatSize(void) { - return GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT, NULL, 0)-1; + return GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT, NULL, 0)-1; } /* write the string describing the time formatting into string ptr. @@ -191,6 +191,6 @@ sqInt sqLocTimeFormatSize(void) { void sqLocGetTimeFormatInto(char * str) { char timeString[80]; int length; - length = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT, timeString, 80); + length = GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT, timeString, 80); strncpy(str, timeString, length-1); } From 539c7692dee3292456301dfb14b8a36513a9cc76 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Fri, 28 Dec 2018 11:32:56 +0100 Subject: [PATCH 24/26] remove unused LongFileNameFromPossiblyShortName This might be a nice piece of code, but it's dead code. Dead code has maintenance costs that generally do not pay back. For example when reviewing UNICODE compatibility, I just paid for what I did not buy. For archeology purposes, there is a source code/version control system. --- platforms/win32/vm/sqWin32Window.c | 53 ------------------------------ 1 file changed, 53 deletions(-) diff --git a/platforms/win32/vm/sqWin32Window.c b/platforms/win32/vm/sqWin32Window.c index 76d95880e1..fc5f9084e0 100644 --- a/platforms/win32/vm/sqWin32Window.c +++ b/platforms/win32/vm/sqWin32Window.c @@ -3008,59 +3008,6 @@ void SetupFilesAndPath(){ #else /* defined(_WIN32_WCE) */ -void -LongFileNameFromPossiblyShortName(TCHAR *nameBuffer) -{ TCHAR oldDir[MAX_PATH+1]; - TCHAR testName[13]; - TCHAR nameBuf[MAX_PATH+1]; - TCHAR *shortName; - WIN32_FIND_DATA findData; - HANDLE findHandle; - - GetCurrentDirectory(MAX_PATH,oldDir); - shortName = lstrrchr(nameBuffer,U_BACKSLASH[0]); - if(!shortName) shortName = lstrrchr(nameBuffer,U_SLASH[0]); - if(!shortName) return; - /* if the file name is longer than 8.3 - this can't be a short name */ - *(shortName++) = 0; - if(lstrlen(shortName) > 12) - goto notFound; - - /* back up the old and change to the given directory, - this makes searching easier */ - lstrcpy(nameBuf, nameBuffer); - lstrcat(nameBuf,TEXT("\\")); - SetCurrentDirectory(nameBuf); - - /* now search the directory */ - findHandle = FindFirstFile(TEXT("*.*"),&findData); - if(findHandle == INVALID_HANDLE_VALUE) goto notFound; /* nothing found */ - do { - if(lstrcmp(findData.cFileName,TEXT("..")) && lstrcmp(findData.cFileName,TEXT("."))) - lstrcpy(testName,findData.cAlternateFileName); - else - *testName = 0; - if(lstrcmp(testName,shortName) == 0) /* gotcha! */ - { - FindClose(findHandle); - /* recurse down */ - lstrcpy(nameBuf, findData.cFileName); - goto recurseDown; - } - } while(FindNextFile(findHandle,&findData) != 0); - /* nothing appropriate found */ - FindClose(findHandle); -notFound: - lstrcpy(nameBuf, shortName); -recurseDown: - /* recurse down */ - LongFileNameFromPossiblyShortName(nameBuffer); - lstrcat(nameBuffer,TEXT("\\")); - lstrcat(nameBuffer,nameBuf); - SetCurrentDirectory(oldDir); -} - void SetupFilesAndPath() { char *tmp; WCHAR tmpName[MAX_PATH]; From 7c5fe91432e72fdcc6a7e098818a8bcfccb3371f Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Fri, 28 Dec 2018 11:54:22 +0100 Subject: [PATCH 25/26] the DPRINTF used in sqWin32PluginSupport.c takes a TCHAR *, not a char * It's hard to decipher, because DPRINTF is both: - a MACRO at top of this file (and in many other files just to shuffle the cards) - a function in sqWin32Main.c Since the MACRO looks like recursive, it's a kind of dangerously convoluted code! --- platforms/win32/vm/sqWin32PluginSupport.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/platforms/win32/vm/sqWin32PluginSupport.c b/platforms/win32/vm/sqWin32PluginSupport.c index c5a7548eda..8b5cdee884 100644 --- a/platforms/win32/vm/sqWin32PluginSupport.c +++ b/platforms/win32/vm/sqWin32PluginSupport.c @@ -81,7 +81,7 @@ EXPORT(int) primitivePluginBrowserReady(void) { if(!fBrowserMode) { /* fast failure is better when not in browser */ - DPRINTF(("fBrowserMode == 0\n")); + DPRINTF((TEXT("fBrowserMode == 0\n"))); return primitiveFail(); } pop(1); @@ -424,7 +424,7 @@ void pluginPostURLRequest(int id, void* urlIndex, int urlSize, */ void pluginSetBrowserPipe(MSG *msg) { - DPRINTF(("New browser pipe: %x\n",msg->lParam)); + DPRINTF((TEXT("New browser pipe: %x\n"),msg->lParam)); if(hBrowserPipe) CloseHandle(hBrowserPipe); hBrowserPipe = (HANDLE) msg->lParam; if(!CreatePipe(&hClientReadEnd, &hClientWriteEnd, NULL, 4096)) @@ -469,15 +469,15 @@ void pluginInit(void) */ void pluginHandleEvent(MSG *msg) { - DPRINTF(("Checking for plugin message (%x)\n",msg->message)); - DPRINTF(("\tg_WM_QUIT_SESSION: %x\n",g_WM_QUIT_SESSION)); - DPRINTF(("\tg_WM_BWND_SIZE: %x\n",g_WM_BWND_SIZE)); - DPRINTF(("\tg_WM_REQUEST_DATA: %x\n",g_WM_REQUEST_DATA)); - DPRINTF(("\tg_WM_POST_DATA: %x\n",g_WM_POST_DATA)); - DPRINTF(("\tg_WM_RECEIVE_DATA: %x\n",g_WM_RECEIVE_DATA)); - DPRINTF(("\tg_WM_INVALIDATE: %x\n",g_WM_INVALIDATE)); - DPRINTF(("\tg_WM_BROWSER_PIPE: %x\n",g_WM_BROWSER_PIPE)); - DPRINTF(("\tg_WM_CLIENT_PIPE: %x\n",g_WM_CLIENT_PIPE)); + DPRINTF((TEXT("Checking for plugin message (%x)\n"),msg->message)); + DPRINTF((TEXT("\tg_WM_QUIT_SESSION: %x\n"),g_WM_QUIT_SESSION)); + DPRINTF((TEXT("\tg_WM_BWND_SIZE: %x\n"),g_WM_BWND_SIZE)); + DPRINTF((TEXT("\tg_WM_REQUEST_DATA: %x\n"),g_WM_REQUEST_DATA)); + DPRINTF((TEXT("\tg_WM_POST_DATA: %x\n"),g_WM_POST_DATA)); + DPRINTF((TEXT("\tg_WM_RECEIVE_DATA: %x\n"),g_WM_RECEIVE_DATA)); + DPRINTF((TEXT("\tg_WM_INVALIDATE: %x\n"),g_WM_INVALIDATE)); + DPRINTF((TEXT("\tg_WM_BROWSER_PIPE: %x\n"),g_WM_BROWSER_PIPE)); + DPRINTF((TEXT("\tg_WM_CLIENT_PIPE: %x\n"),g_WM_CLIENT_PIPE)); /* Messages posted from a different process */ if(msg->message == g_WM_QUIT_SESSION) exit(0); From 19ebd67cbadb77088bec9e4bc2da28c6889251b7 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Sat, 29 Dec 2018 14:55:11 +0100 Subject: [PATCH 26/26] Handle failure to convert WindowTitle preference to UTF8 --- platforms/win32/vm/sqWin32Prefs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platforms/win32/vm/sqWin32Prefs.c b/platforms/win32/vm/sqWin32Prefs.c index 14b906011a..b6339803a4 100644 --- a/platforms/win32/vm/sqWin32Prefs.c +++ b/platforms/win32/vm/sqWin32Prefs.c @@ -212,7 +212,10 @@ void LoadPreferences() TCHAR windowTitleT[MAX_PATH]; GetPrivateProfileString(U_GLOBAL, TEXT("WindowTitle"), TEXT(""), windowTitleT, MAX_PATH, squeakIniName); - WideCharToMultiByte(CP_UTF8, 0, windowTitleT, -1, windowTitle, MAX_PATH, NULL, NULL); + if (WideCharToMultiByte(CP_UTF8, 0, windowTitleT, -1, windowTitle, MAX_PATH, NULL, NULL) == 0) { + printLastError(TEXT("Failed to convert WindowTitle preference to UTF-8")); + windowTitle[0] = 0; + }; } #else GetPrivateProfileString(U_GLOBAL, TEXT("WindowTitle"),