Discussion:
[omniORB] CORBA::Any marshalling endian problem
Steve Donovan
2007-04-17 14:04:42 UTC
Permalink
Hi guys,

Thanks to Duncan's tremendous support I've finally got a Omniorb C++
client running on my embedded Gumstix talking to a Java server. It
faultlessly handles the little-endian nature of the device, except when
I try to put stuff into a CORBA::Any. If I put a double into an Any, it
will not arrive properly.

The workaround, of course, is to pass a octet sequence containing the
double (in bigendian format) and extract that on the server, but this is
less than elegant.

Anybody hit similar problems?

steve d.
--
This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.

CSIR E-mail Legal Notice
http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html

CSIR Copyright, Terms and Conditions
http://mail.csir.co.za/CSIR_Copyright.html

For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to
***@csir.co.za.


This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean.
Sean Parker
2007-04-17 20:18:24 UTC
Permalink
Hello -

I have a question about the "proper" way to return
structs from server methods. (I end up with a memory leak,
but the data gets through fine)

For example:

<IDL code>
struct MyStruct
{
long a;
string b;
};
interface X
{
MyStruct doit();
}
<end IDL code>

Then in C++:

<C++ code>

MyStruct*
X_impl::doit()
{
MyStruct* ms = new MyStruct();
ms->a = 0;
ms->b = ::CORBA::string_dup( "hello" );
return ms;
}

<end C++ Code>


I suppose there are "preferred" ways to do this, so that's
what I'm asking, what's the preferred (or only) way to do
this w/o memory leaks? When using valgrind, I always have a
leak of both the string 'b' and the MyStruct allocation. Is
there a alloc_buf function I need to use, as in creating
sequences of structs? (I thought of always returning
sequences of size one, since I do sequences alot elsewhere
w/o leaks, but that seems klugy...)

Any help appreciated -
Thanks and God Bless

Sean

P.S. I'm using oo 4;

P.P.S. the C++ mapping doc from OMG suggestes something
like a _rtrn() function, as an example for implementations
to do things, but not sure that omniORB has such a thing...


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Carlos
2007-04-18 04:57:00 UTC
Permalink
Post by Sean Parker
Hello -
I have a question about the "proper" way to return
structs from server methods. (I end up with a memory leak,
but the data gets through fine)
<IDL code>
struct MyStruct
{
long a;
string b;
};
interface X
{
MyStruct doit();
}
<end IDL code>
<C++ code>
MyStruct*
X_impl::doit()
{
MyStruct* ms = new MyStruct();
ms->a = 0;
ms->b = ::CORBA::string_dup( "hello" );
return ms;
}
<end C++ Code>
I think this code is correct, but perhaps the memory leak is in client
side, in order to manage the return in a correct way:

X_var x_var = ....

MyStruct_var s_var = x_var->doit();

Now the return pointer is owned by s_var, so when s_var gets out of
scope the destructor properly frees the memory.

And in server side perhaps a better implementation is:

MyStruct*
X_impl::doit()
{
MyStruct_var s_var = new MyStruct();
s_var->a = 0;
s_var->b = ::CORBA::string_dup("Hello");
return s_var._retn();
}

This implementation is better because if inside the method a exception
is raised the destructor of MyStruct_var is called, so you don't get a
memory leak.

Cheers.

Carlos.
Post by Sean Parker
I suppose there are "preferred" ways to do this, so that's
what I'm asking, what's the preferred (or only) way to do
this w/o memory leaks? When using valgrind, I always have a
leak of both the string 'b' and the MyStruct allocation. Is
there a alloc_buf function I need to use, as in creating
sequences of structs? (I thought of always returning
sequences of size one, since I do sequences alot elsewhere
w/o leaks, but that seems klugy...)
Any help appreciated -
Thanks and God Bless
Sean
P.S. I'm using oo 4;
P.P.S. the C++ mapping doc from OMG suggestes something
like a _rtrn() function, as an example for implementations
to do things, but not sure that omniORB has such a thing...
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
Duncan Grisby
2007-04-19 04:04:40 UTC
Permalink
Post by Steve Donovan
Thanks to Duncan's tremendous support I've finally got a Omniorb C++
client running on my embedded Gumstix talking to a Java server. It
faultlessly handles the little-endian nature of the device, except when
I try to put stuff into a CORBA::Any. If I put a double into an Any, it
will not arrive properly.
What goes wrong with it? Do other types like long work? What about
long long? float?

What omniORB version?

