aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf
diff options
context:
space:
mode:
authorGravatar liujisi@google.com <liujisi@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2010-12-07 06:23:55 +0000
committerGravatar liujisi@google.com <liujisi@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2010-12-07 06:23:55 +0000
commit1fd96c43a01ec913a89de31c58c0bc9f1e5bf542 (patch)
treefd75a0bffe10b1e57155cbf70d32d41e44302be0 /src/google/protobuf
parentb4d64bf7f3aa65318a5262977e59f42595c4c5d0 (diff)
Add new files for vcprojs, fix issues: 165, 211, 228, 240
Diffstat (limited to 'src/google/protobuf')
-rw-r--r--src/google/protobuf/compiler/importer.cc7
-rw-r--r--src/google/protobuf/stubs/common.cc18
-rw-r--r--src/google/protobuf/stubs/common.h29
3 files changed, 44 insertions, 10 deletions
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<string> 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 <stdint.h>
#endif
+#if defined(_MSC_VER) && defined(_CPPUNWIND)
+ #define PROTOBUF_USE_EXCEPTIONS
+#elif defined(__EXCEPTIONS)
+ #define PROTOBUF_USE_EXCEPTIONS
+#endif
+#ifdef PROTOBUF_USE_EXCEPTIONS
+#include <exception>
+#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.