Re: Help with struct arrays
Thomas Heller <[email protected]> Fri, 27 Sep 2013 08:12:01 +0200
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
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