Discussion:
[protobuf] MutableExtension crash in Release only
Vylsain
2018-03-27 12:24:38 UTC
Permalink
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 protobuf+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
'Feng Xiao' via Protocol Buffers
2018-03-27 19:00:25 UTC
Permalink
Post by 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.
*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;*
*}*
*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 ?
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.
Post by Vylsain
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
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Vylsain
2018-03-29 12:21:32 UTC
Permalink
Ok, thanks for your answer. I will look for the problem somewhere else
then. ;)
Post by 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.
*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;*
*}*
*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 protobuf+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Egor Basharin
2018-11-15 13:06:14 UTC
Permalink
Hi, did you find out the reason of the problem?
Post by Vylsain
Ok, thanks for your answer. I will look for the problem somewhere else
then. ;)
Post by 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.
*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;*
*}*
*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 protobuf+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Loading...