[omniORB] Problem inserting an array of structs containing strings
into an any
Brian Neal
bgneal at gmail.com
Thu Jan 5 14:46:45 GMT 2006
Hello,
I am using omniORB 4.0.6 under both cygwin and linux, and I'm seeing
the same problem.
I have the following IDL in a file called test.idl:
module Test
{
struct TestStruct
{
long a;
string b;
};
typedef TestStruct TestStructArray[4];
};
And I have the following C++ code in a file called main.cpp:
#include <iostream>
#include <ostream>
#include <iterator>
#include <algorithm>
#include <sstream>
#include <CORBA.h>
#include "test.h"
namespace Test
{
std::ostream& operator<<(std::ostream& os, const Test::TestStruct& ts)
{
os << "a = " << ts.a << "; b = '" << ts.b << '\'' << std::flush;
return os;
}
}
int main()
{
const int numElems = 4;
Test::TestStructArray array;
for (int i = 0; i < numElems; ++i)
{
array[i].a = i;
array[i].b = "test";
}
std::copy(array, array + numElems,
std::ostream_iterator<Test::TestStruct>(std::cout, "\n"));
CORBA::Any a;
std::cout << "Inserting into any..." << std::endl;
a <<= Test::TestStructArray_forany(array); // ****segfault right here
std::cout << "Now extracting..." << std::endl;
Test::TestStructArray_forany fa;
if (a >>= fa)
{
std::cout << "Extraction succeeded; contents = " << std::endl;
std::copy(&fa[0UL], &fa[0UL] + numElems,
std::ostream_iterator<Test::TestStruct>(std::cout, "\n"));
}
return 0;
}
I get a segfault when I insert the forany into the any at the line marked ****
I build and run the program as follows:
$ omniidl -bcxx -Wbh=.h -Wba -Wbs=.cpp -Wbd=.cpp test.idl
bgneal1 at CRP02082 ~/forany
$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o main.o -c -Wall -W -g -I/usr/local/include/omniORB4 main.cpp
g++ -o test.o -c -Wall -W -g -I/usr/local/include/omniORB4 test.cpp
test.cpp:96: warning: unused parameter '_desc'
test.cpp:155: warning: unused parameter '_contiguous'
g++ -o test.exe -Wl,--enable-auto-import test.o main.o
-L/usr/local/lib -Wl,--start-group -lomniORB4
-lomniDynamic4 -lomnithread -lCOS4 -Wl,--end-group
scons: done building targets.
bgneal1 at CRP02082 ~/forany
$ ./test.exe
a = 0; b = 'test'
a = 1; b = 'test'
a = 2; b = 'test'
a = 3; b = 'test'
Inserting into any...
Segmentation fault (core dumped)
I have changed the struct member b from a string to a long, an any,
and a sequence of longs, and when I do, I don't get a seqfault.
I am using g++ version 3.4.4 under cygwin.
Any ideas? Thanks.
Brian Neal
PS
(Note also that I had to use 0UL when I index into the forany fa. I
get a weird compiler error about ISO C++ thinking the operator[] is
ambiguous if I index with just a plain int 0. I think this is because
there are two sets of operator[] for the forany.)
More information about the omniORB-list
mailing list