This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes doc improvement: c_char_p
Type: enhancement Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, nikratio, pitrou, theller
Priority: normal Keywords:

Created on 2009-12-23 19:15 by nikratio, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg96842 - (view) Author: Nikolaus Rath (nikratio) * Date: 2009-12-23 19:15
It would be great if the documentation of c_char_p
(http://docs.python.org/library/ctypes.html#ctypes.c_char_p) could be
reformulated as follows (would have saved me quite some time):

class ctypes.c_char_p¶
    Represents the C char * datatype when it points 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.
msg96941 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-12-28 08:12
Wouldn't a "general" pointer better be of type c_void_p?
msg96955 - (view) Author: Nikolaus Rath (nikratio) * Date: 2009-12-28 15:19
I don't want to judge if the best way to represent binary data in C is a
void* or char*, but there is a lot of C code out there that uses char*,
and if we want to interface with such a library we need to use
POINTER(c_char).

Note that my docpatch doesn't say anything about using void_p or not:
"For a general *character* pointer that may point to binary data,
POINTER(c_char) must be used". This refers only to char*, so if the C
code uses void* instead, we can of course also use c_void_p on the
Python side.
msg96960 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-28 17:23
The suggestion looks good to me.
msg96990 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-12-29 10:34
OK, applied in r77108.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51818
2009-12-29 10:34:48georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg96990
2009-12-28 17:23:05pitrousetnosy: + pitrou
messages: + msg96960
2009-12-28 15:19:07nikratiosetmessages: + msg96955
2009-12-28 08:12:08georg.brandlsetmessages: + msg96941
2009-12-25 01:37:36ezio.melottisetpriority: normal
nosy: + theller

versions: - Python 2.5, 3rd party
2009-12-23 19:15:45nikratiocreate