[omniORB] Extraction of Struct from Any
Monceaux, Weston P ERDC-ITL-MS Contractor
Weston.P.Monceaux@erdc.usace.army.mil
Mon, 20 Nov 2000 15:23:06 -0600
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C05338.12FD7B90
Content-Type: text/plain;
charset="iso-8859-1"
Hello.
I have searched the mailing list archives for an answer and haven't had much
luck, so I apologize if this is a repeat question.
Setup:
Using Visual C++ 6 with OmniOrb 3.02
Creating a DLL that links dynamically with OmniOrb. (This DLL is to be used
by another C++ client as a means of "hiding" the fact that CORBA is being
used.)
The IDL of the struct in question is similar to this:
//IDL
struct TraderEntry
{
string name;
...
string summary;
double quality;
};
As you can see it is quite basic; just a struct full of strings and a
double. The code actually causing the problem is as follows:
int FSData::get_prop_as_TraderEntry(const char* prop, FSTraderEntry &value)
{
try
{
CORBA::Any* any = data->get_prop(prop);
const FrameworkServices::TraderEntry* te;
if(!(*any >>= te))
return -1;
value.revert(*te); // I have removed this and still get
problems, so I don't think it is an issue
// It just copies the values from "te" into
the non-CORBA FSTraderEntry "value"
if(any)
delete any; // <-- This causes a memory access
violation
}
catch(FrameworkServices::FSException&)
{
return -1;
}
return 0;
}
For some reason deleting the "Any" causes a memory access violation. This
does not happen when extracting strings, doubles, or even sequences of
octets. And the best I can figure from the CORBA 2.3 spec is that I should
be deleting the Any that is returned from that call to data->get_prop().
It works in every other case I have tried. Any ideas?
I can only come up with a couple of possible explanations, but can't/haven't
verified either. One is that the String_member objects that are generated
by OmniOrb's IDL are trying to manage the strings rather than letting the
Any maintain ownership, and this is causing some kind of problem. Or,
another problem may be that I am not accessing the correct heap when
deallocation occurs....as I am working from within two (possibly more
depending on OmniORB's implementation) DLLs.
Any ideas? Everything "appears" to work when I do not delete the Any. But
I am disturbed by the possibility of memory leaks and the lack of behavioral
consistency with the CORBA 2.3 spec. I am sure this is something I am doing
incorrectly, and I would appreciate any help.
Thanks.
Weston Monceaux
------_=_NextPart_001_01C05338.12FD7B90
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2448.0">
<TITLE>Extraction of Struct from Any</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2 FACE=3D"Arial">Hello.</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">I have searched the mailing list =
archives for an answer and haven't had much luck, so I apologize if =
this is a repeat question.</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">Setup:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Using Visual C++ 6 with OmniOrb =
3.02</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Creating a DLL that links dynamically =
with OmniOrb. (This DLL is to be used by another C++ client as a =
means of "hiding" the fact that CORBA is being =
used.)</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">The IDL of the struct in question is =
similar to this:</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">//IDL</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">struct TraderEntry</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">{</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">string name;</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">...</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">string summary;</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">double quality;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">};</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">As you can see it is quite basic; just =
a struct full of strings and a double. The code actually causing =
the problem is as follows:</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">int =
FSData::get_prop_as_TraderEntry(const char* prop, FSTraderEntry =
&value)</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">{</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">try</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">{</FONT>
<BR> =
<FONT SIZE=3D2 =
FACE=3D"Arial">CORBA::Any* any =3D data->get_prop(prop);</FONT>
</P>
<P> =
<FONT SIZE=3D2 =
FACE=3D"Arial">const FrameworkServices::TraderEntry* te;</FONT>
<BR> =
<FONT SIZE=3D2 =
FACE=3D"Arial">if(!(*any >>=3D te))</FONT>
<BR> =
=
<FONT SIZE=3D2 =
FACE=3D"Arial">return -1;</FONT>
</P>
<P> =
<FONT SIZE=3D2 =
FACE=3D"Arial">value.revert(*te); // I have removed this and =
still get problems, so I don't think it is an issue</FONT>
<BR> =
=
=
<FONT SIZE=3D2 =
FACE=3D"Arial">// It just copies the values from "te" =
into the non-CORBA FSTraderEntry "value"</FONT>
</P>
<P> =
<FONT SIZE=3D2 =
FACE=3D"Arial">if(any)</FONT>
<BR> =
=
<FONT SIZE=3D2 =
FACE=3D"Arial">delete any; // <-- This causes a memory access =
violation</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">}</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">catch(FrameworkServices::FSException&)</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">{</FONT>
<BR> =
<FONT SIZE=3D2 =
FACE=3D"Arial">return -1;</FONT>
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">}</FONT>
</P>
<P> <FONT SIZE=3D2 =
FACE=3D"Arial">return 0;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">}</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">For some reason deleting the =
"Any" causes a memory access violation. This does not =
happen when extracting strings, doubles, or even sequences of =
octets. And the best I can figure from the CORBA 2.3 spec is that =
I should be deleting the Any that is returned from that call to =
data->get_prop(). It works in every other case I have =
tried. Any ideas?</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">I can only come up with a couple of =
possible explanations, but can't/haven't verified either. One is =
that the String_member objects that are generated by OmniOrb's IDL are =
trying to manage the strings rather than letting the Any maintain =
ownership, and this is causing some kind of problem. Or, another =
problem may be that I am not accessing the correct heap when =
deallocation occurs....as I am working from within two (possibly more =
depending on OmniORB's implementation) DLLs.</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">Any ideas? Everything =
"appears" to work when I do not delete the Any. But I =
am disturbed by the possibility of memory leaks and the lack of =
behavioral consistency with the CORBA 2.3 spec. I am sure this is =
something I am doing incorrectly, and I would appreciate any =
help.</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">Thanks.</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">Weston Monceaux</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C05338.12FD7B90--