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

utils: Use _wfopen and _wfreopen on Windows #13866

Merged
merged 1 commit into from Sep 11, 2018

Conversation

Projects
None yet
8 participants
@ken2812221
Copy link
Member

commented Aug 3, 2018

The fopen function does not support unicode filename on Windows, so use Windows specific function do deal with it.

@ken2812221 ken2812221 force-pushed the ken2812221:fopen-windows branch Aug 3, 2018

@Empact

This comment has been minimized.

@ken2812221

This comment has been minimized.

Copy link
Member Author

commented Aug 3, 2018

@Empact They are the same if we ignore the errno.

@ken2812221 ken2812221 referenced this pull request Aug 3, 2018

Closed

Filename and command line encoding issue on Windows #13869

11 of 12 tasks complete
@DrahtBot

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2018

No more conflicts as of last run.
src/utilstrencodings.cpp Outdated
#ifdef WIN32
std::wstring Utf8ToWide(const std::string& utf8_string)
{
size_t size = MultiByteToWideChar(CP_UTF8, 0, &*utf8_string.begin(), utf8_string.size(), nullptr, 0);

This comment has been minimized.

Copy link
@donaloconnor

donaloconnor Aug 3, 2018

Contributor

I find the &* unnecessarily complicated. Can you use utf8_string.data() or even the more usual c_str() instead that gives a direct pointer back.

This comment has been minimized.

Copy link
@ken2812221

ken2812221 Aug 3, 2018

Author Member

This avoid the unnecessary copy, &*utf8_string.begin() point to where the exact string data are. c_str() and data() is a copy of the string data.

This comment has been minimized.

Copy link
@donaloconnor

donaloconnor Aug 4, 2018

Contributor

Not sure what implementation you are referring to but c_str and data have always returned the pointer to the internal data. Not a copy. Anyway it was just a nitpick. Thanks.

src/utilstrencodings.cpp Outdated
size_t size = MultiByteToWideChar(CP_UTF8, 0, &*utf8_string.begin(), utf8_string.size(), nullptr, 0);
std::wstring wide_string(size, 0);
size = MultiByteToWideChar(CP_UTF8, 0, &*utf8_string.begin(), utf8_string.size(), &*wide_string.begin(), wide_string.size());
assert(size == wide_string.size());

This comment has been minimized.

Copy link
@donaloconnor

donaloconnor Aug 3, 2018

Contributor

Is this assert necessary? MultiByteToWideChar won't change the size of the string.

This comment has been minimized.

Copy link
@ken2812221

ken2812221 Aug 3, 2018

Author Member

They won't change, so that's why I use assert instead of a bunch of error handling.

This comment has been minimized.

Copy link
@donaloconnor

donaloconnor Aug 4, 2018

Contributor

I didn't spot the size= part before the asset. Sorry :)

src/fs.cpp Outdated
@@ -1,15 +1,24 @@
#include <fs.h>
#include <utilstrencodings.h>

This comment has been minimized.

Copy link
@practicalswift

practicalswift Aug 4, 2018

Member

nit: Make this include conditional on WIN32?

@ken2812221 ken2812221 force-pushed the ken2812221:fopen-windows branch 5 times, most recently Aug 4, 2018

@ken2812221

This comment has been minimized.

Copy link
Member Author

commented Aug 5, 2018

Update: use std codecvt instead of custom converter.

@ken2812221 ken2812221 changed the title utils: Use _wfopen and _wreopen on Windows utils: Use _wfopen and _wfreopen on Windows Aug 16, 2018

@laanwj laanwj added this to Blockers in High-priority for review Aug 16, 2018

@ken2812221 ken2812221 force-pushed the ken2812221:fopen-windows branch Aug 21, 2018

@ken2812221 ken2812221 force-pushed the ken2812221:fopen-windows branch Aug 29, 2018

@DrahtBot DrahtBot removed the Needs rebase label Aug 29, 2018

@laanwj laanwj removed this from Blockers in High-priority for review Aug 30, 2018

utils: Use _wfopen and _wreopen on Windows
The fopen function does not support unicode filename on Windows, so use Windows specific function do deal with it
@ryanofsky
Copy link
Contributor

left a comment

utACK b9babc8

@laanwj

This comment has been minimized.

Copy link
Member

commented Sep 11, 2018

utACK b9babc8

@laanwj laanwj merged commit b9babc8 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 #13866: utils: Use _wfopen and _wfreopen on Windows
b9babc8 utils: Use _wfopen and _wreopen on Windows (Chun Kuan Lee)

Pull request description:

  The fopen function does not support unicode filename on Windows, so use Windows specific function do deal with it.

Tree-SHA512: 4dcf14dcf9ec6307b9fdf95404e5b6b6b3df640949fd4b0c4ac7fecf8ea03a64fa25285fc319c4ff8a28e586eee106f1861116c181694955497402b2bf575f22

@ken2812221 ken2812221 deleted the ken2812221:fopen-windows branch Sep 11, 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.