From SYegnaram at cls-bank.com Wed Feb 9 00:36:14 2022 From: SYegnaram at cls-bank.com (Yegnaram, Shrikant) Date: Wed Feb 9 08:16:44 2022 Subject: [xsde-users] XSDE : choice_arm function code generation question Message-ID: Hi We have an internal XSD for which we are generating C++ code using XSDE tool - xsde-3.2.0-x86_64-linux-gnu . We are using following options for code generation cxx-hybrid --generate-parser --generate-aggregate --generate-inline --omit-default-attributes --generate-serializer Our XSD snippet is as below : ... ... The xmlevents.hxx generated is as in below snippet class XYZMessageClass { ... private: ::xmlevents::XYZ_MSG_CLASSES __switch_; union { union { size_t align_; char data_[sizeof (::xmlevents::XYZ_CONTROL_CLASS)]; } control_; ::xmlevents::XYZ_COM_INPUT_CLASS* comInput_; ::xmlevents::ABC_INPUT_CLASS* abcInputClass_; ::xmlevents::XYZ_NOTIFICATION_CLASS* notification_; ... }; The corresponding xmlevents.cxx snippet of code is as below void XYZMessageClass:: choice_arm (choice_arm_tag x) { if (this->choice_arm_ == x) return; switch (this->choice_arm_) { case control_tag: { typedef ::xmlevents::XYZ_CONTROL_CLASS _dtor; reinterpret_cast< ::xmlevents::XYZ_CONTROL_CLASS& > (this->choice_.control_).~_dtor (); break; } case comInput_tag: { delete this->choice_.comInput_; break; } case abcInputClass_tag: { delete this->choice_.abcInputClass_; break; } ... this->choice_arm_ = choice_arm_tag (57); switch (x) { case control_tag: { new (&this->choice_.control_) ::xmlevents::XYZ_CONTROL_CLASS; break; } case comInput_tag: { this->choice_.comInput_ = 0; break; } case abcInputClass_tag: { this->choice_.abcInputClass_ = 0; break; } ... this->choice_arm_ = x; } The question here is regarding elements like XYZMessage.comInput are not allocated / deallocated memory in the choice_arm function like XYZMessage.control field. Our question is huge and cannot share entire details . We are trying to understand why XSDE is not generating code to allocate/deallocate memory for XYZMessage.comInput like XYZMessage.control field in the choice_arm function. We would want to know 1. Why is XSDE creating union {align,data_} for some of the classes in the xs:choice and not for others? We would like to understand this better. 2. If we can change the default behaviour to generate allocate/deallocate memory code for all such enums using any XSDE code generation options in choice_arm function 3. What is the ideal way to create these objects for serialization Thanks, Shrikant Yegnaram CLS Classification: Confidential Information This email was classified by Yegnaram, Shrikant on Wednesday, February 9, 2022 12:35:05 AM CLS is committed to protecting and safeguarding your personal data. Our privacy notice provides you with information about how we process and protect your personal data. We aim to ensure direct marketing is reasonable, proportionate and of relevance to you. However, if you no longer want to receive direct marketing from us please email dpo@cls-services.com. ************************************************************************************ WARNING: This message contains confidential information and is intended only for the individual named. If you are not the named addressee, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mails are not encrypted and cannot be guaranteed to be secure or error-free, as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of this e-mail transmission. If verification is required, please request a hard copy version. ************************************************************************************ WARNING: This message contains confidential information and is intended only for the individual named. If you are not the named addressee, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mails are not encrypted and cannot be guaranteed to be secure or error-free, as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of this e-mail transmission. If verification is required, please request a hard copy version. CLS is committed to protecting and safeguarding your personal data. Our privacy notice ( https://www.cls-group.com/privacy) provides you with information about how we process and protect your personal data. We aim to ensure direct marketing is reasonable, proportionate and of relevance to you. However, if you no longer want to receive direct marketing from us please email dpo@cls-services.com From boris at codesynthesis.com Wed Feb 9 08:36:26 2022 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Feb 9 08:33:23 2022 Subject: [xsde-users] XSDE : choice_arm function code generation question In-Reply-To: References: Message-ID: Yegnaram, Shrikant writes: > union > { > union > { > size_t align_; > char data_[sizeof (::xmlevents::XYZ_CONTROL_CLASS)]; > } control_; > ::xmlevents::XYZ_COM_INPUT_CLASS* comInput_; > ::xmlevents::ABC_INPUT_CLASS* abcInputClass_; > ::xmlevents::XYZ_NOTIFICATION_CLASS* notification_; > } > > [...] > > void XYZMessageClass:: > choice_arm (choice_arm_tag x) > { > if (this->choice_arm_ == x) > return; > > switch (this->choice_arm_) > { > case control_tag: > { > typedef ::xmlevents::XYZ_CONTROL_CLASS _dtor; > reinterpret_cast< ::xmlevents::XYZ_CONTROL_CLASS& > (this->choice_.control_).~_dtor (); > break; > } > case comInput_tag: > { > delete this->choice_.comInput_; > break; > } > case abcInputClass_tag: > { > delete this->choice_.abcInputClass_; > break; > } > > ... > > this->choice_arm_ = choice_arm_tag (57); > > switch (x) > { > case control_tag: > { > new (&this->choice_.control_) ::xmlevents::XYZ_CONTROL_CLASS; > break; > } > case comInput_tag: > { > this->choice_.comInput_ = 0; > break; > } > case abcInputClass_tag: > { > this->choice_.abcInputClass_ = 0; > break; > } > > ... > > this->choice_arm_ = x; > } > > > The question here is regarding elements like XYZMessage.comInput are > not allocated / deallocated memory in the choice_arm function like > XYZMessage.control field. The difference is due to whether the type is fixed or variable-length. This is covered in Section 4.2, "Memory Management": https://codesynthesis.com/projects/xsde/documentation/cxx/hybrid/guide/#4.2 > 1. Why is XSDE creating union {align,data_} for some of the classes > in the xs:choice and not for others? We would like to understand > this better. This is due to the fixed vs variable-length distinction. > 2. If we can change the default behaviour to generate > allocate/deallocate memory code for all such enums using any > XSDE code generation options in choice_arm function No, this is not going to be easy (unless you can change all your types to be fixed-length). But perhaps, after reading Section 4.2, you will see the reasoning behind doing it this way? > 3. What is the ideal way to create these objects for serialization For a fixed-length choice arm you can just assing/copy by-value. For a variable-length arm, you would allocate the arm object with new and then pass the pointer to it. Section 4.5, "Compositors" has some examples: https://codesynthesis.com/projects/xsde/documentation/cxx/hybrid/guide/#4.5