[omniORB] anys in version 280

Barend Gehrels barend@geodan.nl
Wed, 20 Oct 1999 15:12:57 +0200


--------------DBA84156A9662441ECEC3157
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

hi,

I've used the code fragments below in omniOrb 2.7.1, which worked. I'm
now porting to 2.8.0, but it results in a crash. It has something to do
with the new any-extraction and/or insertion. I'm using structures of
which one field is an Any field, and sequences of those structures.
Can anyone tell me what I'm doing wrong?

Thanks, Barend



// ----------------------------------
// idl
module OGIS
{
 struct NVPair
 {
  string name;
  any value;
 };

 typedef sequence<NVPair> NVPairSeq;
};
// ----------------------------------



// ----------------------------------
// cpp
ostream& operator<< (ostream &s, const CORBA::Any &a);

ostream& operator<< (ostream &s, const OGIS::NVPair &nv)
{
 return s << "<" << nv.name << ">" << nv.value << "</" << nv.name <<
">";
}

ostream& operator<< (ostream &s, const OGIS::NVPairSeq &nv)
{
 for (int i = 0; i < nv.length(); i++)
 {
  s << nv[i] << endl;
 }
 return s;
}

ostream& operator<< (ostream &s, const CORBA::Any &a)
{
 CORBA::Long vl;
 CORBA::Double vd;
 const char* vs;
 const OGIS::NVPairSeq* nvs;
 const OGIS::NVPair* nv;

 if (a >>= vl) s << vl;
 else if (a >>= vd) s << vd;
 else if (a >>= vs) s << vs;
 else if (a >>= nv) s << (* nv);
 else if (a >>= nvs) s << (* nvs);
 else
 {
  s << "Unknown type" << endl;
 }
 return s;
}

int main(int argc, char **argv)
{
 g_Orb = CORBA::ORB_init(argc, argv, "omniORB2");
 g_boa = g_Orb->BOA_init(argc, argv, "omniORB2_BOA");

 //omniORB::omniORB_27_CompatibleAnyExtraction = true; // makes no
difference

 {
  OGIS::NVPair Nv;

  const char* n = "name";
  const char* s = "contents";
  //CORBA::Long s = 3; // this instead of previous line goes also wrong
  Nv.name = n;
  Nv.value <<= s;

  OGIS::NVPairSeq Seq;

  Seq.length(1);
  Seq[0].name = n;
  Seq[0].value <<= Nv;

  cout << Nv << endl;
  cout << Seq << endl; // if I remove this line it does NOT crash
 }

 return 1;

}

------------------------------
Barend Gehrels
Geodan IT bv, the Netherlands
tel: +31 20 570 7300
fax: +31 20 570 7333
E-mail: barend@geodan.nl
http://www.geodan.nl
------------------------------


