Discussion:
[omniORB] Getting a marshal Error
Rajesh Khan
2011-12-21 15:50:34 UTC
Permalink
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_;
}

and when i access the method on the receiver (client) using

static void ProcessObject(TestInt_ptr e)
{
CustObj_Cont* obja = e->get_obj(); //At this point i get the CORBA
marshall error
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20111221/4e9f77a2/attachment.htm
Rajesh Khan
2011-12-21 15:52:30 UTC
Permalink
Correction : Actually i get the marshall error when trying to access the
object on the client
Post by Rajesh Khan
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_;
}
and when i access the method on the receiver (client) using
static void ProcessObject(TestInt_ptr e)
{
CustObj_Cont* obja = e->get_obj(); //At this point i get the CORBA
marshall error
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20111221/d29dd6fb/attachment.htm
Olivier Thiboutot
2011-12-21 19:34:53 UTC
Permalink
Hi Rajesh,

I would prefered using _var definition

Here is when the marshaling occurs your CustObj_Cont vctor_ is already destroy with the data since you are returning and destroying it before the real send is made over to the client, you need to let OmniOrb destroy it at the end of the sending process


CustObj_Cont* CustObj_implimentation::get_obj() throw
(CORBA::SystemException)
{

CustObj_Cont_var vctor_var = new CustObj_Cont;
CustObj obja;

obja.val =10;

vctor_var->length(1);
vctor_var[0]=obja; // this does a deep copy of the object if I remembered

return vctor_var._retn(); // this return the sequence (CustObj_Cont*) but also remove the reference return from the _var type to avoid deletion by this function.
}

Olivier Thibout?t
***@voxco.com
Voxco Montr?al | D?veloppeur logiciel principal
Brian Neal
2011-12-21 20:05:02 UTC
Permalink
Post by Rajesh Khan
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

Loading...