Add new files for vcprojs, fix issues: 165, 211, 228, 240

pull/3335/head
liujisi@google.com 14 years ago
parent b4d64bf7f3
commit 1fd96c43a0
  1. 98
      m4/stl_hash.m4
  2. 2
      python/google/protobuf/text_format.py
  3. 7
      src/google/protobuf/compiler/importer.cc
  4. 18
      src/google/protobuf/stubs/common.cc
  5. 29
      src/google/protobuf/stubs/common.h
  6. 8
      vsprojects/libprotoc.vcproj

@ -1,60 +1,72 @@
# We check two things: where the include file is for hash_map, and # We check two things: where the include file is for
# what namespace hash_map lives in within that include file. We # unordered_map/hash_map (we prefer the first form), and what
# namespace unordered/hash_map lives in within that include file. We
# include AC_TRY_COMPILE for all the combinations we've seen in the # include AC_TRY_COMPILE for all the combinations we've seen in the
# wild. We define one of HAVE_HASH_MAP or HAVE_EXT_HASH_MAP depending # wild. We define HASH_MAP_H to the location of the header file, and
# on location, and HASH_NAMESPACE to be the namespace hash_map is # HASH_NAMESPACE to the namespace the class (unordered_map or
# defined in. # hash_map) is in. We define HAVE_UNORDERED_MAP if the class we found
# # is named unordered_map, or leave it undefined if not.
# Ideally we'd use AC_CACHE_CHECK, but that only lets us store one value
# at a time, and we need to store two (filename and namespace).
# prints messages itself, so we have to do the message-printing ourselves
# via AC_MSG_CHECKING + AC_MSG_RESULT. (TODO(csilvers): can we cache?)
# This also checks if unordered map exists.
AC_DEFUN([AC_CXX_STL_HASH], AC_DEFUN([AC_CXX_STL_HASH],
[AC_MSG_CHECKING(the location of hash_map) [
AC_LANG_SAVE AC_MSG_CHECKING(the location of hash_map)
AC_LANG_SAVE
AC_LANG_CPLUSPLUS AC_LANG_CPLUSPLUS
ac_cv_cxx_hash_map_header="" ac_cv_cxx_hash_map=""
ac_cv_cxx_hash_map_class="" # First try unordered_map, but not on gcc's before 4.2 -- I've
for location in [tr1/unordered_map ext/hash_map hash_map]; do # seen unexplainable unordered_map bugs with -O2 on older gcc's.
for namespace in [std::tr1 __gnu_cxx "" std stdext]; do AC_TRY_COMPILE([#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
for name in [unordered_map hash_map]; do # error GCC too old for unordered_map
#endif
if test -z "$ac_cv_cxx_hash_map_header"; then ],
[/* no program body necessary */],
# On OSX 1.5 / GCC 4.0.1 (the standard compiler on that platform), [stl_hash_old_gcc=no],
# calling find() on a const unordered_map does not compile. So, we [stl_hash_old_gcc=yes])
# include a call to find() in our test to detect this broken for location in unordered_map tr1/unordered_map; do
# implementation and avoid using it. Note that ext/hash_map works for namespace in std std::tr1; do
# fine on this platform, so we'll end up using that. if test -z "$ac_cv_cxx_hash_map" -a "$stl_hash_old_gcc" != yes; then
AC_TRY_COMPILE([#include <$location>], # Some older gcc's have a buggy tr1, so test a bit of code.
[const ${namespace}::$name<int, int> t; AC_TRY_COMPILE([#include <$location>],
t.find(1);], [const ${namespace}::unordered_map<int, int> t;
[ac_cv_cxx_hash_map_header="<$location>"; return t.find(5) == t.end();],
ac_cv_cxx_hash_namespace="$namespace"; [ac_cv_cxx_hash_map="<$location>";
ac_cv_cxx_hash_map_class="$name";]) ac_cv_cxx_hash_namespace="$namespace";
fi ac_cv_cxx_hash_map_class="unordered_map";])
done fi
done done
done done
ac_cv_cxx_hash_set_header=`echo "$ac_cv_cxx_hash_map_header" | sed s/map/set/`; # Now try hash_map
for location in ext/hash_map hash_map; do
for namespace in __gnu_cxx "" std stdext; do
if test -z "$ac_cv_cxx_hash_map"; then
AC_TRY_COMPILE([#include <$location>],
[${namespace}::hash_map<int, int> t],
[ac_cv_cxx_hash_map="<$location>";
ac_cv_cxx_hash_namespace="$namespace";
ac_cv_cxx_hash_map_class="hash_map";])
fi
done
done
ac_cv_cxx_hash_set=`echo "$ac_cv_cxx_hash_map" | sed s/map/set/`;
ac_cv_cxx_hash_set_class=`echo "$ac_cv_cxx_hash_map_class" | sed s/map/set/`; ac_cv_cxx_hash_set_class=`echo "$ac_cv_cxx_hash_map_class" | sed s/map/set/`;
if test -n "$ac_cv_cxx_hash_map_header"; then if test -n "$ac_cv_cxx_hash_map"; then
AC_DEFINE(HAVE_HASH_MAP, 1, [define if the compiler has hash_map]) AC_DEFINE(HAVE_HASH_MAP, 1, [define if the compiler has hash_map])
AC_DEFINE(HAVE_HASH_SET, 1, [define if the compiler has hash_set]) AC_DEFINE(HAVE_HASH_SET, 1, [define if the compiler has hash_set])
AC_DEFINE_UNQUOTED(HASH_MAP_H,$ac_cv_cxx_hash_map_header, AC_DEFINE_UNQUOTED(HASH_MAP_H,$ac_cv_cxx_hash_map,
[the location of <hash_map>]) [the location of <unordered_map> or <hash_map>])
AC_DEFINE_UNQUOTED(HASH_SET_H,$ac_cv_cxx_hash_set_header, AC_DEFINE_UNQUOTED(HASH_SET_H,$ac_cv_cxx_hash_set,
[the location of <hash_set>]) [the location of <unordered_set> or <hash_set>])
AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace,
[the namespace of hash_map/hash_set])
AC_DEFINE_UNQUOTED(HASH_MAP_CLASS,$ac_cv_cxx_hash_map_class, AC_DEFINE_UNQUOTED(HASH_MAP_CLASS,$ac_cv_cxx_hash_map_class,
[the name of <hash_set>]) [the name of <hash_map>])
AC_DEFINE_UNQUOTED(HASH_SET_CLASS,$ac_cv_cxx_hash_set_class, AC_DEFINE_UNQUOTED(HASH_SET_CLASS,$ac_cv_cxx_hash_set_class,
[the name of <hash_set>]) [the name of <hash_set>])
AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace, AC_MSG_RESULT([$ac_cv_cxx_hash_map])
[the namespace of hash_map/hash_set])
AC_MSG_RESULT([$ac_cv_cxx_hash_map_header])
else else
AC_MSG_RESULT() AC_MSG_RESULT()
AC_MSG_WARN([could not find an STL hash_map]) AC_MSG_WARN([could not find an STL hash_map])
fi fi
]) ])

@ -222,7 +222,7 @@ def _MergeField(tokenizer, message):
sub_message = message.Extensions[field] sub_message = message.Extensions[field]
else: else:
sub_message = getattr(message, field.name) sub_message = getattr(message, field.name)
sub_message.SetInParent() sub_message.SetInParent()
while not tokenizer.TryConsume(end_token): while not tokenizer.TryConsume(end_token):
if tokenizer.AtEnd(): if tokenizer.AtEnd():

@ -231,7 +231,12 @@ static string CanonicalizePath(string path) {
// The Win32 API accepts forward slashes as a path delimiter even though // The Win32 API accepts forward slashes as a path delimiter even though
// backslashes are standard. Let's avoid confusion and use only forward // backslashes are standard. Let's avoid confusion and use only forward
// slashes. // 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 #endif
vector<string> parts; vector<string> parts;

@ -177,12 +177,6 @@ LogMessage::LogMessage(LogLevel level, const char* filename, int line)
: level_(level), filename_(filename), line_(line) {} : level_(level), filename_(filename), line_(line) {}
LogMessage::~LogMessage() {} LogMessage::~LogMessage() {}
#if defined(_MSC_VER) && defined(_CPPUNWIND)
#define PROTOBUF_USE_EXCEPTIONS
#elif defined(__EXCEPTIONS)
#define PROTOBUF_USE_EXCEPTIONS
#endif
void LogMessage::Finish() { void LogMessage::Finish() {
bool suppress = false; bool suppress = false;
@ -198,15 +192,13 @@ void LogMessage::Finish() {
if (level_ == LOGLEVEL_FATAL) { if (level_ == LOGLEVEL_FATAL) {
#ifdef PROTOBUF_USE_EXCEPTIONS #ifdef PROTOBUF_USE_EXCEPTIONS
throw -1; throw FatalException(filename_, line_, message_);
#else #else
abort(); abort();
#endif #endif
} }
} }
#undef PROTOBUF_USE_EXCEPTIONS
void LogFinisher::operator=(LogMessage& other) { void LogFinisher::operator=(LogMessage& other) {
other.Finish(); other.Finish();
} }
@ -373,5 +365,13 @@ void ShutdownProtobufLibrary() {
internal::shutdown_functions_mutex = NULL; 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 protobuf
} // namespace google } // namespace google

@ -48,6 +48,15 @@
#include <stdint.h> #include <stdint.h>
#endif #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) #if defined(_WIN32) && defined(GetMessage)
// Allow GetMessage to be used as a valid method name in protobuf classes. // 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 // 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 } // 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 // This is at the end of the file instead of the beginning to work around a bug
// in some versions of MSVC. // in some versions of MSVC.
using namespace std; // Don't do this at home, kids. using namespace std; // Don't do this at home, kids.

@ -263,6 +263,10 @@
RelativePath="..\src\google\protobuf\compiler\java\java_service.h" RelativePath="..\src\google\protobuf\compiler\java\java_service.h"
> >
</File> </File>
<File
RelativePath="..\src\google\protobuf\compiler\java\java_string_field.h"
>
</File>
<File <File
RelativePath="..\src\google\protobuf\compiler\python\python_generator.h" RelativePath="..\src\google\protobuf\compiler\python\python_generator.h"
> >
@ -395,6 +399,10 @@
RelativePath="..\src\google\protobuf\compiler\java\java_service.cc" RelativePath="..\src\google\protobuf\compiler\java\java_service.cc"
> >
</File> </File>
<File
RelativePath="..\src\google\protobuf\compiler\java\java_string_filed.cc"
>
</File>
<File <File
RelativePath="..\src\google\protobuf\compiler\python\python_generator.cc" RelativePath="..\src\google\protobuf\compiler\python\python_generator.cc"
> >

Loading…
Cancel
Save