-
Notifications
You must be signed in to change notification settings - Fork 285
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
convert path to the native locale before passing to boost::interprocess::file_mapping() #838
Conversation
@jimhester Do you also prefer |
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.
Could you add a note mentioning this change and the PR number and we can merge this
src/Source.cpp
Outdated
@@ -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]); |
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 it is more clear if this is a CharacterVector rather than a SEXP.
Thanks for the comment about avoiding vague |
@jimhester Do I need to make more changes? If no, I think this is ready to merge now :) |
Thanks! |
Thanks for merging! |
fixes #834, fixes #837
As described on #834, the behavior of
normalizePath()
(more precisely,path.expand()
, which is used insidenormalizePath()
) 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:
R 3.5.0 on Windows 10:
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 tostd::string
. So, we need to convert it to the proper encoding before passing it to the functions that takestd::string
, in this case,boost::interprocess::file_mapping()
here:readr/src/SourceFile.h
Lines 19 to 20 in 6f0bb65
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....)