[omniORB] strings parameters passing rules.

Clarke Brunt clarke.brunt at yeomannavigation.co.uk
Wed Oct 8 14:01:15 BST 2003


Hopefully my own reply will have appeared by now, as well as Alex's one.

I said I'd make a mistake or two. Mine were to say that you need 'free xxx',
when I meant 'delete xxx', and also not to address the question of the
ownership of the string passed into my_func in str_inout.

Alex took care of the latter problem with:
>  // inout_val.s_mem adopts contents of str_inout
>  inout_val.s_mem = str_inout;

whereas my version didn't free the memory pointed at by the callers
str_inout. As I say below, you need to carefully define whether the caller
should expect it to be freed or not.

Alex also used:
>  // inout_val.s_mem yields ownership of contents to str_inout
>  str_inout = inout_val.s_mem._retn();

which saved an avoidable string_dup in my version.

It's up to you to define how you want my_func to behave, but it would be
natural to pretend that it was a true CORBA method, and say that str_inout
will be freed (using CORBA::string_free) by my_func (so the input value must
be allocated by CORBA::string_alloc, or string_dup), and the output value
must be CORBA::string_free'd by the caller.

I think Alex forgot to change the declaration of str_inout to something that
was capable of returning anything useful to the caller.

And use the _var types wherever possible! They are the answer to all your
problems of possibly forgetting to free things, handling exceptions
correctly, etc.

--
Clarke Brunt, Principal Software Engineer, Yeoman Navigation




More information about the omniORB-list mailing list