From 39c9a8bd5a278873e8ca00b0f50e2494a60deb26 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Wed, 3 Dec 2014 14:18:28 -0800 Subject: Sync from Google-internal development. Most notably, a JSON parser is now provided. --- upb/bindings/googlepb/proto2.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'upb/bindings') 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*, 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(submsg); - return submsg; - } -#else // ifdef GOOGLE_PROTOBUF_HAS_ARENAS // Closure is a RepeatedPtrField*, 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( + const_cast(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(); if (!submsg) { submsg = data->prototype()->New(); r->AddAllocated(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) { -- cgit v1.2.3