[omniORB] Extraction of strings from Any

David Riddoch djr@uk.research.att.com
Mon, 24 May 1999 14:39:40 +0100 (GMT)


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
> 
> 
> 
>