aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/dynamic_message.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/dynamic_message.cc')
-rw-r--r--src/google/protobuf/dynamic_message.cc30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/google/protobuf/dynamic_message.cc b/src/google/protobuf/dynamic_message.cc
index 72a8483f..9e83bd29 100644
--- a/src/google/protobuf/dynamic_message.cc
+++ b/src/google/protobuf/dynamic_message.cc
@@ -69,8 +69,8 @@
#include <google/protobuf/stubs/shared_ptr.h>
#endif
-#include <google/protobuf/stubs/scoped_ptr.h>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/scoped_ptr.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/descriptor.h>
@@ -253,12 +253,6 @@ class DynamicMessage : public Message {
DynamicMessage(const TypeInfo* type_info);
~DynamicMessage();
-#ifndef _MSC_VER
- void operator delete(void *p) {
- ::operator delete(p); // non-sized deallocation
- }
-#endif
-
// Called on the prototype after construction to initialize message fields.
void CrossLinkPrototypes();
@@ -273,6 +267,16 @@ class DynamicMessage : public Message {
Metadata GetMetadata() const;
+ // We actually allocate more memory than sizeof(*this) when this
+ // class's memory is allocated via the global operator new. Thus, we need to
+ // manually call the global operator delete. Calling the destructor is taken
+ // care of for us. This makes DynamicMessage compatible with -fsized-delete.
+ // It doesn't work for MSVC though.
+#ifndef _MSC_VER
+ static void operator delete(void* ptr) {
+ ::operator delete(ptr);
+ }
+#endif // !_MSC_VER
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessage);
@@ -425,7 +429,7 @@ DynamicMessage::~DynamicMessage() {
}
// We need to manually run the destructors for repeated fields and strings,
- // just as we ran their constructors in the the DynamicMessage constructor.
+ // just as we ran their constructors in the DynamicMessage constructor.
// We also need to manually delete oneof fields if it is set and is string
// or message.
// Additionally, if any singular embedded messages have been allocated, we
@@ -448,8 +452,10 @@ DynamicMessage::~DynamicMessage() {
case FieldOptions::STRING: {
const ::std::string* default_value =
&(reinterpret_cast<const ArenaStringPtr*>(
- type_info_->prototype->OffsetToPointer(
- type_info_->offsets[i]))->Get(NULL));
+ reinterpret_cast<uint8*>(
+ type_info_->default_oneof_instance)
+ + type_info_->offsets[i])
+ ->Get(NULL));
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(
default_value, NULL);
break;
@@ -710,7 +716,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
// Oneof fields do not use any space.
if (!type->field(i)->containing_oneof()) {
int field_size = FieldSpaceUsed(type->field(i));
- size = AlignTo(size, min(kSafeAlignment, field_size));
+ size = AlignTo(size, std::min(kSafeAlignment, field_size));
offsets[i] = size;
size += field_size;
}
@@ -754,7 +760,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = type->oneof_decl(i)->field(j);
int field_size = OneofFieldSpaceUsed(field);
- oneof_size = AlignTo(oneof_size, min(kSafeAlignment, field_size));
+ oneof_size = AlignTo(oneof_size, std::min(kSafeAlignment, field_size));
offsets[field->index()] = oneof_size;
oneof_size += field_size;
}