diff options
author | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2008-11-21 00:06:27 +0000 |
---|---|---|
committer | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2008-11-21 00:06:27 +0000 |
commit | 26bd9eee6ee6d116e1cc0dedeb660cd69d7aac45 (patch) | |
tree | d35cca89e0da44f136090a554ff9abc93a794fa8 /src/google/protobuf/descriptor.cc | |
parent | a2a32c20434807e9966e3f48375f9419134d1b55 (diff) | |
download | protobuf-26bd9eee6ee6d116e1cc0dedeb660cd69d7aac45.tar.gz protobuf-26bd9eee6ee6d116e1cc0dedeb660cd69d7aac45.tar.bz2 protobuf-26bd9eee6ee6d116e1cc0dedeb660cd69d7aac45.zip |
Integrate changes from internal code.
protoc
* Enum values may now have custom options, using syntax similar to field
options.
* Fixed bug where .proto files which use custom options but don't actually
define them (i.e. they import another .proto file defining the options)
had to explicitly import descriptor.proto.
* Adjacent string literals in .proto files will now be concatenated, like in
C.
C++
* Generated message classes now have a Swap() method which efficiently swaps
the contents of two objects.
* All message classes now have a SpaceUsed() method which returns an estimate
of the number of bytes of allocated memory currently owned by the object.
This is particularly useful when you are reusing a single message object
to improve performance but want to make sure it doesn't bloat up too large.
* New method Message::SerializeAsString() returns a string containing the
serialized data. May be more convenient than calling
SerializeToString(string*).
* In debug mode, log error messages when string-type fields are found to
contain bytes that are not valid UTF-8.
* Fixed bug where a message with multiple extension ranges couldn't parse
extensions.
* Fixed bug where MergeFrom(const Message&) didn't do anything if invoked on
a message that contained no fields (but possibly contained extensions).
* Fixed ShortDebugString() to not be O(n^2). Durr.
* Fixed crash in TextFormat parsing if the first token in the input caused a
tokenization error.
Java
* New overload of mergeFrom() which parses a slice of a byte array instead
of the whole thing.
* New method ByteString.asReadOnlyByteBuffer() does what it sounds like.
* Improved performance of isInitialized() when optimizing for code size.
Python
* Corrected ListFields() signature in Message base class to match what
subclasses actually implement.
* Some minor refactoring.
Diffstat (limited to 'src/google/protobuf/descriptor.cc')
-rw-r--r-- | src/google/protobuf/descriptor.cc | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 882b104b..21c709fb 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -1656,6 +1656,10 @@ class DescriptorBuilder { // dependencies. Symbol FindSymbol(const string& name); + // Like FindSymbol() but does not require that the symbol is in one of the + // file's declared dependencies. + Symbol FindSymbolNotEnforcingDeps(const string& name); + // Like FindSymbol(), but looks up the name relative to some other symbol // name. This first searches siblings of relative_to, then siblings of its // parents, etc. For example, LookupSymbol("foo.bar", "baz.qux.corge") makes @@ -2016,7 +2020,7 @@ bool DescriptorBuilder::IsInPackage(const FileDescriptor* file, file->package()[package_name.size()] == '.'); } -Symbol DescriptorBuilder::FindSymbol(const string& name) { +Symbol DescriptorBuilder::FindSymbolNotEnforcingDeps(const string& name) { Symbol result; // We need to search our pool and all its underlays. @@ -2035,6 +2039,12 @@ Symbol DescriptorBuilder::FindSymbol(const string& name) { pool = pool->underlay_; } + return result; +} + +Symbol DescriptorBuilder::FindSymbol(const string& name) { + Symbol result = FindSymbolNotEnforcingDeps(name); + if (!pool_->enforce_dependencies_) { // Hack for CompilerUpgrader. return result; @@ -3315,7 +3325,8 @@ bool DescriptorBuilder::OptionInterpreter::InterpretSingleOption( // Note that we use DescriptorBuilder::FindSymbol(), not // DescriptorPool::FindMessageTypeByName() because we're already holding the // pool's mutex, and the latter method locks it again. - Symbol symbol = builder_->FindSymbol(options->GetDescriptor()->full_name()); + Symbol symbol = builder_->FindSymbolNotEnforcingDeps( + options->GetDescriptor()->full_name()); if (!symbol.IsNull() && symbol.type == Symbol::MESSAGE) { options_descriptor = symbol.descriptor; } else { @@ -3362,11 +3373,14 @@ bool DescriptorBuilder::OptionInterpreter::InterpretSingleOption( debug_msg_name += name_part; // Search for the field's descriptor as a regular field in the builder's // pool. First we must qualify it by its message name. Note that we use - // DescriptorBuilder::FindSymbol(), not DescriptorPool::FindFieldByName() - // because we're already holding the pool's mutex, and the latter method - // locks it again. + // DescriptorBuilder::FindSymbolNotEnforcingDeps(), not + // DescriptorPool::FindFieldByName() because we're already holding the + // pool's mutex, and the latter method locks it again. We must not + // enforce dependencies here because we did not enforce dependencies + // when looking up |descriptor|, and we need the two to match. string fully_qualified_name = descriptor->full_name() + "." + name_part; - Symbol symbol = builder_->FindSymbol(fully_qualified_name); + Symbol symbol = + builder_->FindSymbolNotEnforcingDeps(fully_qualified_name); if (!symbol.IsNull() && symbol.type == Symbol::FIELD) { field = symbol.field_descriptor; } else { @@ -3378,7 +3392,7 @@ bool DescriptorBuilder::OptionInterpreter::InterpretSingleOption( } } - if (!field) { + if (field == NULL) { return AddNameError("Option \"" + debug_msg_name + "\" unknown."); } else if (field->containing_type() != descriptor) { // This can only happen if, due to some insane misconfiguration of the @@ -3670,10 +3684,11 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( fully_qualified_name += value_name; // Search for the enum value's descriptor in the builder's pool. Note - // that we use DescriptorBuilder::LookupSymbol(), not + // that we use DescriptorBuilder::FindSymbolNotEnforcingDeps(), not // DescriptorPool::FindEnumValueByName() because we're already holding // the pool's mutex, and the latter method locks it again. - Symbol symbol = builder_->FindSymbol(fully_qualified_name); + Symbol symbol = + builder_->FindSymbolNotEnforcingDeps(fully_qualified_name); if (!symbol.IsNull() && symbol.type == Symbol::ENUM_VALUE) { if (symbol.enum_value_descriptor->type() != enum_type) { return AddValueError("Enum type \"" + enum_type->full_name() + |