Issue 7569: ctypes doc improvement: c_char_p (original) (raw)

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:55 admin set github: 51818
2009-12-29 10:34:48 georg.brandl set status: open -> closedresolution: fixedmessages: +
2009-12-28 17:23:05 pitrou set nosy: + pitroumessages: +
2009-12-28 15:19:07 nikratio set messages: +
2009-12-28 08:12:08 georg.brandl set messages: +
2009-12-25 01:37:36 ezio.melotti set priority: normalnosy: + thellerversions: - Python 2.5, 3rd party
2009-12-23 19:15:45 nikratio create