title: JNR-FFI how to read array of structs from pointer to pointer
body: <p>I am trying to interface with a C library <a href="https://github.com/hgst/libzbc" rel="nofollow noreferrer">libzbc</a> using <a href="https://github.com/jnr/jffi" rel="nofollow noreferrer">jnr-ffi</a>.</p>
  
  <p><strong>There is a function:</strong></p>
  
  <blockquote>
    <p>int zbc_list_zones    (   struct zbc_device *     dev, uint64_t   sector, enum
    zbc_reporting_options     ro, <strong>struct zbc_zone **    zones</strong>, unsigned int *
      nr_zones  )</p>
  </blockquote>
  
  <p>How can i read back the array of structures from the parameter <strong>zones</strong> ?</p>
  
  <p>Second question: is the nr_zones parameter declared correctly? The resulting integer is negative, should be positive. I tried using <strong>ShortByReference</strong> ,gives a reasonable result but i do not think that is correct.</p>
  
  <p>I tried the following to read the first element but it doesn't work (gives zero result):</p>
  
  <pre><code>PointerByReference zones=new PointerByReference();
  IntByReference nr_zones=new IntByReference();
  zbc_zone zone=new zbc_zone(runtime);
  z.zbc_list_zones(dev, 0, zbc_reporting_options.ZBC_RO_ALL, zones, nr_zones);
  zone.useMemory(zones.getValue());
  System.out.println("zone 0: "+zone.zbz_length);
  </code></pre>
  
  <p><strong>zbc_zone structure:</strong></p>
  
  <pre><code>public static class zbc_zone extends Struct 
  {
      protected zbc_zone(Runtime runtime) {
          super(runtime);
      }
      public final Unsigned64 zbz_length=new Unsigned64();
      public final Unsigned64 zbz_start=new Unsigned64();
      public final Unsigned64 zbz_write_pointer=new Unsigned64();
      public final Unsigned8 zbz_type=new Unsigned8();
      public final Unsigned8 zbz_conditions=new Unsigned8();
      public final Unsigned8 zbz_attributes=new Unsigned8();
      public final Unsigned8 zbz_pad1=new Unsigned8();
      public final Unsigned8 zbz_pad2=new Unsigned8();
      public final Unsigned8 zbz_pad3=new Unsigned8();
      public final Unsigned8 zbz_pad4=new Unsigned8();
      public final Unsigned8 zbz_pad5=new Unsigned8();
  }
  </code></pre>
  
  <p><strong>JNR interface:</strong></p>
  
  <pre><code>public int zbc_list_zones(@In Pointer dev,@In long sector,
      @In zbc_reporting_options options,@Out PointerByReference zones,
      @Out IntByReference nr_zones);
  </code></pre>