diff --git a/src/unicode_fopen.h b/src/unicode_fopen.h index 292de57b..eac96dc7 100644 --- a/src/unicode_fopen.h +++ b/src/unicode_fopen.h @@ -20,22 +20,23 @@ #include "cpp11/r_string.hpp" #endif -inline void print_hex(const char* string) { - unsigned char* p = (unsigned char*) string; - for (int i = 0; i < 300 ; i++) { - if (p[i] == '\0') break; - Rprintf("%c 0x%02x ", p[i], p[i]); - if ((i%16 == 0) && i) - Rprintf("\n"); - } - Rprintf("\n"); -} +// useful for print debugging file path encoding +// inline void print_hex(const char* string) { +// unsigned char* p = (unsigned char*) string; +// for (int i = 0; i < 300 ; i++) { +// if (p[i] == '\0') break; +// Rprintf("%c 0x%02x ", p[i], p[i]); +// if ((i%16 == 0) && i) +// Rprintf("\n"); +// } +// Rprintf("\n"); +// } // This is needed to support wide character paths on windows inline FILE* unicode_fopen(const char* path, const char* mode) { FILE* out; #ifdef _WIN32 - // First conver the mode to the wide equivalent + // First convert the mode to the wide equivalent // Only usage is 2 characters so max 8 bytes + 2 byte null. wchar_t mode_w[10]; MultiByteToWideChar(CP_UTF8, 0, mode, -1, mode_w, 9); @@ -54,13 +55,10 @@ inline FILE* unicode_fopen(const char* path, const char* mode) { MultiByteToWideChar(CP_UTF8, 0, path, -1, buf, len); out = _wfopen(buf, mode_w); #else - // cpp11 will have converted the user's path to UTF-8 by now - // but we need to pass the path to fopen() in the native encoding - Rprintf("unicode_fopen() received path: %s\n", path); - print_hex(path); + // the path has UTF-8 encoding, because we do that unconditionally on the R + // side (but also because cpp11 is eager to use UTF-8) + // however, we need to pass the path to fopen() in the native encoding const char* native_path = Rf_translateChar(cpp11::r_string(path)); - Rprintf("Calling fopen() on native path: %s\n", native_path); - print_hex(native_path); out = fopen(native_path, mode); #endif @@ -85,13 +83,10 @@ make_mmap_source(const char* file, std::error_code& error) { free(buf); return out; #else - // cpp11 will have converted the user's path to UTF-8 by now - // but we need to pass the path to mio in the native encoding - Rprintf("make_mmap_source() received path: %s\n", file); - print_hex(file); + // the path has UTF-8 encoding, because we do that unconditionally on the R + // side (but also because cpp11 is eager to use UTF-8) + // however, we need to pass the path to fopen() in the native encoding const char* native_path = Rf_translateChar(cpp11::r_string(file)); - Rprintf("Calling mio::make_mmap_source() on native path: %s\n", native_path); - print_hex(native_path); return mio::make_mmap_source(native_path, error); #endif } diff --git a/src/vroom.cc b/src/vroom.cc index 08f30780..6fe129c6 100644 --- a/src/vroom.cc +++ b/src/vroom.cc @@ -95,12 +95,9 @@ [[cpp11::register]] bool has_trailing_newline(const cpp11::strings& filename) { std::FILE* f = unicode_fopen(CHAR(filename[0]), "rb"); - Rprintf("In has_trailing_newline(): "); if (!f) { - Rprintf("no file\n"); return true; } - Rprintf("yes file\n"); std::setvbuf(f, nullptr, _IONBF, 0);