Re: CORBA_free() question



Michael Meeks wrote:
> 
> On Tue, 2003-05-27 at 16:32, Chris Wareham wrote:
>>I have a utility function which returns an object reference by looking
>>it up in the Naming service.
> 
> 	The Naming service is pure pain to use AFAIR; ;-)
> 

I must be masochistic, because I find it quite straightforward :-). Or
at least I did after I'd read the OMG Naming Service spec. The hard part
is figuring out the C mapping - running the IDL through the compiler and
picking it apart was my eventual solution.

I haven't tried writing an server using it though, only clients. My
server currently uses MICO, but I'm definitely going to try porting it
to ORBit.

> 
> 	You need to CORBA_free everything you CORBA_allocate, except that is if
> you do a deep free, in which case there's no point in freeing the
> children. However:
> 
>>     name_components[0].id = CORBA_string_dup(id);
>>     name_components[0].kind = CORBA_string_dup(kind);
> 
> 	These dups are not necessary - unless 'name' is an InOut argument ( is
> it ? ) - for an in argument one just has to garentee the lifetime of the
> strings over the method call.
> 

You're correct. My other source of information is the "GNOME & CORBA"
document, which is good in places but a little dubious in others. The
client example they give does the CORBA_string_dup()'s, but a quick test
shows it's unnecessary.

My cleaned up code now looks like:

CORBA_Object
get_object(char *id, char *kind)
{
     CosNaming_NameComponent name_components[1];
     CosNaming_Name name = { 1, 1, name_components, CORBA_FALSE };
     CORBA_Environment ev;
     CORBA_Object obj;

     name_components[0].id = id;
     name_components[0].kind = kind;

     CORBA_exception_init(&ev);

     obj = CosNaming_NamingContext_resolve(naming_context, &name, &ev);
     if (ev._major != CORBA_NO_EXCEPTION)
         obj = CORBA_OBJECT_NIL;

     CORBA_exception_free(&ev);

     return obj;
}

Chris
-- 
chris.wareham@iosystems.co.uk (work)
chris.wareham@btopenworld.com (home)




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