[issue5149] syntactic sugar: type coercion on pointer assignment
report at bugs.python.org
Sun Aug 7 23:10:20 CEST 2011
Vlad Riscutia <riscutiavlad at gmail.com> added the comment:
The main reason for this issue is that internally ctypes doesn't consider c_char_p as a pointer type. This is a bit counter-intuitive, but c_char_p is treated as a simple type and has some other sugar built-in, like easier integration with Python strings. Alternative pointer type is POINTER(c_char), which allows assignment from array.
I would make this clear in the documentation. Even now, documentation says following about c_char_p:
Represents the C char * datatype when it points to a zero-terminated string. For a general character pointer that may also point to binary data, POINTER(c_char) must be used. The constructor accepts an integer address, or a string.
So there already is a hint that c_char_p has limited use for convenience. We should maybe make documentation more clear. If you want equivalent of C char* behavior, POINTER(c_char) is the way to go.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list