[omniORB] Extraction of strings from Any
Luke Tunmer
luke@harlequin.co.uk
Tue, 25 May 1999 12:36:10 +0100
Hi David,
I forwarded you argument to Michi Henning (whose book prompted me to look at
this issue), and he's replied that the spec is now unarguably clear - the
Any will look after the returned string and the caller should not free it.
Below is his reply to my question.
The key sentence in the new spec is:
For non-primitive types such as struct, union, sequence, exception, string,
wstring, and Any, extraction is done by pointer to const....
I'll be interested in hearing how and when Omni will deal with this
clarification of the spec.
Many thanks,
Luke
> -----Original Message-----
> From: Michi Henning [mailto:michi@triodia.com]
> Sent: 25 May 1999 12:14
> To: Luke Tunmer
> Subject: Re: Extracting strings from Any in C++
>
>
> On Tue, 25 May 1999, Luke Tunmer wrote:
>
> > Since String is as primitive types, Omni claim that the extraction of a
> > string is done by value semantics and therefore the caller
> needs to free the
> > memory.
> >
> > Clearly there's a disagreement over the interpretation of the
> spec which is
> > somewhat worrying. We have one important ORB vendor disagreeing with an
> > authoritative book, which cannot be a good thing. Do you have
> any insights
> > into this? Should Omni change their implementation? Do you know
> what other
> > ORBs do?
>
> There can be no argument about this. The Any continues to own the memory
> for the string. From section 23.16.3 of the C++ mapping (latest version is
> http://www.omg.org/pub/docs/ptc/99-03-04.pdf):
>
> If the extraction is successful, the caller's pointer will point
> to storage managed by the any and operator>>= will return TRUE.
> The caller must not try to delete or otherwise release this storage.
>
> OmniORB is wrong, I'm afraid, and the mapping has been this way for years.
> Other ORBs (Visi, Orbix, ORBacus, ORB Plus) implement this correctly.
>
> Cheers,
>
> Michi.
> --
> Michi Henning +61 7 3236 1633
> Triodia Technologies +61 4 1118 2700 (mobile)
> PO Box 372 +61 7 3211 0047 (fax)
> Annerley 4103 michi@triodia.com
> AUSTRALIA
http://www.triodia.com/staff/michi-henning.html
> -----Original Message-----
> From: David Riddoch [mailto:djr@uk.research.att.com]
> Sent: 24 May 1999 14:40
> To: Luke Tunmer
> Cc: omniorb-list@uk.research.att.com
> Subject: Re: [omniORB] Extraction of strings from Any
>
>
>
> Hi Luke,
>
> Looking at the CORBA 2.2 specification (20-49 onwards), there are two
> types of extraction operator for any.
>
> Boolean operator >>= (const Any&, T&);
> Boolean operator >>= (const Any&, T*&);
>
> The first version is used for primitive types, enumerations, strings and
> object references. The second version for other types.
>
> At the top of page 20-50, it states that the first version "suffices for
> primitive types that are normally passed by value". This implies that
> strings are passed by value.
>
> Further down, we have:
> "for non-primitive types, such as struct, union, sequence, exception,
> Any, and fixed types, extraction is done by pointer".
>
> Notice that string is not included in the list. Strings are very much
> grouped with primitive types -- which is sensible because it is a
> primitive type in IDL. Thus we believe that it is intended that strings
> should be extracted with the value semantics, and not with the same
> semantics as compound types.
>
> Further, C++ revision issue 150 (http://www.omg.org/issues/issue150.txt)
> asks for clarification of this point. Apparently 'clarifying text' has
> been added. As far as I can tell this refers to the following change:
>
> CORBA 2.0 "for non-primitive types, extraction is done by pointer"
> CORBA 2.2 "for non-primitive types, such as struct, union, sequence,
> exception, Any, and fixed types, extraction is done by pointer"
>
> So strings have not been included in this list. Thus they are not
> extracted by pointer. Thus the storage is not managed by the Any.
>
> I hope you all agree!
> David
>
>
>
> On Mon, 24 May 1999, Luke Tunmer wrote:
>
> > While stepping through the Omni code which extracts a string
> from an Any, I
> > noticed that the code allocates the memory for the string and
> returns that.
> > Having seen this I naturally inserted the returned string into a _var to
> > look after it, and it all worked well.
> >
> > However I've just read Henning and Vinoski's book "Advanced CORBA
> > Programming with C++" and they explicitly say that the string
> returned from:
> >
> > CORBA::Boolean CORBA::Any::operator>>=(char*& s) const
> >
> > is managed by the Any and should not be freed by the caller.
> The 2.3 spec of
> > the C++ mapping is not very clear in this regard, so it's understandable
> > that confusion might reign. For complex types the spec is clear
> in that it
> > does say that the Any will look after the memory.
> >
> > Are people aware of this difference, and will Omni ever change it?
> >
> > Thanks in advance,
> > Luke Tunmer
> >
> >
> >
> >
>