[orbitcpp-list] Strings and sequences
Status: Beta
Brought to you by:
philipd
|
From: Phil D. <ph...@us...> - 2000-04-18 17:37:12
|
Hi All,
Once again, strings are causing headaches:
CORBA 2.3 requires that strings in structs and sequences be
initialised to "". This is solved for structs by using the String_mgr
class, whose constructor allocates an empty string. However,
sequences present problems for the current implementation because we
use the ORBit C alloc functions for allocating sequences, and there is
no such 'empty string' requirement in the latest C spec.
Candidate solution:
We redefine operator new[] each time we create a sequence, which
invokes the underlying C allocation function. We then use the operator
new[] in allocbuf() instead of calling the C allocation function
direct. This should insure that the String_mgr constructor gets called
appropriately.
There is still a problem with this, since sequences and arrays have
seperate C allocation functions for variable length types, and you can
only define one operator new[] for each type in C++. I suggest we
remedy this by creating a version of String mgr for arrays and
sequence types - e.g.
struct orbitcpp_SequenceString_mgr : public String_mgr {
static void *operator new[](size_t size);
};
struct orbitcpp_ArrayString_mgr : public String_mgr {
static void *operator new[](size_t size);
};
Which allows us to create two operator new[]s.
Note that this approach must be used with any variable length type
containing a string. e.g.:
-------------- idl ----------------
struct foo {
string str;
};
typedef sequence<foo> fooseq;
-------------- c++ ----------------
struct foo {
String_mgr str;
};
struct orbitcpp_SequenceFoo : public foo {
static void *operator new[](size_t size);
}
typedef _orbitcpp::SequenceTmpl<
orbitcpp_SequenceFoo,_orbitcpp::c::CORBA_sequence_foo> fooseq;
-----------------------------------
Any comments, suggestions? Andreas - you're doing arrays; can you
forsee any problems with this approach?
Cheers,
Phil.
|