Re: Help with struct arrays

Nicholas Earl <[email protected]> Fri, 27 Sep 2013 01:14:28 -0700
Newsgroups gmane.comp.python.ctypes
Message-ID <CANjQ-UdVjbB6T+DwpmaM-Lc7BO+BWTL_xh130_V=r4uxnWo0DQ@mail.gmail.com>
Thanks Thomas, that makes sense. However using either of the two methods
returns nothing. As far as I can tell, the values are stored in the struct,
the function returns the struct to the python wrapper, but when I attempt
to 'print phin[0].times[0]', instead of the location like last time, I just
get nothing...

I'm super confused. Any guidance would be appreciated!

Nicholas Earl
Graduate Research Assistant
San Diego State University


On Thu, Sep 26, 2013 at 11:12 PM, Thomas Heller <[email protected]> wrote:

> Am 27.09.2013 06:37, schrieb Nicholas Earl:
> > Hello all! I'm having difficulties accessing the information in a
> > returned struct object. I'm quite new to C/C++, but I've had plenty of
> > experience with C#, so I think I have my foot in the door.
> >
> > I have a struct defined as
> >
> > class PhotoInfo(ctypes.Structure):
> >      _fields_ = [
> >          ('times', ctypes.POINTER(ctypes.c_double)),
> >          ('fluxes', ctypes.POINTER(ctypes.c_double)),
> >      ]
> >
> > with the restype defined like
> >
> > def main():
> >      lib = ctypes.cdll.LoadLibrary('photoroutine.so')
> >
> >      start = lib.start
> >      PhotoInfoPtr = ctypes.POINTER(PhotoInfo)
> >      start.restype = PhotoInfoPtr
> >
> > But when I call
> >
> > phin = start()
> >
> > I can't get to the time and flux info the returned object has. I've
> > tried using
> >
> > phin.contents.times
> >
> > but it just gives me a location; i.e. <__main__.LP_c_double object at
> > 0x159fef0>
> >
> > How do I get the actual array of times and fluxes?
>
> Try 'phin[0].times[0]' or 'phin.contents.times.contents'.
> The former is the preferred idiom.
>
> Thomas
>
>
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
> from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
> _______________________________________________
> ctypes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ctypes-users
>

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users