aboutsummaryrefslogtreecommitdiffstats
path: root/src/google/protobuf/dynamic_message.cc
diff options
context:
space:
mode:
authorWink Saville <wink@google.com>2010-05-29 13:00:38 -0700
committerWink Saville <wink@google.com>2010-05-29 13:00:38 -0700
commitd0332953cda33fb4f8e24ebff9c49159b69c43d6 (patch)
tree81612e8b12f590310aeb0ebf1da37b304eb7baa6 /src/google/protobuf/dynamic_message.cc
parentede38fe9b9f93888e6e41afc7abb09525f44da95 (diff)
downloadexternal_protobuf-d0332953cda33fb4f8e24ebff9c49159b69c43d6.zip
external_protobuf-d0332953cda33fb4f8e24ebff9c49159b69c43d6.tar.gz
external_protobuf-d0332953cda33fb4f8e24ebff9c49159b69c43d6.tar.bz2
Add protobuf 2.3.0 sources
This is the contents of protobuf-2.3.0.tar.bz2 from http://code.google.com/p/protobuf/downloads/list. Change-Id: Idfde09ce7ef5ac027b07ee83f2674fbbed5c30b2
Diffstat (limited to 'src/google/protobuf/dynamic_message.cc')
-rw-r--r--src/google/protobuf/dynamic_message.cc80
1 files changed, 58 insertions, 22 deletions
diff --git a/src/google/protobuf/dynamic_message.cc b/src/google/protobuf/dynamic_message.cc
index f8b5b4e..c711a2d 100644
--- a/src/google/protobuf/dynamic_message.cc
+++ b/src/google/protobuf/dynamic_message.cc
@@ -106,7 +106,11 @@ int FieldSpaceUsed(const FieldDescriptor* field) {
case FD::CPPTYPE_MESSAGE: return sizeof(RepeatedPtrField<Message>);
case FD::CPPTYPE_STRING:
- return sizeof(RepeatedPtrField<string>);
+ switch (field->options().ctype()) {
+ default: // TODO(kenton): Support other string reps.
+ case FieldOptions::STRING:
+ return sizeof(RepeatedPtrField<string>);
+ }
break;
}
} else {
@@ -122,7 +126,11 @@ int FieldSpaceUsed(const FieldDescriptor* field) {
case FD::CPPTYPE_MESSAGE: return sizeof(Message*);
case FD::CPPTYPE_STRING:
- return sizeof(string*);
+ switch (field->options().ctype()) {
+ default: // TODO(kenton): Support other string reps.
+ case FieldOptions::STRING:
+ return sizeof(string*);
+ }
break;
}
}
@@ -262,19 +270,24 @@ DynamicMessage::DynamicMessage(const TypeInfo* type_info)
break;
case FieldDescriptor::CPPTYPE_STRING:
- if (!field->is_repeated()) {
- if (is_prototype()) {
- new(field_ptr) const string*(&field->default_value_string());
+ switch (field->options().ctype()) {
+ default: // TODO(kenton): Support other string reps.
+ case FieldOptions::STRING:
+ if (!field->is_repeated()) {
+ if (is_prototype()) {
+ new(field_ptr) const string*(&field->default_value_string());
+ } else {
+ string* default_value =
+ *reinterpret_cast<string* const*>(
+ type_info_->prototype->OffsetToPointer(
+ type_info_->offsets[i]));
+ new(field_ptr) string*(default_value);
+ }
} else {
- string* default_value =
- *reinterpret_cast<string* const*>(
- type_info_->prototype->OffsetToPointer(
- type_info_->offsets[i]));
- new(field_ptr) string*(default_value);
+ new(field_ptr) RepeatedPtrField<string>();
}
- } else {
- new(field_ptr) RepeatedPtrField<string>();
- }
+ break;
+ }
break;
case FieldDescriptor::CPPTYPE_MESSAGE: {
@@ -329,8 +342,13 @@ DynamicMessage::~DynamicMessage() {
#undef HANDLE_TYPE
case FieldDescriptor::CPPTYPE_STRING:
- reinterpret_cast<RepeatedPtrField<string>*>(field_ptr)
- ->~RepeatedPtrField<string>();
+ switch (field->options().ctype()) {
+ default: // TODO(kenton): Support other string reps.
+ case FieldOptions::STRING:
+ reinterpret_cast<RepeatedPtrField<string>*>(field_ptr)
+ ->~RepeatedPtrField<string>();
+ break;
+ }
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
@@ -340,10 +358,16 @@ DynamicMessage::~DynamicMessage() {
}
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) {
- string* ptr = *reinterpret_cast<string**>(field_ptr);
- if (ptr != &field->default_value_string()) {
- delete ptr;
+ switch (field->options().ctype()) {
+ default: // TODO(kenton): Support other string reps.
+ case FieldOptions::STRING: {
+ string* ptr = *reinterpret_cast<string**>(field_ptr);
+ if (ptr != &field->default_value_string()) {
+ delete ptr;
+ }
+ break;
}
+ }
} else if ((field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) &&
!is_prototype()) {
Message* message = *reinterpret_cast<Message**>(field_ptr);
@@ -373,7 +397,7 @@ void DynamicMessage::CrossLinkPrototypes() {
// For singular fields, the field is just a pointer which should
// point to the prototype.
*reinterpret_cast<const Message**>(field_ptr) =
- factory->GetPrototype(field->message_type());
+ factory->GetPrototypeNoLock(field->message_type());
}
}
}
@@ -410,11 +434,13 @@ struct DynamicMessageFactory::PrototypeMap {
};
DynamicMessageFactory::DynamicMessageFactory()
- : pool_(NULL), prototypes_(new PrototypeMap) {
+ : pool_(NULL), delegate_to_generated_factory_(false),
+ prototypes_(new PrototypeMap) {
}
DynamicMessageFactory::DynamicMessageFactory(const DescriptorPool* pool)
- : pool_(pool), prototypes_(new PrototypeMap) {
+ : pool_(pool), delegate_to_generated_factory_(false),
+ prototypes_(new PrototypeMap) {
}
DynamicMessageFactory::~DynamicMessageFactory() {
@@ -424,8 +450,18 @@ DynamicMessageFactory::~DynamicMessageFactory() {
}
}
-
const Message* DynamicMessageFactory::GetPrototype(const Descriptor* type) {
+ MutexLock lock(&prototypes_mutex_);
+ return GetPrototypeNoLock(type);
+}
+
+const Message* DynamicMessageFactory::GetPrototypeNoLock(
+ const Descriptor* type) {
+ if (delegate_to_generated_factory_ &&
+ type->file()->pool() == DescriptorPool::generated_pool()) {
+ return MessageFactory::generated_factory()->GetPrototype(type);
+ }
+
const DynamicMessage::TypeInfo** target = &prototypes_->map_[type];
if (*target != NULL) {
// Already exists.