What processor are you using? If it's an ARM, some of them have a
strange mixed-endian double representation. If that applies to you, does
the macro selection in include/omniORB4/CORBA_sysdep.h that sets
OMNI_MIXED_ENDIAN_DOUBLE choose the right setting?

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Steve Donovan
2007-04-19 15:59:53 UTC
Permalink
Post by Duncan Grisby
Post by Duncan Grisby
What goes wrong with it? Do other types like long work? What about
long long? float?
All of these are going across fine. I'm not moving any doubles over
directly,
so I can't tell.
Post by Duncan Grisby
Post by Duncan Grisby
What omniORB version?
4.1.0
Post by Duncan Grisby
Post by Duncan Grisby
What processor are you using?
PXA255 with Xscale, which is ARM-like (-march=armv5te).
Post by Duncan Grisby
If that applies to you, does
the macro selection in include/omniORB4/CORBA_sysdep.h that sets
OMNI_MIXED_ENDIAN_DOUBLE choose the right setting?
Ah, bingo! It was still -D__x86__ in the makefile, so
I changed this to __arm__, and rebuilt the application.

Still behaving badly. Would I have to rebuild my omniORB?

Thanks,
steve d.

PS. Why people would choose to use mixed-endian when
we already have two perfectly good standards, I don't know!
--
This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.

CSIR E-mail Legal Notice
http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html

CSIR Copyright, Terms and Conditions
http://mail.csir.co.za/CSIR_Copyright.html

For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to
***@csir.co.za.


This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean.
Thomas Lockhart
2007-04-19 18:38:37 UTC
Permalink
Post by Steve Donovan
Ah, bingo! It was still -D__x86__ in the makefile, so
I changed this to __arm__, and rebuilt the application.
Still behaving badly. Would I have to rebuild my omniORB?
Yes. And you might want to look at the byte-level result for a double to
confirm the necessary ordering. Not sure if different ARMs have
different word ordering for doubles, but they seem to have variations in
ordering for everything else... :/

- Tom
Steve Donovan
2007-04-19 19:10:41 UTC
Permalink
Post by Thomas Lockhart
Yes. And you might want to look at the byte-level result for a double to
confirm the necessary ordering.
Now that is interesting, because the hack that did work was to
assume that the doubles were standard little-endian, swop
the bytes explicitly, and send them as an octet sequence.

steve d.
--
This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.

CSIR E-mail Legal Notice
http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html

CSIR Copyright, Terms and Conditions
http://mail.csir.co.za/CSIR_Copyright.html

For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to
***@csir.co.za.


This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean.
Sean Parker
2007-04-20 21:56:17 UTC
Permalink
Thanks a ton - I'll try it

Cheers and God Bless
Sean
El mar, 17-04-2007 a las 07:18 -0700, Sean Parker
Post by Sean Parker
Hello -
I have a question about the "proper" way to return
structs from server methods. (I end up with a memory
leak,
Post by Sean Parker
but the data gets through fine)
<IDL code>
struct MyStruct
{
long a;
string b;
};
interface X
{
MyStruct doit();
}
<end IDL code>
<C++ code>
MyStruct*
X_impl::doit()
{
MyStruct* ms = new MyStruct();
ms->a = 0;
ms->b = ::CORBA::string_dup( "hello" );
return ms;
}
<end C++ Code>
I think this code is correct, but perhaps the memory leak
is in client
X_var x_var = ....
MyStruct_var s_var = x_var->doit();
Now the return pointer is owned by s_var, so when s_var
gets out of
scope the destructor properly frees the memory.
MyStruct*
X_impl::doit()
{
MyStruct_var s_var = new MyStruct();
s_var->a = 0;
s_var->b = ::CORBA::string_dup("Hello");
return s_var._retn();
}
This implementation is better because if inside the
method a exception
is raised the destructor of MyStruct_var is called, so
you don't get a
memory leak.
Cheers.
Carlos.
Post by Sean Parker
I suppose there are "preferred" ways to do this, so
that's
Post by Sean Parker
what I'm asking, what's the preferred (or only) way to
do
Post by Sean Parker
this w/o memory leaks? When using valgrind, I always
have a
Post by Sean Parker
leak of both the string 'b' and the MyStruct
allocation. Is
Post by Sean Parker
there a alloc_buf function I need to use, as in
creating
Post by Sean Parker
sequences of structs? (I thought of always returning
sequences of size one, since I do sequences alot
elsewhere
Post by Sean Parker
w/o leaks, but that seems klugy...)
Any help appreciated -
Thanks and God Bless
Sean
P.S. I'm using oo 4;
P.P.S. the C++ mapping doc from OMG suggestes something
like a _rtrn() function, as an example for
implementations
Post by Sean Parker
to do things, but not sure that omniORB has such a
thing...
Post by Sean Parker
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam
protection around
Post by Sean Parker
http://mail.yahoo.com
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
God Bless
Sean Parker




__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Loading...