As far as I know, it should be fine to call CppGenerator::Generate() multiple times. The compiler code is all single-threaded so I doubt that the problem is thread-related. How are you creating the FileDescriptor that you pass to the Generate() call? If I had to guess I would say that something is wrong with the descriptors on the second call--maybe they are being destroyed after the first call and the second call is trying to use a dangling pointer.
On Fri, Jul 5, 2019 at 6:33 AM JZ <[email protected]> wrote: > Hello, > > I am currently using Google's ProtocolBuffers inside my C++ app. > One feature I am adding will generate X.pb.cc and X.pb.h after I've > chosen a proto file from a file dialog. > > To do that, I am calling CppGenerator::Generate (I made my own > implementation of ZeroCopyOutputStream and GeneratorContext). I also > target-linked with pthread (otherwise, the Generate() call will send a SIG > ABRT error). > > The first time I do that, the .pb.cc and .pb.h files are generated > sucessfully. However, when I try to use this feature a second time, I get a > SIG ABRT error (it should be a multi-thread problem). > > The valgrind output shows : > > Process terminating with default action of signal 11 (SIGSEGV) > Access not within mapped region at address 0x38F0000057E > > google::protobuf::EnumDescriptor::FindValueByNumber(int) const > google::protobuf::internal::NameofEnum > google::protobuf::compiler::cpp::(anonymous > namespace)::SetPrimitiveVariables > > google::protobuf::compiler::cpp::PrimitiveFieldGenerator::PrimitiveFieldGenerator > google::protobuf::compiler::cpp::FieldGeneratorMap::MakeGenerator > google::protobuf::compiler::cpp::FieldGeneratorMap::FieldGeneratorMap > google::protobuf::compiler::cpp::MessageGenerator::MessageGenerator > google::protobuf::compiler::cpp::FileGenerator::FileGenerator > google::protobuf::compiler::cpp::CppGenerator::Generate > ProtobufGenerator::GenCode > > Is there a way to "reset" the threading system of the program once I have > finished the first call of Generate() ? > I have already tried to delete the instance of the CppGenerator and > reinstantiate a new one to call Generate() a second time, but it doesn't > work. > However, if I call Generate() twice consecutively within one same call of > the "GenCode" method, it works. > > I can't do that : > ProtobufGenerator::GenCode => > google::protobuf::compiler::cpp::CppGenerator::Generate > and then, another time > ProtobufGenerator::GenCode => > google::protobuf::compiler::cpp::CppGenerator::Generate > > But I can do : > ProtobufGenerator::GenCode => > google::protobuf::compiler::cpp::CppGenerator::Generate > google::protobuf::compiler::cpp::CppGenerator::Generate > > Any idea please? > > Thank you very much for your help > > -- > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/protobuf/ac21a635-0e67-4cb2-8d8c-20795a929c1c%40googlegroups.com > <https://groups.google.com/d/msgid/protobuf/ac21a635-0e67-4cb2-8d8c-20795a929c1c%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/CADqAXr4XQw53%3DU51ajnhpTh%2Bg3TS2S_XNDtGMHZr5y8pqdN1aw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
