PIDL/IDL question(s)

Noel Power nopower at
Fri May 9 05:32:21 MDT 2014


the following is a set of structures (simplified) expressed in c ( or
more likely pseudo-c ) that I wish to marshall. Using PIDL would be
ideal, I have tried but still I have some difficulty expressing the
structures so they would be marshalled in the correct way. Note: I don't
have control of the structures representation and cannot adjust them to
suit what is possible in idl. Note: I am pretty pidl disabled also so
any advice welcome

  struct bounds {
      uint16 nelems;
      uint16 lbound;

  struct ndim_arraytype {
      uint16 ndims;
      uint16 somefield;
      struct bounds *bounds; /* bounds[ndims] */
      string values; /* values[elems] - where elems is calculated by
summing the nelems values from each bound struct stored above */

PROBLEM A: Although I can see howto to represent the bounds array above
(simple inline array) in idl I can't see how to do that for the elements
array where the number of elements is determined at runtime from the
contents of the bounds array. Aspirationally I would like to do
something like

  typedef [public] struct {
      uint16 ndims;    
      uint16 somefield;    
      struct bounds bounds[ndims]
      string values[custom_fn(bounds, ndims)];
  } ndim_arraytype;

and indeed the generated code looks like it would do what I require,
however the custom_fn is obviously undefined and therefore wont build. I
can I guess create a new source & header file that contains the custom
function I need and build it with the generated ndr_xyz files, but is
this the correct thing to do?, am I depending on some unintentional
behaviour by using 'variant elements[custom_fn(bounds, ndims)];'? or
indeed is there a better way to do this ?

I'll try to explain my next problem with more c  pseudo code

  #define TYPE1 = 0x0001; /* e.g. fixed size type uint16 */
  #define TYPE2 = 0x0002; /* e.g  fixed size type uint32 *.
  #define TYPE3 = 0x0003; /* e.g. variable size string */
    ""     ""        ""
  #define VECTOR = 0x4000;
  #define ARRAY  = 0x7000;

  struct ndim_variant_arraytype {
      uint16 elems;
      uint16 somefield1;
      uint32 somefield1;
      void *values; /* values[elems] */

  struct variant_vector {
      uint16 elems;
      uint32 somefield;
      void *value; /* value[elems] */

  struct variant {
      uint16 type; /* to represent fields of fixed or dynamic sizes */
      void *value; /* type value or vector or array of value ( where
value is one of uint16, uint32, string or .... type )

PROBLEM B: I don't see how to 'switch' the elements type in the
variant_vector or ndim_variant_arraytype struct above as no field of the
struct expresses the type, the type is expressed in the parent struct
variant field 'type' above. Is it possible even ? Of course I could do
something like ....

  typedef [public] struct {
      uint16 ndims;    
      uint16 other_field;    
      struct bounds bounds[ndims]
      uint32 vdata[custom_fn(bounds,ndims)];
  } ndim_uint32_arraytype;

  typedef [public] struct {
      uint16 ndims;    
      uint16 other_field;    
      struct bounds bounds[ndims]
      uint16 vdata[custom_fn(bounds,ndims)];
  } ndim_uint16_arraytype;

  typdef [public] struct {
      uint16 elems;
      uint32 somefield;
      uint32 values[elems];
  } variant_vector_uin32;

  typedef [public,nodiscriminant,switch_type(uint16)] union {
      [case(TYPE1)] uint32 i4;
      [case(TYPE2)] uint16 i2;

      /* and others */

      [case(TYPE1 | ARRAY)]  struct ndim_uint32_arraytype uint32_array;
      [case(TYPE1 | VECTOR)] struct variant_vector_uint32 uint32_vector;
  } types;

  typedef [public] struct {
      uint16 type;
      [switch_is(type)] types value;
  } variant;

but I'm duplicating alot here and wish to avoid that, any ideas ??



More information about the samba-technical mailing list