[Vortex] xml-rpc-gen and code generation containing an array of structs

Francis Brosnan Blazquez francis at aspl.es
Fri Mar 16 08:51:57 CET 2007


> Hi there,

Hi Vicent,

> Yep, that worked fine, cheers for that.

Nice,

> I did have one minor problem though, In my client code from yesterday i
> was testing if the array position made a difference of where i was
> placing my structs.  So i had ended up with the following:
> 
>         EventToken      *ev_tok1 = NULL;
>         EventToken      *ev_tok2 = NULL;
>         EventTokenArray *ev_arr = NULL;
> 
>         ev_tok1 = ar_eventtoken_new( "TOKEN=1", "VALUE=1111111111" );
>         ev_tok2 = ar_eventtoken_new( "TOKEN=2", "VALUE=2222222222" );
>         ev_arr = ar_eventtokenarray_new( 2 );
> 
>         ar_eventtokenarray_set( ev_arr, 1, ev_tok1 );
>         ar_eventtokenarray_set( ev_arr, 2, ev_tok2 );
> 
> 
> When this was run against the server it failed.
> 
> When i changed that above code to:
> 
>         ar_eventtokenarray_set( ev_arr, 0, ev_tok1 );
>         ar_eventtokenarray_set( ev_arr, 1, ev_tok2 );
> 
> It Worked fine.

That's right, array positions are handled from 0 up to n-1 as you have
observed.

> I thought ( and i havent checked the code yet ) that be specifying
> ar_eventtokenarray_new( 2 ), that it'd fail if i tried to:
> 
> a) place more than two elements in the array
> b) went past the end of the array boundaries.
> 
> But the client code appears to have accepted the former without failing.

Not really. If some position were not filled, then the marshalling code
will fail, making to also fail the vortex_xml_rpc_array_add call done
at: ar_array_eventtokenarray_xml_rpc.c:47

> Should this be expected?

Let me clarify that declaring an array with 2 elements you are asserting
that your variable will hold some amount between 0 up (2 - 1). Then the
marshalling code will detect that positions that were filled to only
send those ones.

This also exposes a problem that must be taken into consideration. If an
array have "empty" elements (following your example filling the [1]
position but [0]), the marshalling code will place a warning once found
the [0] empty slot but, still will marshall the array with only one
element (the one found at [1]), placed in the marshalled array at the
[0].

This is a problem because the client side have sent data at a particular
position ([1]) which is received at the server side at a different
position ([0]).

So, the conclusion could be: "avoid leaving empty array cell preceding
filled ones".

> BTW, and on a totally different note, would you like some help tidying
> up the english translations on the code/web site?  There's quite a lot
> of room for improvement.
> Should this be expected?

Sure Vicent, any help is appreciated.

Nice day Vicent!

> Cheers,
> -vince

-- 
Francis Brosnan Blazquez <francis at aspl.es>
Advanced Software Production Line, S.L.




More information about the Vortex mailing list