Hi,
 
I'm trying to implement polymorphism with protobuf. I want to have several 
levels, each new level extending the previous one.
I have a crash when calling MutableExtension.

My .proto file looks like :


*package aapb;*

*message A*
*{*
*     optional int32 fooA = 1;*

*     extensions 1000 to max;*
*}*

*message B*
*{*
*     extend A*
*     {*

*optional B b = 1000;*

*     }*

*     optional int32 fooB = 1;*

*     extensions 1000 to max;*
*}*

*message C*
*{*
*     extend B*

*     {*

*optional C c = 1000;*

*     }*

*     optional int32 fooC = 1;*

*     extensions 1000 to max;*
*}*



On the C++ side, I have the corresponding classes :

*class A*
*{*
*    virtual void WriteExtensions(aapb::A *pA){}*
*}*

*class B : public A*
*{*
*    virtual void WriteExtensions(aapb::A *pA)*
*    {*
*        aapb::B* pB = pA->MutableExtension(aapb::B::b);*
*        pB->fooB = 1;*
*        WriteExtensions(pB);*
*    }*

*        virtual void WriteExtensions(aapb::B *pB){}*
*}*

*class C : public B*
*{*
*    virtual void WriteExtensions(aapb::B *pB)*
*    {*
*        aapb::C* pC = pB->MutableExtension(aapb::C::c);                    
 //crash happens here*
*        pC->fooC = 2;*
*    }*
*}*

Then, in my program I just create shared_ptr<C> and aapb::A objects and 
call C's WriteExtensions method with aapb::A reference as an argument.
It works as expected in Debug and I retrieve the correct data when reading 
the file.
But in Release, I have a segfault when writing the file, when it reaches 
the MutableExtension call of the C class.
To be more precise, the segfault happens on the call of 
*google::protobuf::internal::ExtensionSet::MutableMessage(int, 
unsigned char, google::protobuf::MessageLite const&, 
google::protobuf::FieldDescriptor const*) ()*

I'm struggling to see where the problem is coming from and wanted to make 
sure the protobuf part is correct before I look for other causes.
So you guys see anything wrong in the way I use this ?

Thanks


-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to