diff --git a/3party/protobuf/CHANGES.txt b/3party/protobuf/CHANGES.txt index eebd57d321..737f865960 100644 --- a/3party/protobuf/CHANGES.txt +++ b/3party/protobuf/CHANGES.txt @@ -1,4 +1,86 @@ -2009-01-08 version 2.3.0: +2011-05-01 version 2.4.1: + + C++ + * Fixed the frendship problem for old compilers to make the library now gcc 3 + compatible again. + * Fixed vcprojects/extract_includes.bat to extract compiler/plugin.h. + + Java + * Removed usages of JDK 1.6 only features to make the library now JDK 1.5 + compatible again. + * Fixed a bug about negative enum values. + * serialVersionUID is now defined in generated messages for java serializing. + * Fixed protoc to use java.lang.Object, which makes "Object" now a valid + message name again. + + Python + * Experimental C++ implementation now requires C++ protobuf library installed. + See the README.txt in the python directory for details. + +2011-02-02 version 2.4.0: + + General + * The RPC (cc|java|py)_generic_services default value is now false instead of + true. + * Custom options can have aggregate types. For example, + message MyOption { + optional string comment = 1; + optional string author = 2; + } + extend google.protobuf.FieldOptions { + optional MyOption myoption = 12345; + } + This option can now be set as follows: + message SomeType { + optional int32 field = 1 [(myoption) = { comment:'x' author:'y' }]; + } + + C++ + * Various speed and code size optimizations. + * Added a release_foo() method on string and message fields. + * Fixed gzip_output_stream sub-stream handling. + + Java + * Builders now maintain sub-builders for sub-messages. Use getFooBuilder() to + get the builder for the sub-message "foo". This allows you to repeatedly + modify deeply-nested sub-messages without rebuilding them. + * Builder.build() no longer invalidates the Builder for generated messages + (You may continue to modify it and then build another message). + * Code generator will generate efficient equals() and hashCode() + implementations if new option java_generate_equals_and_hash is enabled. + (Otherwise, reflection-based implementations are used.) + * Generated messages now implement Serializable. + * Fields with [deprecated=true] will be marked with @Deprecated in Java. + * Added lazy conversion of UTF-8 encoded strings to String objects to improve + performance. + * Various optimizations. + * Enum value can be accessed directly, instead of calling getNumber() on the + enum member. + * For each enum value, an integer constant is also generated with the suffix + _VALUE. + + Python + * Added an experimental C++ implementation for Python messages via a Python + extension. Implementation type is controlled by an environment variable + PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION (valid values: "cpp" and "python") + The default value is currently "python" but will be changed to "cpp" in + future release. + * Improved performance on message instantiation significantly. + Most of the work on message instantiation is done just once per message + class, instead of once per message instance. + * Improved performance on text message parsing. + * Allow add() to forward keyword arguments to the concrete class. + E.g. instead of + item = repeated_field.add() + item.foo = bar + item.baz = quux + You can do: + repeated_field.add(foo=bar, baz=quux) + * Added a sort() interface to the BaseContainer. + * Added an extend() method to repeated composite fields. + * Added UTF8 debug string support. + +2010-01-08 version 2.3.0: General * Parsers for repeated numeric fields now always accept both packed and diff --git a/3party/protobuf/CONTRIBUTORS.txt b/3party/protobuf/CONTRIBUTORS.txt index a20efc4bed..b39ec308b3 100644 --- a/3party/protobuf/CONTRIBUTORS.txt +++ b/3party/protobuf/CONTRIBUTORS.txt @@ -80,5 +80,11 @@ Patch contributors: * Fixes for Solaris 10 32/64-bit confusion. Evan Jones * Optimize Java serialization code when writing a small message to a stream. + * Optimize Java serialization of strings so that UTF-8 encoding happens only + once per string per serialization call. + * Clean up some Java warnings. + * Fix bug with permanent callbacks that delete themselves when run. Michael Kucharski * Added CodedInputStream.getTotalBytesRead(). + Kacper Kowalik + * Fixed m4/acx_pthread.m4 problem for some Linux distributions. diff --git a/3party/protobuf/protobuf.pro b/3party/protobuf/protobuf.pro index c1bab343aa..cab4ed4926 100644 --- a/3party/protobuf/protobuf.pro +++ b/3party/protobuf/protobuf.pro @@ -25,7 +25,6 @@ SOURCES += \ src/google/protobuf/stubs/common.cc \ src/google/protobuf/extension_set.cc \ src/google/protobuf/generated_message_util.cc \ - src/google/protobuf/stubs/hash.cc \ src/google/protobuf/message_lite.cc \ src/google/protobuf/stubs/once.cc \ src/google/protobuf/repeated_field.cc \ diff --git a/3party/protobuf/src/google/protobuf/extension_set.cc b/3party/protobuf/src/google/protobuf/extension_set.cc index 729410ef9a..1a6f5dfc25 100644 --- a/3party/protobuf/src/google/protobuf/extension_set.cc +++ b/3party/protobuf/src/google/protobuf/extension_set.cc @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include @@ -186,6 +186,18 @@ int ExtensionSet::ExtensionSize(int number) const { return iter->second.GetSize(); } +FieldType ExtensionSet::ExtensionType(int number) const { + map::const_iterator iter = extensions_.find(number); + if (iter == extensions_.end()) { + GOOGLE_LOG(DFATAL) << "Don't lookup extension types if they aren't present (1). "; + return 0; + } + if (iter->second.is_cleared) { + GOOGLE_LOG(DFATAL) << "Don't lookup extension types if they aren't present (2). "; + } + return iter->second.type; +} + void ExtensionSet::ClearExtension(int number) { map::iterator iter = extensions_.find(number); if (iter == extensions_.end()) return; diff --git a/3party/protobuf/src/google/protobuf/extension_set.h b/3party/protobuf/src/google/protobuf/extension_set.h index 14d5d15089..ac1ada029f 100644 --- a/3party/protobuf/src/google/protobuf/extension_set.h +++ b/3party/protobuf/src/google/protobuf/extension_set.h @@ -39,11 +39,11 @@ #define GOOGLE_PROTOBUF_EXTENSION_SET_H__ #include -#include #include #include #include + #include namespace google { @@ -214,6 +214,7 @@ class LIBPROTOBUF_EXPORT ExtensionSet { bool Has(int number) const; int ExtensionSize(int number) const; // Size of a repeated extension. + FieldType ExtensionType(int number) const; void ClearExtension(int number); // singular fields ------------------------------------------------- @@ -451,6 +452,7 @@ class LIBPROTOBUF_EXPORT ExtensionSet { int SpaceUsedExcludingSelf() const; }; + // Gets the extension with the given number, creating it if it does not // already exist. Returns true if the extension did not already exist. bool MaybeNewExtension(int number, const FieldDescriptor* descriptor, diff --git a/3party/protobuf/src/google/protobuf/generated_message_util.cc b/3party/protobuf/src/google/protobuf/generated_message_util.cc index 7ac015d079..76e547bb8d 100644 --- a/3party/protobuf/src/google/protobuf/generated_message_util.cc +++ b/3party/protobuf/src/google/protobuf/generated_message_util.cc @@ -47,6 +47,8 @@ double NaN() { return std::numeric_limits::quiet_NaN(); } +const ::std::string kEmptyString; + } // namespace internal } // namespace protobuf diff --git a/3party/protobuf/src/google/protobuf/generated_message_util.h b/3party/protobuf/src/google/protobuf/generated_message_util.h index daa16f7748..1a2343d440 100644 --- a/3party/protobuf/src/google/protobuf/generated_message_util.h +++ b/3party/protobuf/src/google/protobuf/generated_message_util.h @@ -38,6 +38,8 @@ #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ +#include + #include @@ -66,8 +68,11 @@ namespace internal { // Constants for special floating point values. -LIBPROTOBUF_EXPORT double Infinity(); -LIBPROTOBUF_EXPORT double NaN(); +double Infinity(); +double NaN(); + +// Constant used for empty default strings. +extern const ::std::string kEmptyString; } // namespace internal diff --git a/3party/protobuf/src/google/protobuf/io/coded_stream.cc b/3party/protobuf/src/google/protobuf/io/coded_stream.cc index 220c74414a..57d486f958 100644 --- a/3party/protobuf/src/google/protobuf/io/coded_stream.cc +++ b/3party/protobuf/src/google/protobuf/io/coded_stream.cc @@ -38,9 +38,9 @@ // will not cross the end of the buffer, since we can avoid a lot // of branching in this case. -#include #include #include +#include #include #include #include @@ -56,6 +56,15 @@ static const int kMaxVarintBytes = 10; static const int kMaxVarint32Bytes = 5; +inline bool NextNonEmpty(ZeroCopyInputStream* input, + const void** data, int* size) { + bool success; + do { + success = input->Next(data, size); + } while (success && *size == 0); + return success; +} + } // namespace // CodedInputStream ================================================== @@ -489,7 +498,7 @@ bool CodedInputStream::Refresh() { const void* void_buffer; int buffer_size; - if (input_->Next(&void_buffer, &buffer_size)) { + if (NextNonEmpty(input_, &void_buffer, &buffer_size)) { buffer_ = reinterpret_cast(void_buffer); buffer_end_ = buffer_ + buffer_size; GOOGLE_CHECK_GE(buffer_size, 0); diff --git a/3party/protobuf/src/google/protobuf/io/coded_stream.h b/3party/protobuf/src/google/protobuf/io/coded_stream.h index 652a3a5520..1b6b4e18b4 100644 --- a/3party/protobuf/src/google/protobuf/io/coded_stream.h +++ b/3party/protobuf/src/google/protobuf/io/coded_stream.h @@ -109,16 +109,28 @@ #ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ #define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ -#include #include -#ifndef _MSC_VER -#include -#endif // !_MSC_VER +#ifdef _MSC_VER + #if defined(_M_IX86) && \ + !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) + #define PROTOBUF_LITTLE_ENDIAN 1 + #endif + #if _MSC_VER >= 1300 + // If MSVC has "/RTCc" set, it will complain about truncating casts at + // runtime. This file contains some intentional truncating casts. + #pragma runtime_checks("c", off) + #endif +#else + #include // __BYTE_ORDER + #if defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN && \ + !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) + #define PROTOBUF_LITTLE_ENDIAN 1 + #endif +#endif #include -#include // for GOOGLE_PREDICT_TRUE macro + namespace google { - namespace protobuf { class DescriptorPool; @@ -555,7 +567,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // char text[] = "Hello world!"; // // int coded_size = sizeof(magic_number) + -// CodedOutputStream::Varint32Size(strlen(text)) + +// CodedOutputStream::VarintSize32(strlen(text)) + // strlen(text); // // uint8* buffer = @@ -736,8 +748,7 @@ inline bool CodedInputStream::ReadVarint64(uint64* value) { inline const uint8* CodedInputStream::ReadLittleEndian32FromArray( const uint8* buffer, uint32* value) { -#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ - defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN +#if defined(PROTOBUF_LITTLE_ENDIAN) memcpy(value, buffer, sizeof(*value)); return buffer + sizeof(*value); #else @@ -752,8 +763,7 @@ inline const uint8* CodedInputStream::ReadLittleEndian32FromArray( inline const uint8* CodedInputStream::ReadLittleEndian64FromArray( const uint8* buffer, uint64* value) { -#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ - defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN +#if defined(PROTOBUF_LITTLE_ENDIAN) memcpy(value, buffer, sizeof(*value)); return buffer + sizeof(*value); #else @@ -772,9 +782,8 @@ inline const uint8* CodedInputStream::ReadLittleEndian64FromArray( } inline bool CodedInputStream::ReadLittleEndian32(uint32* value) { -#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ - defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN - if (GOOGLE_PREDICT_TRUE(BufferSize() >= sizeof(*value))) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { memcpy(value, buffer_, sizeof(*value)); Advance(sizeof(*value)); return true; @@ -787,9 +796,8 @@ inline bool CodedInputStream::ReadLittleEndian32(uint32* value) { } inline bool CodedInputStream::ReadLittleEndian64(uint64* value) { -#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ - defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN - if (GOOGLE_PREDICT_TRUE(BufferSize() >= sizeof(*value))) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { memcpy(value, buffer_, sizeof(*value)); Advance(sizeof(*value)); return true; @@ -916,8 +924,7 @@ inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray( inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value, uint8* target) { -#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ - defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN +#if defined(PROTOBUF_LITTLE_ENDIAN) memcpy(target, &value, sizeof(value)); #else target[0] = static_cast(value); @@ -930,8 +937,7 @@ inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value, inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value, uint8* target) { -#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ - defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN +#if defined(PROTOBUF_LITTLE_ENDIAN) memcpy(target, &value, sizeof(value)); #else uint32 part0 = static_cast(value); @@ -984,12 +990,12 @@ inline int CodedOutputStream::VarintSize32SignExtended(int32 value) { } inline void CodedOutputStream::WriteString(const string& str) { - WriteRaw(str.data(), str.size()); + WriteRaw(str.data(), static_cast(str.size())); } inline uint8* CodedOutputStream::WriteStringToArray( const string& str, uint8* target) { - return WriteRawToArray(str.data(), str.size(), target); + return WriteRawToArray(str.data(), static_cast(str.size()), target); } inline int CodedOutputStream::ByteCount() const { @@ -1045,7 +1051,7 @@ inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input) last_tag_(0), legitimate_message_end_(false), aliasing_enabled_(false), - current_limit_(INT_MAX), + current_limit_(kint32max), buffer_size_after_limit_(0), total_bytes_limit_(kDefaultTotalBytesLimit), total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), @@ -1087,5 +1093,10 @@ inline CodedInputStream::~CodedInputStream() { } // namespace io } // namespace protobuf + +#if defined(_MSC_VER) && _MSC_VER >= 1300 + #pragma runtime_checks("c", restore) +#endif // _MSC_VER + } // namespace google #endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ diff --git a/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc b/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc new file mode 100644 index 0000000000..1384c746af --- /dev/null +++ b/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc @@ -0,0 +1,470 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifdef _MSC_VER +#include +#else +#include +#include +#include +#include +#endif +#include +#include +#include + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace io { + +#ifdef _WIN32 +// Win32 lseek is broken: If invoked on a non-seekable file descriptor, its +// return value is undefined. We re-define it to always produce an error. +#define lseek(fd, offset, origin) ((off_t)-1) +#endif + +namespace { + +// EINTR sucks. +int close_no_eintr(int fd) { + int result; + do { + result = close(fd); + } while (result < 0 && errno == EINTR); + return result; +} + +} // namespace + + +// =================================================================== + +FileInputStream::FileInputStream(int file_descriptor, int block_size) + : copying_input_(file_descriptor), + impl_(©ing_input_, block_size) { +} + +FileInputStream::~FileInputStream() {} + +bool FileInputStream::Close() { + return copying_input_.Close(); +} + +bool FileInputStream::Next(const void** data, int* size) { + return impl_.Next(data, size); +} + +void FileInputStream::BackUp(int count) { + impl_.BackUp(count); +} + +bool FileInputStream::Skip(int count) { + return impl_.Skip(count); +} + +int64 FileInputStream::ByteCount() const { + return impl_.ByteCount(); +} + +FileInputStream::CopyingFileInputStream::CopyingFileInputStream( + int file_descriptor) + : file_(file_descriptor), + close_on_delete_(false), + is_closed_(false), + errno_(0), + previous_seek_failed_(false) { +} + +FileInputStream::CopyingFileInputStream::~CopyingFileInputStream() { + if (close_on_delete_) { + if (!Close()) { + GOOGLE_LOG(ERROR) << "close() failed: " << strerror(errno_); + } + } +} + +bool FileInputStream::CopyingFileInputStream::Close() { + GOOGLE_CHECK(!is_closed_); + + is_closed_ = true; + if (close_no_eintr(file_) != 0) { + // The docs on close() do not specify whether a file descriptor is still + // open after close() fails with EIO. However, the glibc source code + // seems to indicate that it is not. + errno_ = errno; + return false; + } + + return true; +} + +int FileInputStream::CopyingFileInputStream::Read(void* buffer, int size) { + GOOGLE_CHECK(!is_closed_); + + int result; + do { + result = read(file_, buffer, size); + } while (result < 0 && errno == EINTR); + + if (result < 0) { + // Read error (not EOF). + errno_ = errno; + } + + return result; +} + +int FileInputStream::CopyingFileInputStream::Skip(int count) { + GOOGLE_CHECK(!is_closed_); + + if (!previous_seek_failed_ && + lseek(file_, count, SEEK_CUR) != (off_t)-1) { + // Seek succeeded. + return count; + } else { + // Failed to seek. + + // Note to self: Don't seek again. This file descriptor doesn't + // support it. + previous_seek_failed_ = true; + + // Use the default implementation. + return CopyingInputStream::Skip(count); + } +} + +// =================================================================== + +FileOutputStream::FileOutputStream(int file_descriptor, int block_size) + : copying_output_(file_descriptor), + impl_(©ing_output_, block_size) { +} + +FileOutputStream::~FileOutputStream() { + impl_.Flush(); +} + +bool FileOutputStream::Close() { + bool flush_succeeded = impl_.Flush(); + return copying_output_.Close() && flush_succeeded; +} + +bool FileOutputStream::Flush() { + return impl_.Flush(); +} + +bool FileOutputStream::Next(void** data, int* size) { + return impl_.Next(data, size); +} + +void FileOutputStream::BackUp(int count) { + impl_.BackUp(count); +} + +int64 FileOutputStream::ByteCount() const { + return impl_.ByteCount(); +} + +FileOutputStream::CopyingFileOutputStream::CopyingFileOutputStream( + int file_descriptor) + : file_(file_descriptor), + close_on_delete_(false), + is_closed_(false), + errno_(0) { +} + +FileOutputStream::CopyingFileOutputStream::~CopyingFileOutputStream() { + if (close_on_delete_) { + if (!Close()) { + GOOGLE_LOG(ERROR) << "close() failed: " << strerror(errno_); + } + } +} + +bool FileOutputStream::CopyingFileOutputStream::Close() { + GOOGLE_CHECK(!is_closed_); + + is_closed_ = true; + if (close_no_eintr(file_) != 0) { + // The docs on close() do not specify whether a file descriptor is still + // open after close() fails with EIO. However, the glibc source code + // seems to indicate that it is not. + errno_ = errno; + return false; + } + + return true; +} + +bool FileOutputStream::CopyingFileOutputStream::Write( + const void* buffer, int size) { + GOOGLE_CHECK(!is_closed_); + int total_written = 0; + + const uint8* buffer_base = reinterpret_cast(buffer); + + while (total_written < size) { + int bytes; + do { + bytes = write(file_, buffer_base + total_written, size - total_written); + } while (bytes < 0 && errno == EINTR); + + if (bytes <= 0) { + // Write error. + + // FIXME(kenton): According to the man page, if write() returns zero, + // there was no error; write() simply did not write anything. It's + // unclear under what circumstances this might happen, but presumably + // errno won't be set in this case. I am confused as to how such an + // event should be handled. For now I'm treating it as an error, since + // retrying seems like it could lead to an infinite loop. I suspect + // this never actually happens anyway. + + if (bytes < 0) { + errno_ = errno; + } + return false; + } + total_written += bytes; + } + + return true; +} + +// =================================================================== + +IstreamInputStream::IstreamInputStream(istream* input, int block_size) + : copying_input_(input), + impl_(©ing_input_, block_size) { +} + +IstreamInputStream::~IstreamInputStream() {} + +bool IstreamInputStream::Next(const void** data, int* size) { + return impl_.Next(data, size); +} + +void IstreamInputStream::BackUp(int count) { + impl_.BackUp(count); +} + +bool IstreamInputStream::Skip(int count) { + return impl_.Skip(count); +} + +int64 IstreamInputStream::ByteCount() const { + return impl_.ByteCount(); +} + +IstreamInputStream::CopyingIstreamInputStream::CopyingIstreamInputStream( + istream* input) + : input_(input) { +} + +IstreamInputStream::CopyingIstreamInputStream::~CopyingIstreamInputStream() {} + +int IstreamInputStream::CopyingIstreamInputStream::Read( + void* buffer, int size) { + input_->read(reinterpret_cast(buffer), size); + int result = input_->gcount(); + if (result == 0 && input_->fail() && !input_->eof()) { + return -1; + } + return result; +} + +// =================================================================== + +OstreamOutputStream::OstreamOutputStream(ostream* output, int block_size) + : copying_output_(output), + impl_(©ing_output_, block_size) { +} + +OstreamOutputStream::~OstreamOutputStream() { + impl_.Flush(); +} + +bool OstreamOutputStream::Next(void** data, int* size) { + return impl_.Next(data, size); +} + +void OstreamOutputStream::BackUp(int count) { + impl_.BackUp(count); +} + +int64 OstreamOutputStream::ByteCount() const { + return impl_.ByteCount(); +} + +OstreamOutputStream::CopyingOstreamOutputStream::CopyingOstreamOutputStream( + ostream* output) + : output_(output) { +} + +OstreamOutputStream::CopyingOstreamOutputStream::~CopyingOstreamOutputStream() { +} + +bool OstreamOutputStream::CopyingOstreamOutputStream::Write( + const void* buffer, int size) { + output_->write(reinterpret_cast(buffer), size); + return output_->good(); +} + +// =================================================================== + +ConcatenatingInputStream::ConcatenatingInputStream( + ZeroCopyInputStream* const streams[], int count) + : streams_(streams), stream_count_(count), bytes_retired_(0) { +} + +ConcatenatingInputStream::~ConcatenatingInputStream() { +} + +bool ConcatenatingInputStream::Next(const void** data, int* size) { + while (stream_count_ > 0) { + if (streams_[0]->Next(data, size)) return true; + + // That stream is done. Advance to the next one. + bytes_retired_ += streams_[0]->ByteCount(); + ++streams_; + --stream_count_; + } + + // No more streams. + return false; +} + +void ConcatenatingInputStream::BackUp(int count) { + if (stream_count_ > 0) { + streams_[0]->BackUp(count); + } else { + GOOGLE_LOG(DFATAL) << "Can't BackUp() after failed Next()."; + } +} + +bool ConcatenatingInputStream::Skip(int count) { + while (stream_count_ > 0) { + // Assume that ByteCount() can be used to find out how much we actually + // skipped when Skip() fails. + int64 target_byte_count = streams_[0]->ByteCount() + count; + if (streams_[0]->Skip(count)) return true; + + // Hit the end of the stream. Figure out how many more bytes we still have + // to skip. + int64 final_byte_count = streams_[0]->ByteCount(); + GOOGLE_DCHECK_LT(final_byte_count, target_byte_count); + count = target_byte_count - final_byte_count; + + // That stream is done. Advance to the next one. + bytes_retired_ += final_byte_count; + ++streams_; + --stream_count_; + } + + return false; +} + +int64 ConcatenatingInputStream::ByteCount() const { + if (stream_count_ == 0) { + return bytes_retired_; + } else { + return bytes_retired_ + streams_[0]->ByteCount(); + } +} + + +// =================================================================== + +LimitingInputStream::LimitingInputStream(ZeroCopyInputStream* input, + int64 limit) + : input_(input), limit_(limit) {} + +LimitingInputStream::~LimitingInputStream() { + // If we overshot the limit, back up. + if (limit_ < 0) input_->BackUp(-limit_); +} + +bool LimitingInputStream::Next(const void** data, int* size) { + if (limit_ <= 0) return false; + if (!input_->Next(data, size)) return false; + + limit_ -= *size; + if (limit_ < 0) { + // We overshot the limit. Reduce *size to hide the rest of the buffer. + *size += limit_; + } + return true; +} + +void LimitingInputStream::BackUp(int count) { + if (limit_ < 0) { + input_->BackUp(count - limit_); + limit_ = count; + } else { + input_->BackUp(count); + limit_ += count; + } +} + +bool LimitingInputStream::Skip(int count) { + if (count > limit_) { + if (limit_ < 0) return false; + input_->Skip(limit_); + limit_ = 0; + return false; + } else { + if (!input_->Skip(count)) return false; + limit_ -= count; + return true; + } +} + +int64 LimitingInputStream::ByteCount() const { + if (limit_ < 0) { + return input_->ByteCount() + limit_; + } else { + return input_->ByteCount(); + } +} + + +// =================================================================== + +} // namespace io +} // namespace protobuf +} // namespace google diff --git a/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h b/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h new file mode 100644 index 0000000000..9fedb00576 --- /dev/null +++ b/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h @@ -0,0 +1,357 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file contains common implementations of the interfaces defined in +// zero_copy_stream.h which are only included in the full (non-lite) +// protobuf library. These implementations include Unix file descriptors +// and C++ iostreams. See also: zero_copy_stream_impl_lite.h + +#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ +#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ + +#include +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace io { + + +// =================================================================== + +// A ZeroCopyInputStream which reads from a file descriptor. +// +// FileInputStream is preferred over using an ifstream with IstreamInputStream. +// The latter will introduce an extra layer of buffering, harming performance. +// Also, it's conceivable that FileInputStream could someday be enhanced +// to use zero-copy file descriptors on OSs which support them. +class LIBPROTOBUF_EXPORT FileInputStream : public ZeroCopyInputStream { + public: + // Creates a stream that reads from the given Unix file descriptor. + // If a block_size is given, it specifies the number of bytes that + // should be read and returned with each call to Next(). Otherwise, + // a reasonable default is used. + explicit FileInputStream(int file_descriptor, int block_size = -1); + ~FileInputStream(); + + // Flushes any buffers and closes the underlying file. Returns false if + // an error occurs during the process; use GetErrno() to examine the error. + // Even if an error occurs, the file descriptor is closed when this returns. + bool Close(); + + // By default, the file descriptor is not closed when the stream is + // destroyed. Call SetCloseOnDelete(true) to change that. WARNING: + // This leaves no way for the caller to detect if close() fails. If + // detecting close() errors is important to you, you should arrange + // to close the descriptor yourself. + void SetCloseOnDelete(bool value) { copying_input_.SetCloseOnDelete(value); } + + // If an I/O error has occurred on this file descriptor, this is the + // errno from that error. Otherwise, this is zero. Once an error + // occurs, the stream is broken and all subsequent operations will + // fail. + int GetErrno() { return copying_input_.GetErrno(); } + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + private: + class LIBPROTOBUF_EXPORT CopyingFileInputStream : public CopyingInputStream { + public: + CopyingFileInputStream(int file_descriptor); + ~CopyingFileInputStream(); + + bool Close(); + void SetCloseOnDelete(bool value) { close_on_delete_ = value; } + int GetErrno() { return errno_; } + + // implements CopyingInputStream --------------------------------- + int Read(void* buffer, int size); + int Skip(int count); + + private: + // The file descriptor. + const int file_; + bool close_on_delete_; + bool is_closed_; + + // The errno of the I/O error, if one has occurred. Otherwise, zero. + int errno_; + + // Did we try to seek once and fail? If so, we assume this file descriptor + // doesn't support seeking and won't try again. + bool previous_seek_failed_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileInputStream); + }; + + CopyingFileInputStream copying_input_; + CopyingInputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileInputStream); +}; + +// =================================================================== + +// A ZeroCopyOutputStream which writes to a file descriptor. +// +// FileOutputStream is preferred over using an ofstream with +// OstreamOutputStream. The latter will introduce an extra layer of buffering, +// harming performance. Also, it's conceivable that FileOutputStream could +// someday be enhanced to use zero-copy file descriptors on OSs which +// support them. +class LIBPROTOBUF_EXPORT FileOutputStream : public ZeroCopyOutputStream { + public: + // Creates a stream that writes to the given Unix file descriptor. + // If a block_size is given, it specifies the size of the buffers + // that should be returned by Next(). Otherwise, a reasonable default + // is used. + explicit FileOutputStream(int file_descriptor, int block_size = -1); + ~FileOutputStream(); + + // Flushes any buffers and closes the underlying file. Returns false if + // an error occurs during the process; use GetErrno() to examine the error. + // Even if an error occurs, the file descriptor is closed when this returns. + bool Close(); + + // Flushes FileOutputStream's buffers but does not close the + // underlying file. No special measures are taken to ensure that + // underlying operating system file object is synchronized to disk. + bool Flush(); + + // By default, the file descriptor is not closed when the stream is + // destroyed. Call SetCloseOnDelete(true) to change that. WARNING: + // This leaves no way for the caller to detect if close() fails. If + // detecting close() errors is important to you, you should arrange + // to close the descriptor yourself. + void SetCloseOnDelete(bool value) { copying_output_.SetCloseOnDelete(value); } + + // If an I/O error has occurred on this file descriptor, this is the + // errno from that error. Otherwise, this is zero. Once an error + // occurs, the stream is broken and all subsequent operations will + // fail. + int GetErrno() { return copying_output_.GetErrno(); } + + // implements ZeroCopyOutputStream --------------------------------- + bool Next(void** data, int* size); + void BackUp(int count); + int64 ByteCount() const; + + private: + class LIBPROTOBUF_EXPORT CopyingFileOutputStream : public CopyingOutputStream { + public: + CopyingFileOutputStream(int file_descriptor); + ~CopyingFileOutputStream(); + + bool Close(); + void SetCloseOnDelete(bool value) { close_on_delete_ = value; } + int GetErrno() { return errno_; } + + // implements CopyingOutputStream -------------------------------- + bool Write(const void* buffer, int size); + + private: + // The file descriptor. + const int file_; + bool close_on_delete_; + bool is_closed_; + + // The errno of the I/O error, if one has occurred. Otherwise, zero. + int errno_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileOutputStream); + }; + + CopyingFileOutputStream copying_output_; + CopyingOutputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileOutputStream); +}; + +// =================================================================== + +// A ZeroCopyInputStream which reads from a C++ istream. +// +// Note that for reading files (or anything represented by a file descriptor), +// FileInputStream is more efficient. +class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { + public: + // Creates a stream that reads from the given C++ istream. + // If a block_size is given, it specifies the number of bytes that + // should be read and returned with each call to Next(). Otherwise, + // a reasonable default is used. + explicit IstreamInputStream(istream* stream, int block_size = -1); + ~IstreamInputStream(); + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + private: + class LIBPROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream { + public: + CopyingIstreamInputStream(istream* input); + ~CopyingIstreamInputStream(); + + // implements CopyingInputStream --------------------------------- + int Read(void* buffer, int size); + // (We use the default implementation of Skip().) + + private: + // The stream. + istream* input_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream); + }; + + CopyingIstreamInputStream copying_input_; + CopyingInputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(IstreamInputStream); +}; + +// =================================================================== + +// A ZeroCopyOutputStream which writes to a C++ ostream. +// +// Note that for writing files (or anything represented by a file descriptor), +// FileOutputStream is more efficient. +class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { + public: + // Creates a stream that writes to the given C++ ostream. + // If a block_size is given, it specifies the size of the buffers + // that should be returned by Next(). Otherwise, a reasonable default + // is used. + explicit OstreamOutputStream(ostream* stream, int block_size = -1); + ~OstreamOutputStream(); + + // implements ZeroCopyOutputStream --------------------------------- + bool Next(void** data, int* size); + void BackUp(int count); + int64 ByteCount() const; + + private: + class LIBPROTOBUF_EXPORT CopyingOstreamOutputStream : public CopyingOutputStream { + public: + CopyingOstreamOutputStream(ostream* output); + ~CopyingOstreamOutputStream(); + + // implements CopyingOutputStream -------------------------------- + bool Write(const void* buffer, int size); + + private: + // The stream. + ostream* output_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream); + }; + + CopyingOstreamOutputStream copying_output_; + CopyingOutputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OstreamOutputStream); +}; + +// =================================================================== + +// A ZeroCopyInputStream which reads from several other streams in sequence. +// ConcatenatingInputStream is unable to distinguish between end-of-stream +// and read errors in the underlying streams, so it assumes any errors mean +// end-of-stream. So, if the underlying streams fail for any other reason, +// ConcatenatingInputStream may do odd things. It is suggested that you do +// not use ConcatenatingInputStream on streams that might produce read errors +// other than end-of-stream. +class LIBPROTOBUF_EXPORT ConcatenatingInputStream : public ZeroCopyInputStream { + public: + // All streams passed in as well as the array itself must remain valid + // until the ConcatenatingInputStream is destroyed. + ConcatenatingInputStream(ZeroCopyInputStream* const streams[], int count); + ~ConcatenatingInputStream(); + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + + private: + // As streams are retired, streams_ is incremented and count_ is + // decremented. + ZeroCopyInputStream* const* streams_; + int stream_count_; + int64 bytes_retired_; // Bytes read from previous streams. + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ConcatenatingInputStream); +}; + +// =================================================================== + +// A ZeroCopyInputStream which wraps some other stream and limits it to +// a particular byte count. +class LIBPROTOBUF_EXPORT LimitingInputStream : public ZeroCopyInputStream { + public: + LimitingInputStream(ZeroCopyInputStream* input, int64 limit); + ~LimitingInputStream(); + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + + private: + ZeroCopyInputStream* input_; + int64 limit_; // Decreases as we go, becomes negative if we overshoot. + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream); +}; + +// =================================================================== + +} // namespace io +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ diff --git a/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc index b82ca52458..e80125109f 100644 --- a/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +++ b/3party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include #include #include diff --git a/3party/protobuf/src/google/protobuf/message_lite.cc b/3party/protobuf/src/google/protobuf/message_lite.cc index e2e7b407af..7c8f37dc7f 100644 --- a/3party/protobuf/src/google/protobuf/message_lite.cc +++ b/3party/protobuf/src/google/protobuf/message_lite.cc @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include namespace google { diff --git a/3party/protobuf/src/google/protobuf/repeated_field.cc b/3party/protobuf/src/google/protobuf/repeated_field.cc index f7beb110fb..09377742af 100644 --- a/3party/protobuf/src/google/protobuf/repeated_field.cc +++ b/3party/protobuf/src/google/protobuf/repeated_field.cc @@ -32,11 +32,14 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + #include #include namespace google { namespace protobuf { + namespace internal { void RepeatedPtrFieldBase::Reserve(int new_size) { @@ -88,8 +91,8 @@ void StringTypeHandlerBase::Delete(string* value) { delete value; } +} // namespace internal -} // namespace internal } // namespace protobuf } // namespace google diff --git a/3party/protobuf/src/google/protobuf/repeated_field.h b/3party/protobuf/src/google/protobuf/repeated_field.h index defdefe07e..6080ddccce 100644 --- a/3party/protobuf/src/google/protobuf/repeated_field.h +++ b/3party/protobuf/src/google/protobuf/repeated_field.h @@ -72,8 +72,11 @@ template class RepeatedField { public: RepeatedField(); + RepeatedField(const RepeatedField& other); ~RepeatedField(); + RepeatedField& operator=(const RepeatedField& other); + int size() const; const Element& Get(int index) const; @@ -90,6 +93,7 @@ class RepeatedField { void RemoveLast(); void Clear(); void MergeFrom(const RepeatedField& other); + void CopyFrom(const RepeatedField& other); // Reserve space to expand the field to at least the given size. If the // array is grown, it will always be at least doubled in size. @@ -116,6 +120,7 @@ class RepeatedField { // STL-like iterator support typedef Element* iterator; typedef const Element* const_iterator; + typedef Element value_type; iterator begin(); const_iterator begin() const; @@ -127,8 +132,6 @@ class RepeatedField { int SpaceUsedExcludingSelf() const; private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedField); - static const int kInitialSize = 4; Element* elements_; @@ -203,6 +206,8 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { void Clear(); template void MergeFrom(const RepeatedPtrFieldBase& other); + template + void CopyFrom(const RepeatedPtrFieldBase& other); void Reserve(int new_size); @@ -300,7 +305,7 @@ class LIBPROTOBUF_EXPORT StringTypeHandlerBase { static void Merge(const string& from, string* to) { *to = from; } }; -class StringTypeHandler : public StringTypeHandlerBase { +class LIBPROTOBUF_EXPORT StringTypeHandler : public StringTypeHandlerBase { public: static int SpaceUsed(const string& value) { return sizeof(value) + StringSpaceUsedExcludingSelf(value); @@ -316,9 +321,11 @@ template class RepeatedPtrField : public internal::RepeatedPtrFieldBase { public: RepeatedPtrField(); - + RepeatedPtrField(const RepeatedPtrField& other); ~RepeatedPtrField(); + RepeatedPtrField& operator=(const RepeatedPtrField& other); + int size() const; const Element& Get(int index) const; @@ -327,6 +334,7 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase { void RemoveLast(); // Remove the last element in the array. void Clear(); void MergeFrom(const RepeatedPtrField& other); + void CopyFrom(const RepeatedPtrField& other); // Reserve space to expand the field to at least the given size. This only // resizes the pointer array; it doesn't allocate any objects. If the @@ -349,6 +357,7 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase { // STL-like iterator support typedef internal::RepeatedPtrIterator iterator; typedef internal::RepeatedPtrIterator const_iterator; + typedef Element value_type; iterator begin(); const_iterator begin() const; @@ -365,11 +374,6 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase { // excluding sizeof(*this). int SpaceUsedExcludingSelf() const; - // The spaced used just by the pointer array, not counting the objects pointed - // at. Returns zero if the array is inlined (i.e. initial_space_ is being - // used). - int SpaceUsedByArray() const; - // Advanced memory management -------------------------------------- // When hardcore memory management becomes necessary -- as it often // does here at Google -- the following methods may be useful. @@ -410,9 +414,6 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase { // methods on RepeatedPtrFieldBase. class TypeHandler; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPtrField); }; // implementation ==================================================== @@ -424,6 +425,14 @@ inline RepeatedField::RepeatedField() total_size_(kInitialSize) { } +template +inline RepeatedField::RepeatedField(const RepeatedField& other) + : elements_(initial_space_), + current_size_(0), + total_size_(kInitialSize) { + CopyFrom(other); +} + template RepeatedField::~RepeatedField() { if (elements_ != initial_space_) { @@ -431,6 +440,13 @@ RepeatedField::~RepeatedField() { } } +template +inline RepeatedField& +RepeatedField::operator=(const RepeatedField& other) { + CopyFrom(other); + return *this; +} + template inline int RepeatedField::size() const { return current_size_; @@ -501,6 +517,12 @@ inline void RepeatedField::MergeFrom(const RepeatedField& other) { current_size_ += other.current_size_; } +template +inline void RepeatedField::CopyFrom(const RepeatedField& other) { + Clear(); + MergeFrom(other); +} + template inline Element* RepeatedField::mutable_data() { return elements_; @@ -594,14 +616,14 @@ inline void RepeatedField::Truncate(int new_size) { template inline void RepeatedField::MoveArray( - Element to[], Element from[], int size) { - memcpy(to, from, size * sizeof(Element)); + Element to[], Element from[], int array_size) { + memcpy(to, from, array_size * sizeof(Element)); } template inline void RepeatedField::CopyArray( - Element to[], const Element from[], int size) { - memcpy(to, from, size * sizeof(Element)); + Element to[], const Element from[], int array_size) { + memcpy(to, from, array_size * sizeof(Element)); } @@ -675,10 +697,16 @@ template inline void RepeatedPtrFieldBase::MergeFrom(const RepeatedPtrFieldBase& other) { Reserve(current_size_ + other.current_size_); for (int i = 0; i < other.current_size_; i++) { - TypeHandler::Merge(other.Get(i), Add()); + TypeHandler::Merge(other.template Get(i), Add()); } } +template +inline void RepeatedPtrFieldBase::CopyFrom(const RepeatedPtrFieldBase& other) { + RepeatedPtrFieldBase::Clear(); + RepeatedPtrFieldBase::MergeFrom(other); +} + inline int RepeatedPtrFieldBase::Capacity() const { return total_size_; } @@ -804,11 +832,24 @@ class RepeatedPtrField::TypeHandler template inline RepeatedPtrField::RepeatedPtrField() {} +template +inline RepeatedPtrField::RepeatedPtrField( + const RepeatedPtrField& other) { + CopyFrom(other); +} + template RepeatedPtrField::~RepeatedPtrField() { Destroy(); } +template +inline RepeatedPtrField& RepeatedPtrField::operator=( + const RepeatedPtrField& other) { + CopyFrom(other); + return *this; +} + template inline int RepeatedPtrField::size() const { return RepeatedPtrFieldBase::size(); @@ -845,6 +886,12 @@ inline void RepeatedPtrField::MergeFrom( RepeatedPtrFieldBase::MergeFrom(other); } +template +inline void RepeatedPtrField::CopyFrom( + const RepeatedPtrField& other) { + RepeatedPtrFieldBase::CopyFrom(other); +} + template inline Element** RepeatedPtrField::mutable_data() { return RepeatedPtrFieldBase::mutable_data(); @@ -944,7 +991,7 @@ class RepeatedPtrIterator template RepeatedPtrIterator(const RepeatedPtrIterator& other) : it_(other.it_) { - // Force a compiler error if the other type is not convertable to ours. + // Force a compiler error if the other type is not convertible to ours. if (false) { implicit_cast(0); } @@ -1152,7 +1199,7 @@ template class RepeatedFieldBackInsertIterator } private: - RepeatedField* const field_; + RepeatedField* field_; }; // A back inserter for RepeatedPtrField objects. @@ -1183,7 +1230,7 @@ template class RepeatedPtrFieldBackInsertIterator } private: - RepeatedPtrField* const field_; + RepeatedPtrField* field_; }; // A back inserter for RepeatedPtrFields that inserts by transfering ownership @@ -1212,7 +1259,7 @@ template class AllocatedRepeatedPtrFieldBackInsertIterator } private: - RepeatedPtrField* const field_; + RepeatedPtrField* field_; }; } // namespace internal diff --git a/3party/protobuf/src/google/protobuf/stubs/common.cc b/3party/protobuf/src/google/protobuf/stubs/common.cc index 3b47cf0b92..7b15be44d8 100644 --- a/3party/protobuf/src/google/protobuf/stubs/common.cc +++ b/3party/protobuf/src/google/protobuf/stubs/common.cc @@ -36,17 +36,16 @@ #include #include -//#include "config.h" +#include "config.h" -#if defined(_WIN32) && !defined(_BADA_SIMULATOR) && !defined(_BADA_DEVICE) -//#define WIN32_LEAN_AND_MEAN // We only need minimal includes +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN // We only need minimal includes #include #define snprintf _snprintf // see comment in strutil.cc #elif defined(HAVE_PTHREAD) #include #else -#warning "No suitable threading library available." -//#error "No suitable threading library available." +#error "No suitable threading library available." #endif namespace google { @@ -192,7 +191,11 @@ void LogMessage::Finish() { } if (level_ == LOGLEVEL_FATAL) { +#ifdef PROTOBUF_USE_EXCEPTIONS + throw FatalException(filename_, line_, message_); +#else abort(); +#endif } } @@ -239,7 +242,7 @@ void DoNothing() {} // =================================================================== // emulates google3/base/mutex.cc -#if defined(_WIN32) && !defined(_BADA_SIMULATOR) && !defined(_BADA_DEVICE) +#ifdef _WIN32 struct Mutex::Internal { CRITICAL_SECTION mutex; @@ -362,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/3party/protobuf/src/google/protobuf/stubs/common.h b/3party/protobuf/src/google/protobuf/stubs/common.h index 551ee4aac6..7173a84d14 100644 --- a/3party/protobuf/src/google/protobuf/stubs/common.h +++ b/3party/protobuf/src/google/protobuf/stubs/common.h @@ -48,13 +48,38 @@ #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 +// function. The inline function should be equivalent for C++ users. +inline BOOL GetMessage_Win32( + LPMSG lpMsg, HWND hWnd, + UINT wMsgFilterMin, UINT wMsgFilterMax) { + return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); +} +#undef GetMessage +inline BOOL GetMessage( + LPMSG lpMsg, HWND hWnd, + UINT wMsgFilterMin, UINT wMsgFilterMax) { + return GetMessage_Win32(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); +} +#endif + + namespace std {} namespace google { namespace protobuf { -using namespace std; // Don't do this at home, kids. - #undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS #define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ TypeName(const TypeName&); \ @@ -83,24 +108,24 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 2003000 +#define GOOGLE_PROTOBUF_VERSION 2004001 // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2003000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2004000 // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 2003000; +static const int kMinHeaderVersionForLibrary = 2004000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 2003000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 2004000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 2003000; +static const int kMinHeaderVersionForProtoc = 2004000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. @@ -108,7 +133,7 @@ void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion, const char* filename); // Converts a numeric version number to a string. -string LIBPROTOBUF_EXPORT VersionString(int version); +std::string LIBPROTOBUF_EXPORT VersionString(int version); } // namespace internal @@ -351,6 +376,7 @@ struct CompileAssert { typedef ::google::protobuf::internal::CompileAssert<(bool(expr))> \ msg[bool(expr) ? 1 : -1] + // Implementation details of COMPILE_ASSERT: // // - COMPILE_ASSERT works by defining an array type that has -1 @@ -618,7 +644,7 @@ class LIBPROTOBUF_EXPORT LogMessage { LogMessage(LogLevel level, const char* filename, int line); ~LogMessage(); - LogMessage& operator<<(const string& value); + LogMessage& operator<<(const std::string& value); LogMessage& operator<<(const char* value); LogMessage& operator<<(char value); LogMessage& operator<<(int value); @@ -634,7 +660,7 @@ class LIBPROTOBUF_EXPORT LogMessage { LogLevel level_; const char* filename_; int line_; - string message_; + std::string message_; }; // Used to make the entire "LOG(BLAH) << etc." expression have a void return @@ -713,7 +739,7 @@ class LIBPROTOBUF_EXPORT LogFinisher { #endif // !NDEBUG typedef void LogHandler(LogLevel level, const char* filename, int line, - const string& message); + const std::string& message); // The protobuf library sometimes writes warning and error messages to // stderr. These messages are primarily useful for developers, but may @@ -825,8 +851,9 @@ class LIBPROTOBUF_EXPORT FunctionClosure0 : public Closure { ~FunctionClosure0(); void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes function_(); - if (self_deleting_) delete this; + if (needs_delete) delete this; } private: @@ -844,8 +871,9 @@ class MethodClosure0 : public Closure { ~MethodClosure0() {} void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes (object_->*method_)(); - if (self_deleting_) delete this; + if (needs_delete) delete this; } private: @@ -866,8 +894,9 @@ class FunctionClosure1 : public Closure { ~FunctionClosure1() {} void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes function_(arg1_); - if (self_deleting_) delete this; + if (needs_delete) delete this; } private: @@ -888,8 +917,9 @@ class MethodClosure1 : public Closure { ~MethodClosure1() {} void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes (object_->*method_)(arg1_); - if (self_deleting_) delete this; + if (needs_delete) delete this; } private: @@ -911,8 +941,9 @@ class FunctionClosure2 : public Closure { ~FunctionClosure2() {} void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes function_(arg1_, arg2_); - if (self_deleting_) delete this; + if (needs_delete) delete this; } private: @@ -934,8 +965,9 @@ class MethodClosure2 : public Closure { ~MethodClosure2() {} void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes (object_->*method_)(arg1_, arg2_); - if (self_deleting_) delete this; + if (needs_delete) delete this; } private: @@ -1149,6 +1181,30 @@ 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. + } // namespace protobuf } // namespace google diff --git a/3party/protobuf/src/google/protobuf/stubs/hash.cc b/3party/protobuf/src/google/protobuf/stubs/hash.cc deleted file mode 100644 index 9eaf4a1ee2..0000000000 --- a/3party/protobuf/src/google/protobuf/stubs/hash.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) - -#include - -namespace google { -namespace protobuf { - -// Nothing needed here right now. - -} // namespace protobuf -} // namespace google diff --git a/3party/protobuf/src/google/protobuf/stubs/hash.h b/3party/protobuf/src/google/protobuf/stubs/hash.h index 6e4421048b..822d605013 100644 --- a/3party/protobuf/src/google/protobuf/stubs/hash.h +++ b/3party/protobuf/src/google/protobuf/stubs/hash.h @@ -37,7 +37,7 @@ #include #include -//#include "config.h" +#include "config.h" #if defined(HAVE_HASH_MAP) && defined(HAVE_HASH_SET) #include HASH_MAP_H diff --git a/3party/protobuf/src/google/protobuf/stubs/once.cc b/3party/protobuf/src/google/protobuf/stubs/once.cc index 9d32c7fba4..5b7af9ce99 100644 --- a/3party/protobuf/src/google/protobuf/stubs/once.cc +++ b/3party/protobuf/src/google/protobuf/stubs/once.cc @@ -35,7 +35,7 @@ // This header is intended to be included only by internal .cc files and // generated .pb.cc files. Users should not use this directly. -#if defined(_WIN32) && !defined(_BADA_SIMULATOR) && !defined(_BADA_DEVICE) +#ifdef _WIN32 #include #endif @@ -44,7 +44,7 @@ namespace google { namespace protobuf { -#if defined(_WIN32) && !defined(_BADA_SIMULATOR) && !defined(_BADA_DEVICE) +#ifdef _WIN32 struct ProtobufOnceInternal { ProtobufOnceInternal() { diff --git a/3party/protobuf/src/google/protobuf/wire_format_lite.cc b/3party/protobuf/src/google/protobuf/wire_format_lite.cc index b1ff93a293..d347d11697 100644 --- a/3party/protobuf/src/google/protobuf/wire_format_lite.cc +++ b/3party/protobuf/src/google/protobuf/wire_format_lite.cc @@ -40,7 +40,7 @@ #include #include #include -#include +#include namespace google { namespace protobuf { diff --git a/3party/protobuf/src/google/protobuf/wire_format_lite_inl.h b/3party/protobuf/src/google/protobuf/wire_format_lite_inl.h index 1a2d99bfe8..103b0bd0ca 100644 --- a/3party/protobuf/src/google/protobuf/wire_format_lite_inl.h +++ b/3party/protobuf/src/google/protobuf/wire_format_lite_inl.h @@ -222,7 +222,7 @@ inline const uint8* WireFormatLite::ReadPrimitiveFromArray< } template -inline bool WireFormatLite::ReadRepeatedPrimitive(int /*tag_size*/, +inline bool WireFormatLite::ReadRepeatedPrimitive(int, // tag_size, unused. uint32 tag, io::CodedInputStream* input, RepeatedField* values) { @@ -285,7 +285,7 @@ inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive( return true; } -// Specializations of ReadRepeatedPrimitive for the fixed size types, which use +// Specializations of ReadRepeatedPrimitive for the fixed size types, which use // the optimized code path. #define READ_REPEATED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \ template <> \ @@ -368,12 +368,24 @@ inline bool WireFormatLite::ReadMessage(io::CodedInputStream* input, return true; } -template -inline bool WireFormatLite::ReadGroupNoVirtual(int field_number, - io::CodedInputStream* input, - MessageType* value) { +// We name the template parameter something long and extremely unlikely to occur +// elsewhere because a *qualified* member access expression designed to avoid +// virtual dispatch, C++03 [basic.lookup.classref] 3.4.5/4 requires that the +// name of the qualifying class to be looked up both in the context of the full +// expression (finding the template parameter) and in the context of the object +// whose member we are accessing. This could potentially find a nested type +// within that object. The standard goes on to require these names to refer to +// the same entity, which this collision would violate. The lack of a safe way +// to avoid this collision appears to be a defect in the standard, but until it +// is corrected, we choose the name to avoid accidental collisions. +template +inline bool WireFormatLite::ReadGroupNoVirtual( + int field_number, io::CodedInputStream* input, + MessageType_WorkAroundCppLookupDefect* value) { if (!input->IncrementRecursionDepth()) return false; - if (!value->MessageType::MergePartialFromCodedStream(input)) return false; + if (!value-> + MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input)) + return false; input->DecrementRecursionDepth(); // Make sure the last thing read was an end tag for this group. if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) { @@ -381,14 +393,16 @@ inline bool WireFormatLite::ReadGroupNoVirtual(int field_number, } return true; } -template -inline bool WireFormatLite::ReadMessageNoVirtual(io::CodedInputStream* input, - MessageType* value) { +template +inline bool WireFormatLite::ReadMessageNoVirtual( + io::CodedInputStream* input, MessageType_WorkAroundCppLookupDefect* value) { uint32 length; if (!input->ReadVarint32(&length)) return false; if (!input->IncrementRecursionDepth()) return false; io::CodedInputStream::Limit limit = input->PushLimit(length); - if (!value->MessageType::MergePartialFromCodedStream(input)) return false; + if (!value-> + MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input)) + return false; // Make sure that parsing stopped when the limit was hit, not at an endgroup // tag. if (!input->ConsumedEntireMessage()) return false; @@ -461,21 +475,24 @@ inline void WireFormatLite::WriteEnumNoTag(int value, output->WriteVarint32SignExtended(value); } -template -inline void WireFormatLite::WriteGroupNoVirtual(int field_number, - const MessageType& value, - io::CodedOutputStream* output) { +// See comment on ReadGroupNoVirtual to understand the need for this template +// parameter name. +template +inline void WireFormatLite::WriteGroupNoVirtual( + int field_number, const MessageType_WorkAroundCppLookupDefect& value, + io::CodedOutputStream* output) { WriteTag(field_number, WIRETYPE_START_GROUP, output); - value.MessageType::SerializeWithCachedSizes(output); + value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output); WriteTag(field_number, WIRETYPE_END_GROUP, output); } -template -inline void WireFormatLite::WriteMessageNoVirtual(int field_number, - const MessageType& value, - io::CodedOutputStream* output) { +template +inline void WireFormatLite::WriteMessageNoVirtual( + int field_number, const MessageType_WorkAroundCppLookupDefect& value, + io::CodedOutputStream* output) { WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output); - output->WriteVarint32(value.MessageType::GetCachedSize()); - value.MessageType::SerializeWithCachedSizes(output); + output->WriteVarint32( + value.MessageType_WorkAroundCppLookupDefect::GetCachedSize()); + value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output); } // =================================================================== @@ -672,20 +689,26 @@ inline uint8* WireFormatLite::WriteMessageToArray(int field_number, return value.SerializeWithCachedSizesToArray(target); } -template +// See comment on ReadGroupNoVirtual to understand the need for this template +// parameter name. +template inline uint8* WireFormatLite::WriteGroupNoVirtualToArray( - int field_number, const MessageType& value, uint8* target) { + int field_number, const MessageType_WorkAroundCppLookupDefect& value, + uint8* target) { target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); - target = value.MessageType::SerializeWithCachedSizesToArray(target); + target = value.MessageType_WorkAroundCppLookupDefect + ::SerializeWithCachedSizesToArray(target); return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); } -template +template inline uint8* WireFormatLite::WriteMessageNoVirtualToArray( - int field_number, const MessageType& value, uint8* target) { + int field_number, const MessageType_WorkAroundCppLookupDefect& value, + uint8* target) { target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); target = io::CodedOutputStream::WriteVarint32ToArray( - value.MessageType::GetCachedSize(), target); - return value.MessageType::SerializeWithCachedSizesToArray(target); + value.MessageType_WorkAroundCppLookupDefect::GetCachedSize(), target); + return value.MessageType_WorkAroundCppLookupDefect + ::SerializeWithCachedSizesToArray(target); } // =================================================================== @@ -730,13 +753,17 @@ inline int WireFormatLite::MessageSize(const MessageLite& value) { return io::CodedOutputStream::VarintSize32(size) + size; } -template -inline int WireFormatLite::GroupSizeNoVirtual(const MessageType& value) { - return value.MessageType::ByteSize(); +// See comment on ReadGroupNoVirtual to understand the need for this template +// parameter name. +template +inline int WireFormatLite::GroupSizeNoVirtual( + const MessageType_WorkAroundCppLookupDefect& value) { + return value.MessageType_WorkAroundCppLookupDefect::ByteSize(); } -template -inline int WireFormatLite::MessageSizeNoVirtual(const MessageType& value) { - int size = value.MessageType::ByteSize(); +template +inline int WireFormatLite::MessageSizeNoVirtual( + const MessageType_WorkAroundCppLookupDefect& value) { + int size = value.MessageType_WorkAroundCppLookupDefect::ByteSize(); return io::CodedOutputStream::VarintSize32(size) + size; } diff --git a/tools/protoc/protoc.exe b/tools/protoc/protoc.exe new file mode 100644 index 0000000000..2d8d4a5d75 Binary files /dev/null and b/tools/protoc/protoc.exe differ diff --git a/tools/protoc/readme.txt b/tools/protoc/readme.txt new file mode 100644 index 0000000000..d919519f4d --- /dev/null +++ b/tools/protoc/readme.txt @@ -0,0 +1,15 @@ +Protocol Buffers - Google's data interchange format +Copyright 2008 Google Inc. +http://code.google.com/p/protobuf/ + +This package contains a precompiled Win32 binary version of the protocol buffer +compiler (protoc). This binary is intended for Windows users who want to +use Protocol Buffers in Java or Python but do not want to compile protoc +themselves. To install, simply place this binary somewhere in your PATH. + +This binary was built using MinGW, but the output is the same regardless of +the C++ compiler used. + +You will still need to download the source code package in order to obtain the +Java or Python runtime libraries. Get it from: + http://code.google.com/p/protobuf/downloads/