Re: [protobuf] MutableExtension crash in Release only

2018-03-27 Thread 'Feng Xiao' via Protocol Buffers
On Tue, Mar 27, 2018 at 5:24 AM Vylsain  wrote:

> 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 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 ?
>
I don't see a problem there, except that "pB->fooB = 1; " won't compile.
It's likely the problem is not in the code shown above.


>
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] MutableExtension crash in Release only

2018-03-27 Thread Vylsain
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 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.