ctypes issues involving a pointer to an array of strings

MRAB python at mrabarnett.plus.com
Tue Oct 20 20:08:50 CEST 2009


Nathaniel Hayes wrote:
> 
> 
> On Tue, Oct 20, 2009 at 12:12 PM, MRAB <python at mrabarnett.plus.com 
> <mailto:python at mrabarnett.plus.com>> wrote:
> 
>     The digits in that pointer value look suspiciously like the character
>     codes of a string rather than an actual address:
> 
>      >>> "\x42\x71\x61\x44"
>     'BqaD'
> 
>     It looks like the first 4 characters of a string starting 'DaqB' are
>     being used as a string pointer on a little-endian platform.
> 
> 
>         I am really at a loss here, so any insight at all would be
>         great.  Something odd though, is that when I pass just c_char_p
>         instead of an array of c_char_p, I receive the one device I have
>         installed on this computer, and it works great.  However, when I
>         make an array of just one item, I get these odd errors.
> 
> Well, the name of the device is DaqBoard2K, so thats where the DaqB is 
> coming from.  That means that the function worked, but I can seem to get 
> the information in a usable format.  I'm not well versed in C or 
> anything low level like that, so not really sure what is going behind 
> the scenes.  I have seen (c_char_p*4)() would make an iterable ctypes 
> array of 4 c_char_p variables, but it seems like the address to the 
> string has been overwritten by the string itself?
> 
What does the documentation of the C API actually say? What does the
parameter list of the C function look like?



More information about the Python-list mailing list