CORBA_any usage



I know this is not ORBit specific question but a C-language binding one
but I do not know of a more apropriate place to ask.

I have some problems with the usage of the CORBA_any type.
The language specification declare

typedef struct CORBA_any
{
	CORBA_TypeCode _type;
	void*          _value;
} CORBA_any;

And the specification states that _value should be a pointer
to the datum.

But suppose that I have a corba method

any getMeSomething();


with an implementation somewhere along the lines

CORBA_any* getMeSomething (....., .....)
{
	long x;
	CORBA_any *returnValue;

	x = aFunctionReturningAnInteger ();

	// Initializing the CORBA_any value.

	returnValue = CORBA_any__alloc ();
	returnValue->_type = TC_CORBA_long;
	
	// What now?????

	XXXXXXX;
}

The XXXXXX if I read the spec correctly should be:

	returnValue->_value = &x;

But this obviously is not going to work because x is allocated on the stack.
But allocating memory for just an integer seems

a) lot of overhead (but I do not really care about that right now)
b) When is that memory freed?
	I suppose that a trick along the line

		returnValue->_value = CORBA_char (sizeof (CORBA_long) - 1);
		* ((CORBA_long*) returnValue->_value) = x;

		CORBA_any_set_release (returnValue, CORBA_TRUE);

	could work.  But it sure is ugly.


I hope I am missing something obvious here.

Greetings,

Wim Oudshoorn.

	




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]