[omniORB] Getting a marshal Error

Brian Neal bgneal at gmail.com
Wed Dec 21 08:04:30 GMT 2011


2011/12/21 Rajesh Khan <rajeshkhan808 at gmail.com>:
> Hi i am getting a CORBA::marshal exception while trying to send an object
>
> This is the function implimentation at the server
>
> CustObj_Cont* CustObj_implimentation::get_obj() throw
> (CORBA::SystemException)
> {
>
>     CustObj_Cont vctor_;
>
>     CustObj obja;
>     obja.val =10;
>
>     vctor_.length(1);
>     vctor_[0]=obja;
>     return &vctor_;
> }
>

You aren't following the rules for the C++ mapping. Again, I suggest
you download a copy of the IDL to C++ mapping from the OMG website
(omg.org) and read it before you try to go further. An even better
resource is the Henning & Vinowski book "Advanced CORBA Programming
with C++".

Your function returns a sequence. The mapping requires you to new one
up. You can't just return the address of a local sequence on the
stack.

You probably want something like this (untested):

CustObj_Cont_var vector(new CustObj_Cont);
vector->length(1);

CustObj obja;
obja.val = 10;

vector[0] = obja;

return vector._retn();

I'm using the _var types for exception safety purposes, in case an
exception is thrown between the time you create the sequence but
before you can return it to the skeleton code. The "return
vector._retn();" tells the _var type not to delete the memory when its
destructor runs, as we want to give the sequence to the caller (the
skeleton code). The IDL to C++ generated skeleton code is responsible
for deleting the sequence after it has marshalled it back to the
client.

As you can see the (current) C++ mapping is not for the faint-hearted.
It is complicated and error prone. You need to read the book.  :)

Best,
BN



More information about the omniORB-list mailing list