Re: ctypes char array question

"Gordon L. Kindlmann" <[email protected]> Fri, 2 Dec 2011 11:54:56 -0600
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Thomas, thank you for all your work on ctypes over the years.

Gordon

On Dec 2, 2011, at 11:32 AM, Steve Thompson wrote:

> There needs to be a method of accessing that information.  I can't force developers to modify their embedded source code or hack in a work around on the python side every time I generate ctypes from the embedded C code.  That's not a good long term solution.
> 
> Any thoughts on if/when this could be added?  Is there no way to access the underlying raw data?
> 
> On Fri, Dec 2, 2011 at 11:09 AM, Thomas Heller <[email protected]> wrote:
> Am 01.12.2011 22:16, schrieb Steve Thompson:
> >      Assume:
> >          import ctypes
> >          class str_type(ctypes.Array):
> >              _type_ = ctypes.c_char
> >              _length_ = 4
> >          class struct(ctypes.Structure):
> >              _fields_ = ( ("first", str_type),
> >                           ("second", ctypes.c_int), )
> >          x = struct()
> >          x.first = "a\0bc"
> >          print "x.first:", x.first, x.second
> >
> > The output is “x.first: a 0”.Is there a way to access the part of the
> > array that’s after the null terminator like you would be able to in
> > normal C code?  I’ve inspected the type and don’t really see a way to do
> > this.  As a temporary work around I’ve changed it to an array of uint8.
> 
> Your workaround is fine.  There doesn't seem to be another way.
> 
> Thomas
> 
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure
> contains a definitive record of customers, application performance,
> security threats, fraudulent activity, and more. Splunk takes this
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> ctypes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ctypes-users
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure 
> contains a definitive record of customers, application performance, 
> security threats, fraudulent activity, and more. Splunk takes this 
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d_______________________________________________
> ctypes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ctypes-users

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d

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