Skip to content

Commit

Permalink
Clean up comments, remove print debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed May 9, 2022
1 parent bdecf47 commit 1023b1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
41 changes: 18 additions & 23 deletions src/unicode_fopen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand All @@ -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
}
3 changes: 0 additions & 3 deletions src/vroom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1023b1c

Please sign in to comment.