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

convert path to the native locale before passing to boost::interprocess::file_mapping() #838

Merged
merged 3 commits into from Jun 5, 2018

Conversation

@yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented May 1, 2018

fixes #834, fixes #837

As described on #834, the behavior of normalizePath() (more precisely, path.expand(), which is used inside normalizePath()) has been changed to return the character encoded in UTF-8. I guess this happens only with Windows on non-UTF-8 locales.

R 3.4.4 on Windows 10:

Encoding(normalizePath("~/鬼"))
#> [1] "unknown"

R 3.5.0 on Windows 10:

Encoding(normalizePath("~/鬼"))
#> [1] "UTF-8"

This usually doesn't become a problem; on R codes, most R functions take care of the encoding automatically. But, on C++ codes, the encoding attribute is lost when the String is converted to std::string. So, we need to convert it to the proper encoding before passing it to the functions that take std::string, in this case, boost::interprocess::file_mapping() here:

readr/src/SourceFile.h

Lines 19 to 20 in 6f0bb65

fm_ = boost::interprocess::file_mapping(
path.c_str(), boost::interprocess::read_only);

It seems boost::interprocess::file_mapping() takes the path string encoded in the native locale (CE_NATIVE). So, we need to ensure the string is encoded properly, instead of blindly pass the one passed from R session.

IIUC, Rcpp doesn't have a function to do this, so Rf_translateChar() is the choice in this case. (I'm not an Rcpp expert, so please point out if I'm wrong at this point....)

@yutannihilation
Copy link
Member Author

@yutannihilation yutannihilation commented May 9, 2018

@jimhester Do you also prefer enc2native(normalizePath()) solution here as with the case of readxl?

Copy link
Member

@jimhester jimhester left a comment

Could you add a note mentioning this change and the PR number and we can merge this

@@ -18,8 +18,8 @@ SourcePtr Source::create(List spec) {
return SourcePtr(
new SourceString(as<CharacterVector>(spec[0]), skip, comment));
} else if (subclass == "source_file") {
std::string path(as<CharacterVector>(spec[0])[0]);
return SourcePtr(new SourceFile(path, skip, comment));
SEXP path(as<CharacterVector>(spec[0])[0]);

This comment has been minimized.

@jimhester

jimhester May 10, 2018
Member

I think it is more clear if this is a CharacterVector rather than a SEXP.

@yutannihilation
Copy link
Member Author

@yutannihilation yutannihilation commented May 10, 2018

Thanks for the comment about avoiding vague SEXP. I've made a change. Is this what you mean?

@yutannihilation
Copy link
Member Author

@yutannihilation yutannihilation commented Jun 4, 2018

@jimhester Do I need to make more changes? If no, I think this is ready to merge now :)

@jimhester
Copy link
Member

@jimhester jimhester commented Jun 5, 2018

Thanks!

@jimhester jimhester merged commit c662432 into tidyverse:master Jun 5, 2018
4 checks passed
4 checks passed
@codecov
codecov/patch 100% of diff hit (target 79.87%)
Details
@codecov
codecov/project 79.87% (+0%) compared to 47ea858
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@yutannihilation
Copy link
Member Author

@yutannihilation yutannihilation commented Jun 5, 2018

Thanks for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants