From 055dc308ee6e8c238c487ee88fdabb8754f59446 Mon Sep 17 00:00:00 2001 From: Deepak Majeti Date: Sat, 16 Sep 2017 22:51:06 -0400 Subject: [PATCH 1/3] ARROW-1536:[C++] Do not transitively depend on libboost_system --- cpp/src/arrow/io/file.cc | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/cpp/src/arrow/io/file.cc b/cpp/src/arrow/io/file.cc index 0abadbb16af..d3c5c5d50b3 100644 --- a/cpp/src/arrow/io/file.cc +++ b/cpp/src/arrow/io/file.cc @@ -107,16 +107,33 @@ #include "arrow/status.h" #include "arrow/util/logging.h" +namespace arrow { +namespace io { + +#if defined(__MSC_VER__) #include // NOLINT #include // NOLINT - +#define PlatformFilename fs::path namespace fs = boost::filesystem; +#else +struct PlatformFilename { + static Status Init(const std::string& utf8_path, PlatformFilename* out) { + out->utf8_path = utf8_path; + return Status::OK(); + } -namespace arrow { -namespace io { + const char* c_str() const { return utf8_path.c_str(); } + + const std::string string() const { return utf8_path; } + + size_t length() const { return utf8_path.size(); } + + std::string utf8_path; +}; +#endif static inline Status CheckOpenResult(int ret, int errno_actual, - const fs::path& file_name) { + const PlatformFilename& file_name) { if (ret == -1) { // TODO: errno codes to strings std::stringstream ss; @@ -137,7 +154,7 @@ static inline int64_t lseek64_compat(int fd, int64_t pos, int whence) { #endif } -static inline Status FileOpenReadable(const fs::path& file_name, int* fd) { +static inline Status FileOpenReadable(const PlatformFilename& file_name, int* fd) { int ret; errno_t errno_actual = 0; #if defined(_MSC_VER) @@ -152,7 +169,7 @@ static inline Status FileOpenReadable(const fs::path& file_name, int* fd) { return CheckOpenResult(ret, errno_actual, file_name); } -static inline Status FileOpenWriteable(const fs::path& file_name, bool write_only, +static inline Status FileOpenWriteable(const PlatformFilename& file_name, bool write_only, bool truncate, int* fd) { int ret; errno_t errno_actual = 0; @@ -366,20 +383,20 @@ class OSFile { protected: Status SetFileName(const std::string& file_name) { - try { #if defined(_MSC_VER) + try { std::codecvt_utf8_utf16 utf16_converter; file_name_.assign(file_name, utf16_converter); -#else - file_name_ = file_name; -#endif } catch (boost::system::system_error& e) { return Status::Invalid(e.what()); } +#else + PlatformFilename::Init(file_name, &file_name_); +#endif return Status::OK(); } - fs::path file_name_; + PlatformFilename file_name_; std::mutex lock_; From d49e1aa06074b712adfad6ed4d7c67bdd369a83c Mon Sep 17 00:00:00 2001 From: Deepak Majeti Date: Sun, 17 Sep 2017 07:38:09 -0400 Subject: [PATCH 2/3] Fix failure --- cpp/src/arrow/io/file.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cpp/src/arrow/io/file.cc b/cpp/src/arrow/io/file.cc index d3c5c5d50b3..2de2df8fe04 100644 --- a/cpp/src/arrow/io/file.cc +++ b/cpp/src/arrow/io/file.cc @@ -107,15 +107,19 @@ #include "arrow/status.h" #include "arrow/util/logging.h" -namespace arrow { -namespace io { - -#if defined(__MSC_VER__) +#if defined(_MSC_VER) #include // NOLINT #include // NOLINT -#define PlatformFilename fs::path namespace fs = boost::filesystem; +#define PlatformFilename fs::path + +namespace arrow { +namespace io { + #else +namespace arrow { +namespace io { + struct PlatformFilename { static Status Init(const std::string& utf8_path, PlatformFilename* out) { out->utf8_path = utf8_path; @@ -391,7 +395,7 @@ class OSFile { return Status::Invalid(e.what()); } #else - PlatformFilename::Init(file_name, &file_name_); + RETURN_NOT_OK(PlatformFilename::Init(file_name, &file_name_)); #endif return Status::OK(); } From 9f4ed610716a93a101b6292886787fbb23d5ab3f Mon Sep 17 00:00:00 2001 From: Deepak Majeti Date: Mon, 18 Sep 2017 18:19:55 -0400 Subject: [PATCH 3/3] Review comments --- cpp/src/arrow/io/file.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cpp/src/arrow/io/file.cc b/cpp/src/arrow/io/file.cc index 2de2df8fe04..843cfe89fc0 100644 --- a/cpp/src/arrow/io/file.cc +++ b/cpp/src/arrow/io/file.cc @@ -121,14 +121,12 @@ namespace arrow { namespace io { struct PlatformFilename { - static Status Init(const std::string& utf8_path, PlatformFilename* out) { - out->utf8_path = utf8_path; - return Status::OK(); - } + PlatformFilename() {} + explicit PlatformFilename(const std::string& path) { utf8_path = path; } const char* c_str() const { return utf8_path.c_str(); } - const std::string string() const { return utf8_path; } + const std::string& string() const { return utf8_path; } size_t length() const { return utf8_path.size(); } @@ -395,7 +393,7 @@ class OSFile { return Status::Invalid(e.what()); } #else - RETURN_NOT_OK(PlatformFilename::Init(file_name, &file_name_)); + file_name_ = PlatformFilename(file_name); #endif return Status::OK(); }