title: c struct to Python
body: <p>I have the following c code: </p>
  
  <pre><code>rx_data_t* readBuffer()
  {
      rx_data_t buffer[512];
  
      results = doSomething()
  
      rx_data_t* newBuf = malloc(results.count());
  
      for(i=0;i&lt;results.count();i++)
      {
          newBuf[i].receive_time = buffer[i].receive_time;
          newBuf[i].low = buffer[i].low;
          newBuf[i].high = buffer[i].high;
      }
  
      return newBuf;
  }
  </code></pre>
  
  <p>I am using ctypes in Python (3.4) to get the results of this function,</p>
  
  <pre><code> class BufferResults(ctypes.Structure):
      """ creates a struct to match rx_data_t
      """
  
      _fields_ = [
          ('receive_time', ctypes.c_ulong),
          ('low', ctypes.c_ushort),
          ('high', ctypes.c_ushort)
      ]
  
  self.lib.readBuffer.restype = ctypes.POINTER(BufferResults)
  
  res = self.lib.readBuffer()
  </code></pre>
  
  <p>This works and I get all the results from the c structure, however if I iterate through res there are hundreds of results rather than the one or two I'm expecting.</p>
  
  <p>Is there something I'm doing wrong or not doing?</p>
  
  <p>Thanks.</p>