--------------DBA84156A9662441ECEC3157
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
hi,
<p>I've used the code fragments below in omniOrb 2.7.1, which worked. I'm
now porting to 2.8.0, but it results in a crash. It has something to do
with the new any-extraction and/or insertion. I'm using structures of which
one field is an Any field, and sequences of those structures.
<br>Can anyone tell me what I'm doing wrong?
<p>Thanks, Barend
<br>&nbsp;
<br>&nbsp;
<p><tt>// ----------------------------------</tt>
<br><tt>// idl</tt>
<br><tt>module OGIS</tt>
<br><tt>{</tt>
<br><tt>&nbsp;struct NVPair</tt>
<br><tt>&nbsp;{</tt>
<br><tt>&nbsp; string name;</tt>
<br><tt>&nbsp; any value;</tt>
<br><tt>&nbsp;};</tt>
<p><tt>&nbsp;typedef sequence&lt;NVPair> NVPairSeq;</tt>
<br><tt>};</tt>
<br><tt>// ----------------------------------</tt>
<br>&nbsp;
<br>&nbsp;
<p><tt>// ----------------------------------</tt>
<br><tt>// cpp</tt>
<br><tt>ostream&amp; operator&lt;&lt; (ostream &amp;s, const CORBA::Any
&amp;a);</tt>
<p><tt>ostream&amp; operator&lt;&lt; (ostream &amp;s, const OGIS::NVPair
&amp;nv)</tt>
<br><tt>{</tt>
<br><tt>&nbsp;return s &lt;&lt; "&lt;" &lt;&lt; nv.name &lt;&lt; ">" &lt;&lt;
nv.value &lt;&lt; "&lt;/" &lt;&lt; nv.name &lt;&lt; ">";</tt>
<br><tt>}</tt>
<p><tt>ostream&amp; operator&lt;&lt; (ostream &amp;s, const OGIS::NVPairSeq
&amp;nv)</tt>
<br><tt>{</tt>
<br><tt>&nbsp;for (int i = 0; i &lt; nv.length(); i++)</tt>
<br><tt>&nbsp;{</tt>
<br><tt>&nbsp; s &lt;&lt; nv[i] &lt;&lt; endl;</tt>
<br><tt>&nbsp;}</tt>
<br><tt>&nbsp;return s;</tt>
<br><tt>}</tt>
<p><tt>ostream&amp; operator&lt;&lt; (ostream &amp;s, const CORBA::Any
&amp;a)</tt>
<br><tt>{</tt>
<br><tt>&nbsp;CORBA::Long vl;</tt>
<br><tt>&nbsp;CORBA::Double vd;</tt>
<br><tt>&nbsp;const char* vs;</tt>
<br><tt>&nbsp;const OGIS::NVPairSeq* nvs;</tt>
<br><tt>&nbsp;const OGIS::NVPair* nv;</tt>
<p><tt>&nbsp;if (a >>= vl) s &lt;&lt; vl;</tt>
<br><tt>&nbsp;else if (a >>= vd) s &lt;&lt; vd;</tt>
<br><tt>&nbsp;else if (a >>= vs) s &lt;&lt; vs;</tt>
<br><tt>&nbsp;else if (a >>= nv) s &lt;&lt; (* nv);</tt>
<br><tt>&nbsp;else if (a >>= nvs) s &lt;&lt; (* nvs);</tt>
<br><tt>&nbsp;else</tt>
<br><tt>&nbsp;{</tt>
<br><tt>&nbsp; s &lt;&lt; "Unknown type" &lt;&lt; endl;</tt>
<br><tt>&nbsp;}</tt>
<br><tt>&nbsp;return s;</tt>
<br><tt>}</tt>
<p><tt>int main(int argc, char **argv)</tt>
<br><tt>{</tt>
<br><tt>&nbsp;g_Orb = CORBA::ORB_init(argc, argv, "omniORB2");</tt>
<br><tt>&nbsp;g_boa = g_Orb->BOA_init(argc, argv, "omniORB2_BOA");</tt>
<p><tt>&nbsp;//omniORB::omniORB_27_CompatibleAnyExtraction = true; // makes
no difference</tt>
<p><tt>&nbsp;{</tt>
<br><tt>&nbsp; OGIS::NVPair Nv;</tt>
<p><tt>&nbsp; const char* n = "name";</tt>
<br><tt>&nbsp; const char* s = "contents";</tt>
<br><tt>&nbsp; //CORBA::Long s = 3; // this instead of previous line goes
also wrong</tt>
<br><tt>&nbsp; Nv.name = n;</tt>
<br><tt>&nbsp; Nv.value &lt;&lt;= s;</tt>
<p><tt>&nbsp; OGIS::NVPairSeq Seq;</tt>
<p><tt>&nbsp; Seq.length(1);</tt>
<br><tt>&nbsp; Seq[0].name = n;</tt>
<br><tt>&nbsp; Seq[0].value &lt;&lt;= Nv;</tt>
<p><tt>&nbsp; cout &lt;&lt; Nv &lt;&lt; endl;</tt>
<br><tt>&nbsp; cout &lt;&lt; Seq &lt;&lt; endl; // if I remove this line
it does NOT crash</tt>
<br><tt>&nbsp;}</tt>
<p><tt>&nbsp;return 1;</tt>
<p><tt>}</tt>
<p>------------------------------
<br>Barend Gehrels
<br>Geodan IT bv, the Netherlands
<br>tel: +31 20 570 7300
<br>fax: +31 20 570 7333
<br>E-mail: barend@geodan.nl
<br><A HREF="http://www.geodan.nl">http://www.geodan.nl</A>
<br>------------------------------
<br>&nbsp;</html>

--------------DBA84156A9662441ECEC3157--