From: larrybr Date: Sun, 29 Oct 2023 16:26:12 +0000 (+0000) Subject: Properly close a handle. Use a putatively effective runtime test for UTF-8 console... X-Git-Tag: version-3.44.0~13^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=060c097e0d2f947ad77ce12f6781320aec6088f9;p=thirdparty%2Fsqlite.git Properly close a handle. Use a putatively effective runtime test for UTF-8 console I/O capability. (This makes the version test useful mainly for avoiding a warning that UTF-8 console I/O could not be setup.) FossilOrigin-Name: dc91eb91725f3db65c73725f1fbcf18a711cafb65b4fea3277aa0905a24df353 --- diff --git a/manifest b/manifest index 1eba221ff9..431c97d07b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Condition\sdefault\sUTF-8\sconsole\sI/O\sfor\sWindows\sbuilds\son\sOS\sversion\s10\sor\smore.\sThis\sis\sto\saccomodate\san\sIsValidCodePage()\sAPI\swhich\smay\shappily\sreport\sCP_UTF8\sas\sa\svalid\scode\spage\swhen\sthe\sstock\sconsole\scannot,\sin\sfact,\sdo\sUTF-8\sI/O. -D 2023-10-29T00:24:22.936 +C Properly\sclose\sa\shandle.\sUse\sa\sputatively\seffective\sruntime\stest\sfor\sUTF-8\sconsole\sI/O\scapability.\s(This\smakes\sthe\sversion\stest\suseful\smainly\sfor\savoiding\sa\swarning\sthat\sUTF-8\sconsole\sI/O\scould\snot\sbe\ssetup.) +D 2023-10-29T16:26:12.664 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -722,7 +722,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 31229276a8eb5b5de1428cd2d80f6f1cf8ffc5248be25e47cf575df12f1b8f23 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 64c9bc7494f3d220a27498137551762c25458282388ea9ac0a710dd6d5dc1510 -F src/shell.c.in 29b2abb039ddff7b512960a5396cecbaee6ab236537de36f4f972adbfc4467c1 +F src/shell.c.in 6c7a4481b776a2d568816344597d0481359b4a20f465ce1c3033004fa9fa4a72 F src/sqlite.h.in ef0e41e83ad1ac0dcc9ec9939bf541a44b1c5de821bee2d6c61754c3252f3276 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 2f30b2671f4c03cd27a43f039e11251391066c97d11385f5f963bb40b03038ac @@ -2139,11 +2139,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 765290663b28e90a0494997baf023f9610a4ed32f0ff0099bf9fc3d485733fca -R 06beefd7b5a601159ef2b90a69791f5c -T *branch * win-utf8-io-split -T *sym-win-utf8-io-split * -T -sym-trunk * +P 6b9b2a886fd4d239c2e87c3f3809c011f77c0f60e0c279bbe4e1d1b53c609e2d +R bab24205be6731c553860e9beeba6fcf U larrybr -Z 8b9699cbbd0e4aa806c0f866919f402f +Z a3328aae66d1d54e0b613e1b32590aa3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d8f3ed59bf..dd7ecada55 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6b9b2a886fd4d239c2e87c3f3809c011f77c0f60e0c279bbe4e1d1b53c609e2d \ No newline at end of file +dc91eb91725f3db65c73725f1fbcf18a711cafb65b4fea3277aa0905a24df353 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index e61887bc62..7041b7d693 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -619,13 +619,13 @@ static int CheckAtLeastWin10(void){ typedef LONG (WINAPI *REG_OPEN)(HKEY,LPCSTR,DWORD,REGSAM,PHKEY); typedef LSTATUS (WINAPI *REG_READ)(HKEY,LPCSTR,LPCSTR,DWORD, LPDWORD,PVOID,LPDWORD); - typedef LSTATUS (WINAPI *REG_UNLOAD)(HKEY,LPCSTR); + typedef LSTATUS (WINAPI *REG_CLOSE)(HKEY); int rv = 0; HINSTANCE hLib = LoadLibrary(TEXT("Advapi32.dll")); if( NULL != hLib ){ REG_OPEN rkOpen = (REG_OPEN)GetProcAddress(hLib, "RegOpenKeyExA"); REG_READ rkRead = (REG_READ)GetProcAddress(hLib, "RegGetValueA"); - REG_UNLOAD rkFree = (REG_UNLOAD)GetProcAddress(hLib, "RegUnLoadKeyA"); + REG_CLOSE rkFree = (REG_CLOSE)GetProcAddress(hLib, "RegCloseKey"); if( rkOpen != NULL && rkRead != NULL && rkFree != NULL ){ HKEY hk; const char *zsk = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; @@ -635,7 +635,7 @@ static int CheckAtLeastWin10(void){ RRF_RT_REG_DWORD, 0, &kv, &kvsize) ){ rv = (kv >= 10); } - rkFree(hk, 0); + rkFree(hk); } } FreeLibrary(hLib); @@ -659,6 +659,7 @@ static void console_prepare_utf8(void){ HANDLE hCC = INVALID_HANDLE_VALUE; DWORD consoleMode = 0; u8 conI = 0, conO = 0; + struct ConsoleState csWork = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 }; console_utf8_in = console_utf8_out = 0; if( isatty(0) && GetFileType(hCI)==FILE_TYPE_CHAR ) conI = 1; @@ -667,24 +668,28 @@ static void console_prepare_utf8(void){ if( conI ) hCC = hCI; else hCC = hCO; if( !IsValidCodePage(CP_UTF8) || !GetConsoleMode( hCC, &consoleMode) ){ + bail: fprintf(stderr, "Cannot use UTF-8 code page.\n"); return; } - conState.hConsole = hCC; - conState.consoleMode = consoleMode; - conState.inCodePage = GetConsoleCP(); - conState.outCodePage = GetConsoleOutputCP(); + csWork.hConsole = hCC; + csWork.consoleMode = consoleMode; + csWork.inCodePage = GetConsoleCP(); + csWork.outCodePage = GetConsoleOutputCP(); if( conI ){ + if( !SetConsoleCP(CP_UTF8) ) goto bail; console_utf8_in = 1; - SetConsoleCP(CP_UTF8); consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT; SetConsoleMode(conState.hConsole, consoleMode); - conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT); + csWork.infsMode = _setmode(_fileno(stdin), _O_U16TEXT); } if( conO ){ + /* Here, it is assumed that if conI is true, this call will + ** also succeed, so there is no need to undo above setup. */ + if( !SetConsoleOutputCP(CP_UTF8) ) goto bail; console_utf8_out = 1; - SetConsoleOutputCP(CP_UTF8); } + conState = csWork; } /* @@ -12245,7 +12250,10 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #endif #if SHELL_WIN_UTF8_OPT - /* If Windows build and not RT, set*/ + /* If Windows build and not RT, set default MBCS/UTF-8 translation + ** for console according to detected Windows version. This default + ** may be overridden by the -utf8 or -no-utf8 invocation options. + */ mbcs_opted = (IS_WIN10_OR_LATER())? 0 : 1; #endif