Sequences

Arne Christensen arc@pine.dk
Fri, 10 Oct 1997 15:32:19 +0200 (MET DST)


Jörg Narr writes:
> Hi experts,

Even though you do not address me, I'll give it try :-)

> since nobody has any problems out there I hope you are happy to see
> that at least I have a problem:

I'm much too happy about my own problems already..

> I use the following IDL-Code:
> 
> interface CORBAMSG_ValueDef 
> {
>    struct attributes 
> 	{
> 	   string slotname;
>       long flag;
> 	   string value;
> 		string state; 
> 	};
> 
> 	typedef sequence <attributes> attributes_seq;
> 
> 	oneway void update (in attributes_seq as);
> };
> 
> 
> And the following code for initializing and sending the Message:
> 
> CORBAMSG_ValueDef::attributes_seq_var asv;            // in a
> Header-File Class CorbaWrapper
> asv = new CORBAMSG_ValueDef::attributes_seq;          // in the
> Constructur of the C++-File of CorbaWrapper (I have also tried the
> max-len
>                                                       // constructor,
> but it doesn't work, too.)
> 
> asv->length(5);                                       // In a method
> "eingabe" that is input of CorbaWrapper
> 	
> asv[0].slotname  = (const char*) "Slotname";          // I have even
> tried CORBA::string_dup("Slotname");
> asv[0].flag      = 120L;
> asv[0].value     = (const char*) "Value";
> asv[0].state     = (const char*) "State";
> 
> 
> I got a valid Object-Reference, at least CORBA::is_nil(ref) gives back
> true.

You mean false, I assume? It ain't nil, is it?

> As soon as I use ref->update(asv) though I get a segmentation fault -
> core dump.
> 
> This only happens when asv->length isn't set to 1. As long as it is set
> to 1 it works fine.
> 
> I would appreciate any help since I am getting crazy about this.

Oh, we can't risk that! Just a dumb question, but you do initialize
the remaining 4 elements of the sequence, don't you? I mean, the

	asv->length(5);

sets the _current_ length of the sequence to 5 (not the allocated
length). If you initialize only the first element, you have four
uninitialized elements which you try to pass in the invocation.
Well, they should initialize themselves to empty strings and the like,
but if there's a bug somewhere it might be triggered by uninitialized
elements. At least that explanation is consistent with the behaviour in
the case where the length is set to 1.

-- Arne