title: Return struct pointer from C to Python using ctypes - 32 bit python on 64 bit system
body: <p>I'm trying to access a C function that returns a struct pointer using ctypes. I'm using 32 bit ipython from EPD. I'm on a 64 bit CentOS machine, but I have to use 32 bit Python, because the shared lib is 32 bit. When I try to get the struct pointer, I get a segmentation fault. I don't need to access the struct fields, because I'm only using the struct as input to another C function. The code looks something like this.</p>
  
  <pre><code>from ctypes import *
  
  libfoo = CDLL("libfoo.so")
  
  func1 = libfoo.func1
  func2 = libfoo.func2
  
  func1.restype = c_void_p
  
  obj = func1() # This is where it stops with segfault
  
  func2 (data, obj)
  </code></pre>
  
  <hr>
  
  <p>C Code</p>
  
  <hr>
  
  <pre><code>typedef struct
  {
      int int1;
      int int2;
      float float1;
      float *arr;
      fftwf_plan fft;
  } mystruct;
  
  
  mystruct *func1(void)
  {
      mystruct *bar = (mystruct *) malloc (sizeof(mystruct));
  
      bar-&gt;int1 = 1;
      bar-&gt;int2 = 2;
      bar-&gt;float1 = 1.0;
      ....
  
      bar-&gt;arr = (float *) fftwf_malloc (sizeof(float) * (FFT_LEN + 2));
      bar-&gt;fft = fftwf_plan_dft_r2c_1d (FFT_LEN, ch-&gt;arr, (fftwf_complex *)ch-&gt;arr, FFTW_MEASURE);
  
      return bar;
  }
  
  void func2 (float *data, mystruct *bar)
  {
      ....
  }
  </code></pre>
  
  <p>I tried creating a ctypes struct object as well, but still got a segfault. If possible, I'd like to simply pass the pointer across to func2, without having to create a ctypes Structure. I've read several posts with similar questions, but none of them really match. </p>