diff options
author | Josh Haberman <jhaberman@gmail.com> | 2014-12-03 14:18:28 -0800 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2014-12-03 14:19:59 -0800 |
commit | 39c9a8bd5a278873e8ca00b0f50e2494a60deb26 (patch) | |
tree | 336ed01c8b25407151861a21efb53bc6ea83fb53 /upb/bindings/googlepb/proto2.cc | |
parent | 177212c82f62e86e67bca69d1dbcf9d39d9123c4 (diff) |
Sync from Google-internal development.
Most notably, a JSON parser is now provided.
Diffstat (limited to 'upb/bindings/googlepb/proto2.cc')
-rw-r--r-- | upb/bindings/googlepb/proto2.cc | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/upb/bindings/googlepb/proto2.cc b/upb/bindings/googlepb/proto2.cc index 498ae2d..3911172 100644 --- a/upb/bindings/googlepb/proto2.cc +++ b/upb/bindings/googlepb/proto2.cc @@ -978,32 +978,32 @@ case goog::FieldDescriptor::cpptype: \ } }; -#ifdef GOOGLE_PROTOBUF_HAS_ARENAS - // Closure is a RepeatedPtrField<SubMessageType>*, but we access it through - // its base class RepeatedPtrFieldBase*. - static goog::Message* StartRepeatedSubMessage( - goog::internal::RepeatedPtrFieldBase* r, - const SubMessageHandlerData* data) { - goog::Message* submsg = data->prototype()->New(r->GetArenaNoVirtual()); - r->AddAllocated<RepeatedMessageTypeHandler>(submsg); - return submsg; - } -#else // ifdef GOOGLE_PROTOBUF_HAS_ARENAS // Closure is a RepeatedPtrField<SubMessageType>*, but we access it through // its base class RepeatedPtrFieldBase*. static goog::Message* StartRepeatedSubMessage( goog::internal::RepeatedPtrFieldBase* r, const SubMessageHandlerData* data) { +#ifdef GOOGLE_PROTOBUF_HAS_ARENAS + return r->Add<RepeatedMessageTypeHandler>( + const_cast<goog::Message*>(data->prototype())); +#else + // This code path is required not because of arena-related API changes but + // because the variant of Add<>() that takes a prototype object was added + // only recently. Without the prototype, there's no way for Add<>() to + // create a new submessage with out typehandler implementation because we + // don't have New() (because we don't template-specialize our typehandler + // class on concrete message types). So we have to implement the runtime + // polymorphism externally (in this function) and then use AddAllocated to + // insert the pointer. goog::Message* submsg = r->AddFromCleared<RepeatedMessageTypeHandler>(); if (!submsg) { submsg = data->prototype()->New(); r->AddAllocated<RepeatedMessageTypeHandler>(submsg); } return submsg; +#endif } -#endif // ifdef GOOGLE_PROTOBUF_HAS_ARENAS - #ifdef GOOGLE_PROTOBUF_HAS_ONEOF static goog::Message* StartOneofSubMessage( goog::Message* m, const OneofSubMessageHandlerData* data) { |