Skip to content
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

gui: Drop boost::scoped_array and use wchar_t API explicitly on Windows #13734

Merged
merged 2 commits into from Sep 11, 2018

Conversation

8 participants
@ken2812221
Copy link
Member

commented Jul 21, 2018

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

@MarcoFalke MarcoFalke added the GUI label Jul 22, 2018

@MarcoFalke MarcoFalke changed the title Drop boost::scoped_array gui: Drop boost::scoped_array Jul 22, 2018

@fanquake fanquake added this to In progress in Boost → C++11 migration Jul 22, 2018

@fanquake

This comment has been minimized.

Copy link
Member

commented Jul 22, 2018

This was introduced in #5793. Looks like something similar to what you are doing was proposed at the time as well.

@ken2812221

This comment has been minimized.

Copy link
Member Author

commented Jul 22, 2018

Hope there is a way to see code that is before he force push.

@practicalswift

This comment has been minimized.

Copy link
Member

commented Jul 22, 2018

Concept ACK

Thanks for removing Boost dependencies. Keep it coming! :-)

@MarcoFalke

This comment has been minimized.

Copy link
Member

commented Jul 22, 2018

Any suggestion on how to test this?

@ken2812221

This comment has been minimized.

Copy link
Member Author

commented Jul 22, 2018

This is Windows-only code, can be tested as same as #5793 (comment)

@Sjors
Copy link
Member

left a comment

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:

schermafbeelding 2018-07-24 om 17 43 26

I have a version from earlier this year where it leads to a slightly nicer crash:
schermafbeelding 2018-07-24 om 17 46 37

(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

This comment has been minimized.

Copy link
@Sjors

Sjors Jul 24, 2018

Member

Add a comment that UNICODE is only defined for Windows? (if that's the case)

@ken2812221 ken2812221 force-pushed the ken2812221:drop-boost-scoped-array branch Jul 29, 2018

@ken2812221

This comment has been minimized.

Copy link
Member Author

commented Jul 29, 2018

Update: Since the goal is to make it unicode compatible, just make it use wchar_t version of api explicitly.

@ken2812221 ken2812221 changed the title gui: Drop boost::scoped_array gui: Drop boost::scoped_array and use wchar_t API explicitly on Windows Jul 29, 2018

reinterpret_cast<void**>(&psl));

if (SUCCEEDED(hres))
{
// Get the current executable path
TCHAR pszExePath[MAX_PATH];
GetModuleFileName(nullptr, pszExePath, sizeof(pszExePath));

This comment has been minimized.

Copy link
@ken2812221

ken2812221 Jul 29, 2018

Author Member

This is bug before, if TCHAR is wchar_t, then sizeof(pszExePath)= 2*MAX_PATH, which can result memory overflow.

@Sjors

This comment has been minimized.

Copy link
Member

commented Jul 30, 2018

Tested that make still works on macOS with 5d70ab0. I have no opinion on the code itself, other than it seems good to keep making progress here: https://github.com/bitcoin/bitcoin/projects/3#card-205363

@MarcoFalke

This comment has been minimized.

Copy link
Member

commented Jul 31, 2018

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))

screenshot from 2018-07-31 10-13-36

@MarcoFalke MarcoFalke requested a review from jonasschnelli Jul 31, 2018

@ken2812221 ken2812221 force-pushed the ken2812221:drop-boost-scoped-array branch Jul 31, 2018

@ken2812221

This comment has been minimized.

Copy link
Member Author

commented Jul 31, 2018

@MarcoFalke Can you test this again? Now it should fix #13819.

@MarcoFalke MarcoFalke added this to the 0.17.0 milestone Jul 31, 2018

@MarcoFalke

This comment has been minimized.

Copy link
Member

commented Aug 1, 2018

Now it fails for commit d41914b (master and this pull) that it can not write to the directory:

(though the folders are created, as can be seen in the explorer in the background)

screenshot from 2018-08-01 11-35-25

@MarcoFalke MarcoFalke modified the milestones: 0.17.0, 0.18.0 Aug 1, 2018

@ken2812221

This comment has been minimized.

Copy link
Member Author

commented Aug 1, 2018

@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];

This comment has been minimized.

Copy link
@Empact

Empact Aug 3, 2018

Member

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

This comment has been minimized.

Copy link
@ken2812221

ken2812221 Aug 3, 2018

Author Member

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"";

This comment has been minimized.

Copy link
@Empact

Empact Aug 3, 2018

Member

Same, WCHAR seems preferable.

This comment has been minimized.

Copy link
@ken2812221

ken2812221 Aug 3, 2018

Author Member

fixed

@DrahtBot

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2018

No more conflicts as of last run.

@ken2812221 ken2812221 force-pushed the ken2812221:drop-boost-scoped-array branch Aug 3, 2018


if(SHGetSpecialFolderPathA(nullptr, pszPath, nFolder, fCreate))
if(SHGetSpecialFolderPathW(nullptr, pszPath, nFolder, fCreate))

This comment has been minimized.

Copy link
@Empact

Empact Aug 3, 2018

Member

nit: the failure message below references SHGetSpecialFolderPathA

This comment has been minimized.

Copy link
@ken2812221

ken2812221 Aug 3, 2018

Author Member

fixed

@Empact

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

utACK b446918

@ken2812221 ken2812221 force-pushed the ken2812221:drop-boost-scoped-array branch to bb6ca65 Aug 3, 2018

@ken2812221 ken2812221 referenced this pull request Aug 3, 2018

Closed

Filename and command line encoding issue on Windows #13869

11 of 12 tasks complete

@ken2812221 ken2812221 closed this Aug 21, 2018

@ken2812221 ken2812221 reopened this Aug 21, 2018

@bitcoin bitcoin deleted a comment from DrahtBot Aug 21, 2018

@bitcoin bitcoin deleted a comment from DrahtBot Aug 21, 2018

@laanwj

This comment has been minimized.

Copy link
Member

commented Sep 11, 2018

nice cleanup, too

utACK bb6ca65

@laanwj laanwj merged commit bb6ca65 into bitcoin:master Sep 11, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

laanwj added a commit that referenced this pull request Sep 11, 2018

Merge #13734: gui: Drop boost::scoped_array and use wchar_t API expli…
…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

@ken2812221 ken2812221 deleted the ken2812221:drop-boost-scoped-array branch Sep 11, 2018

@fanquake fanquake moved this from In progress to Done in Boost → C++11 migration Sep 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.