-
Notifications
You must be signed in to change notification settings - Fork 37.7k
gui: Drop boost::scoped_array and use wchar_t API explicitly on Windows #13734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This was introduced in #5793. Looks like something similar to what you are doing was proposed at the time as well. |
Hope there is a way to see code that is before he force push. |
Concept ACK Thanks for removing Boost dependencies. Keep it coming! :-) |
Any suggestion on how to test this? |
This is Windows-only code, can be tested as same as #5793 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the reference also be removed from test/lint/lint-includes.sh
?
Tested that make
still works on macOS.
Tested the gitian binary on a Windows 10 VM, by launching with bitcoin-qt -wallet=你好
, assuming that was the problem? This leads to a crash, but that's also the case on master:
I have a version from earlier this year where it leads to a slightly nicer crash:
(seems unrelated, so I made a ticket #13754)
bitcoin-qt -wallet=test
works fine by the way, maybe that was all.
src/qt/guiutil.cpp
Outdated
@@ -625,7 +615,7 @@ bool SetStartOnSystemStartup(bool fAutoStart) | |||
#ifndef UNICODE | |||
psl->SetArguments(strArgs.toStdString().c_str()); | |||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment that UNICODE
is only defined for Windows? (if that's the case)
Update: Since the goal is to make it unicode compatible, just make it use wchar_t version of api explicitly. |
reinterpret_cast<void**>(&psl)); | ||
|
||
if (SUCCEEDED(hres)) | ||
{ | ||
// Get the current executable path | ||
TCHAR pszExePath[MAX_PATH]; | ||
GetModuleFileName(nullptr, pszExePath, sizeof(pszExePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is bug before, if TCHAR is wchar_t, then sizeof(pszExePath)= 2*MAX_PATH, which can result memory overflow.
Tested that |
Tested that for commit 6031f7f (master and this pull) I can launch regtest and testnet after re-login for a user with only ascii character in the name. (See lower left of screenshot, Compare to #5793 (comment)) |
@MarcoFalke Can you test this again? Now it should fix #13819. |
@MarcoFalke That should fixed by #13426. You can merge these two PR and test locally. |
src/qt/guiutil.cpp
Outdated
reinterpret_cast<void**>(&psl)); | ||
|
||
if (SUCCEEDED(hres)) | ||
{ | ||
// Get the current executable path | ||
TCHAR pszExePath[MAX_PATH]; | ||
GetModuleFileName(nullptr, pszExePath, sizeof(pszExePath)); | ||
wchar_t pszExePath[MAX_PATH]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think safer to use WCHAR
here, as I'm seeing differing descriptions of its definition, e.g. unsigned wchar_t
here: https://docs.microsoft.com/en-us/windows/desktop/intl/windows-data-types-for-strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/util.cpp
Outdated
@@ -1118,9 +1118,9 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { | |||
#ifdef WIN32 | |||
fs::path GetSpecialFolderPath(int nFolder, bool fCreate) | |||
{ | |||
char pszPath[MAX_PATH] = ""; | |||
wchar_t pszPath[MAX_PATH] = L""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, WCHAR
seems preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
nice cleanup, too utACK bb6ca65 |
…citly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix #13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454
Drop boost::scoped_array and simplify the code. TCHAR should be defined as wchar_t if UNICODE is defined. So we can use .toStdWString().c_str() to get wchar_t C-style string. Backports bitcoin#13734
Drop boost::scoped_array and simplify the code. TCHAR should be defined as wchar_t if UNICODE is defined. So we can use .toStdWString().c_str() to get wchar_t C-style string. Backports bitcoin#13734
Summary: * Drop boost::scoped_array * gui: get special folder in unicode This is a backport of Core [[bitcoin/bitcoin#13734 | PR13734]] Test Plan: make check Run bitcoin-qt on win64 Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D5889
Summary: * Drop boost::scoped_array * gui: get special folder in unicode This is a backport of Core [[bitcoin/bitcoin#13734 | PR13734]] Test Plan: make check Run bitcoin-qt on win64 Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D5889
Backport Boost removal PRs Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#7613 - bitcoin/bitcoin#10502 - bitcoin/bitcoin#10193 - bitcoin/bitcoin#13961 - bitcoin/bitcoin#13734 - Only the second commit (we don't need the first). - bitcoin/bitcoin#14480 Part of #4819.
e2fee5c [GUI] Use wchar_t API explicitly on Windows (Fuzzbawls) Pull request description: backport of bitcoin#13734 to use the wchar API for windows startup function. This is the first in a long list of upstream PRs that aim to bring full Unicode support to Windows clients as detailed in bitcoin#13869 Also included here is the relevant parts of bitcoin#5793, to use per-network auto startup shortcuts. ACKs for top commit: furszy: utACK e2fee5c . random-zebra: utACK e2fee5c and merging... Tree-SHA512: dc4ea84ee10199bdf293977f00c09caf65cbdd1ee2ae14b1adb34fd75c05b847d5971abd17732a77be88bed9e06092b670b09c5760a686b29d64ba8f02d2e4b2
…I explicitly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix bitcoin#13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454 # Conflicts: # src/qt/guiutil.cpp
…I explicitly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix bitcoin#13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454 # Conflicts: # src/qt/guiutil.cpp
…I explicitly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix bitcoin#13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454 # Conflicts: # src/qt/guiutil.cpp
…I explicitly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix bitcoin#13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454 # Conflicts: # src/qt/guiutil.cpp
…I explicitly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix bitcoin#13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454 # Conflicts: # src/qt/guiutil.cpp
…I explicitly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix bitcoin#13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454 # Conflicts: # src/qt/guiutil.cpp
…I explicitly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix bitcoin#13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454 # Conflicts: # src/qt/guiutil.cpp
…I explicitly on Windows bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix bitcoin#13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454 # Conflicts: # src/qt/guiutil.cpp
63e0be6 [Remove] By-pass logprint-scanner restriction. (furszy) 280ced3 utils: Fix broken Windows filelock (Chun Kuan Lee) be89860 utils: Convert Windows args to utf-8 string (Chun Kuan Lee) e8cfa6e Call unicode API on Windows (Chun Kuan Lee) 1a02a8a tests: Add test case for std::ios_base::ate (Chun Kuan Lee) 2e57cd4 Move boost/std fstream to fsbridge (furszy) 9d8bcd4 utils: Add fsbridge fstream function wrapper (Chun Kuan Lee) d59d48d utils: Convert fs error messages from multibyte to utf-8 (ken2812221) 9ef58cc Logging: use "fmterr" variable name for errors instead of general "e" that can be used by any other function. (furszy) dd94241 utils: Use _wfopen and _wreopen on Windows (Chun Kuan Lee) 3993641 add unicode compatible file_lock for Windows (Chun Kuan Lee) 48349f8 Provide relevant error message if datadir is not writable. (murrayn) Pull request description: As the software is currently using the ANSI encoding on Windows, the user's language settings could affect the proper functioning of the node/wallet, to the point of not be able to open some non-ASCII name files and directories. This solves the Windows encoding issues, completing the entire bitcoin#13869 work path (and some other required backports). Enabling for example users that use non-english characters in directories and file names to be accepted. Backported PRs: * bitcoin#12422. * bitcoin#12630. * bitcoin#13862. * bitcoin#13866. * bitcoin#13877. * bitcoin#13878. * bitcoin#13883. * bitcoin#13884. * bitcoin#13886. * bitcoin#13888. * bitcoin#14192. * bitcoin#13734. * bitcoin#14426. This is built on top of other two PRs that i have open #2423 and #2369. Solves old issues #940 and #2163. TODO: * Backport `assert_start_raises_init_error` and `ErrorMatch` in TestNode` (bitcoin#12718) ACKs for top commit: Fuzzbawls: ACK 63e0be6 random-zebra: ACK 63e0be6 and merging... Tree-SHA512: cb1f7c23abb5b7b3af50bba18652cc2cad93fd7c2fca9c16ffd3fee34c4c152a3b666dfa87fe6b44c430064dcdee4367144dcb4a41203c91b0173b805bdb3d7d
Drop boost::scoped_array and simplify the code.
TCHAR
should be defined aswchar_t
ifUNICODE
is defined. So we can use.toStdWString().c_str()
to get wchar_t C-style string.Fix #13819