[omniORB] Resizing a string sequence

Johan Cronje jcronje at dsp.sun.ac.za
Mon Nov 24 17:40:21 GMT 2003


Hi all

I would like to know something about resizing string sequences.
In my idl file I have the following:

typedef string attributes;
typedef sequence<attributes> attribute_list;

And in my application I have:

protected:
  attribute_list component_attr;
// this is a global variable, as it is returned by following function

  attribute_list* return_attributes()
  {
     ...
     component_attr.length(number_of_attributes);
     for (int i = 0; i < number_of_attributes; i++){
        component_attr[i] = CORBA::string_dup(string_obtained_from_fn);
     }
     ...
  }

The idea of return_attributes() is to return a given component's attributes,
which is a dynamic quantity depending on the component. In assigning values
to the sequence, I take care to use CORBA::string_dup to make deep copies of
the strings.

However, if the current component has less attributes than the pervious one,
I get a segfault in free(*s) in stringtypes.h:129. If the current component
has more attributes than the previous one, I get a segfault in copybuffer() in
stringtypes.h:797: newdata[i] = pd_data[i];

In both cases the function works correctly the first time it is called, and in
both cases it is the call to length() that causes the segfault.

From playing around with gdb I make the assumption that in the latter case
pd_data has left the building; it gives me a "cannot access memory at address
0x0" error if I try to print any value from it. The same goes for *s in the
former case.

As I understand it, there are two variants of length: one that returns the 
length of the sequence (if length is called without arguments) and another
that you must use to resize the sequence. A quick glance through stringtypes.h
showed me that this is indeed the case. Now, my question is: what am I doing
wrong? I use CORBA::string_dup to copy the strings into the sequence, and 
before I do that I use length(n) to resize the sequence to a proper length.
I have tried to use a temporary sequence that I assign to my global one, but
it gives the same results.

Any ideas?

Thank you

Johan

-- 
"There is beauty in simplicity"		-- Johan Cronje
---------------------------------------------------------------
Johan Cronje
Digital Signal Processing / Telecommunications Group
Electrical and Electronic Engineering Department
University of Stellenbosch
http://www.dsp.sun.ac.za/~jcronje
---------------------------------------------------------------
GNUPG Key: http://www.dsp.sun.ac.za/~jcronje/jcronje.asc




More information about the omniORB-list mailing list