title: passing arrays with ctypes
body: <p>I have a C function</p>
  
  <pre><code>void read_FIFO_AI0(int16_t** input, size_t size, NiFpga_Session* session, NiFpga_Status* status)
  {
    *input = (int16_t*) malloc (size*sizeof(int16_t));
    // function that populates the array *input
  }
  </code></pre>
  
  <p>which populates the array "*input". Now I want to pass the data in that array to python for further processing. I try to use ctypes to do that:</p>
  
  <pre><code>def read_FIFO_AI0(size,session,status):
      _libfpga.read_FIFO_AI0.argtypes = [POINTER(ARRAY(c_int16, size)), c_int, POINTER(c_uint32), POINTER(c_int32)]
      _libfpga.read_FIFO_AI0.restype = None
  
      values = (c_int16*size)()
      _libfpga.read_FIFO_AI0(byref(values),size,byref(session),byref(status))
      return values
  </code></pre>
  
  <p>The code executes but I get wrong results in the array. When I try to use the C function from within C I get proper results:</p>
  
  <pre><code>size_t size=20;
  int16_t* input;
  
  read_FIFO_AI0(&amp;input, size, &amp;session, &amp;status);
  </code></pre>
  
  <p>What would be the right way to populate the array such that I can access the data in Python? I'm not tied to using a pointer to an array that gets populated, I would also be fine with creating the array in the C function and sending this as a return to Python, but I did not get to work either.</p>