From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,9a36fee7fc1f6cfd X-Google-Attributes: gidf678f,public X-Google-ArrivalTime: 1993-09-23 07:46:20 PST Path: gmd.de!newsserver.jvnc.net!howland.reston.ans.net!sol.ctr.columbia.edu!news.kei.com!bloom-beacon.mit.edu!paperboy.osf.org!rsalz From: rsalz@osf.org (Rich Salz) Newsgroups: comp.unix.osf.misc Subject: Re: DCE RPC: [out] conformant arrays? Date: 23 Sep 1993 14:21:13 GMT Organization: Open Software Foundation Message-ID: <27sbcp$s3r@paperboy.osf.org> References: NNTP-Posting-Host: sulphur.osf.org In daniels@jabberwock.NeoSoft.com (Brad Daniels) writes: >typedef enum { > INT_TYPE, FLOAT_TYPE, DOUBLE_TYPE >} valType; > >typedef struct { > union switch (valType t) { > case INT_TYPE: int i; > case FLOAT_TYPE: float f; > case DOUBLE_TYPE: double d; > } valUnion; >} value; > >typedef struct { > int count; > [size_is(count)] value vals[]; >} valList; > >[idempotent] void getValues([out] valList *vals); You were *very* close. :-) You want to do this: void getValues([in, out] valList *vals); Your client code should look like this: valList x; x.count = 0; getValues(&x); for (i = 0; i < x.count) munge(x.vals[i]); rpc_ss_client_free(x.vals); Your server could should look like this: getValues(valList *xp) { int i; xp->count = get_count(); xp->vals = rpc_ss_allocate(xp->count * sizeof xp->vals[0]); for (i = 0; i < xp->count; i++) get_nth_value(i, &xp->vals[i]); } The key is that you cannot pass in a top-level conformant array. You have to wrap it in a struct, as you did. The DCE Application Development Guide says that a structure containing a conformant array must be passed by reference, must have the [in] attribute, and that the containing structure can only have one conformant array which must be the last element in the array. See "Rules for Using Arrays" (section 17.14.5.3) in Volume 1 of the guide. :In either case, how are we actually supposed to handle memory allocation? :I think we're supposed to just allocate the memory at the client end, :and pass it in to be filled up by the stub. You can do this but you'll also have to fill in dummy values or add a [length_is] attribute and variable so that the memory is allocated, but the client ships 0 elements and the server ships back the right number of elements. Or, you can do as I did above and use the rpc_ss_xxx functions. A basic rule is that if the server is going to allocate memory that will be returned to a client, it must use rpc_ss_allocate (rather then malloc). If a client wants to free memory that was allocated by a stub it should call rpc_ss_client_free (rather then free). The client should free everything that the server allocated. Hope this helps, /r$