From 1fd96c43a01ec913a89de31c58c0bc9f1e5bf542 Mon Sep 17 00:00:00 2001 From: "liujisi@google.com" Date: Tue, 7 Dec 2010 06:23:55 +0000 Subject: Add new files for vcprojs, fix issues: 165, 211, 228, 240 --- src/google/protobuf/compiler/importer.cc | 7 ++++++- src/google/protobuf/stubs/common.cc | 18 +++++++++--------- src/google/protobuf/stubs/common.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc index 7689ce93..422f759f 100644 --- a/src/google/protobuf/compiler/importer.cc +++ b/src/google/protobuf/compiler/importer.cc @@ -231,7 +231,12 @@ static string CanonicalizePath(string path) { // The Win32 API accepts forward slashes as a path delimiter even though // backslashes are standard. Let's avoid confusion and use only forward // slashes. - path = StringReplace(path, "\\", "/", true); + if (HasPrefixString(path, "\\\\")) { + // Avoid converting two leading backslashes. + path = "\\\\" + StringReplace(path.substr(2), "\\", "/", true); + } else { + path = StringReplace(path, "\\", "/", true); + } #endif vector parts; diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index 34a7d139..7b15be44 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc @@ -177,12 +177,6 @@ LogMessage::LogMessage(LogLevel level, const char* filename, int line) : level_(level), filename_(filename), line_(line) {} LogMessage::~LogMessage() {} -#if defined(_MSC_VER) && defined(_CPPUNWIND) - #define PROTOBUF_USE_EXCEPTIONS -#elif defined(__EXCEPTIONS) - #define PROTOBUF_USE_EXCEPTIONS -#endif - void LogMessage::Finish() { bool suppress = false; @@ -198,15 +192,13 @@ void LogMessage::Finish() { if (level_ == LOGLEVEL_FATAL) { #ifdef PROTOBUF_USE_EXCEPTIONS - throw -1; + throw FatalException(filename_, line_, message_); #else abort(); #endif } } -#undef PROTOBUF_USE_EXCEPTIONS - void LogFinisher::operator=(LogMessage& other) { other.Finish(); } @@ -373,5 +365,13 @@ void ShutdownProtobufLibrary() { internal::shutdown_functions_mutex = NULL; } +#ifdef PROTOBUF_USE_EXCEPTIONS +FatalException::~FatalException() throw() {} + +const char* FatalException::what() const throw() { + return message_.c_str(); +} +#endif + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 0b4df8a9..5c2bdc51 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -48,6 +48,15 @@ #include #endif +#if defined(_MSC_VER) && defined(_CPPUNWIND) + #define PROTOBUF_USE_EXCEPTIONS +#elif defined(__EXCEPTIONS) + #define PROTOBUF_USE_EXCEPTIONS +#endif +#ifdef PROTOBUF_USE_EXCEPTIONS +#include +#endif + #if defined(_WIN32) && defined(GetMessage) // Allow GetMessage to be used as a valid method name in protobuf classes. // windows.h defines GetMessage() as a macro. Let's re-define it as an inline @@ -1172,6 +1181,26 @@ LIBPROTOBUF_EXPORT void OnShutdown(void (*func)()); } // namespace internal +#ifdef PROTOBUF_USE_EXCEPTIONS +class FatalException : public std::exception { + public: + FatalException(const char* filename, int line, const std::string& message) + : filename_(filename), line_(line), message_(message) {} + virtual ~FatalException() throw(); + + virtual const char* what() const throw(); + + const char* filename() const { return filename_; } + int line() const { return line_; } + const std::string& message() const { return message_; } + + private: + const char* filename_; + const int line_; + const std::string message_; +}; +#endif + // This is at the end of the file instead of the beginning to work around a bug // in some versions of MSVC. using namespace std; // Don't do this at home, kids. -- cgit v1.2.3