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.

Author theller
Recipients
Date 2007-04-18.19:20:26
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
This is a difficult issue.  The integer (which is interpreted as address) is allowed because some libraries use 'char *' pointers initialized to small, invalid addresses for special purposes.

On windows, printing a c_char_p(42) does not crash, it raises a ValueError instead:
>>> from ctypes import *
>>> c_char_p(42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid string pointer 0x00B20B48
>>>

Windows does this by checking if there is a valid string at the address (see Modules/_ctypes/cfield.c, line 1366) by calling the IsBadStringPointer api function.  Do other platforms have a function that can do this check?

If not, I'm afraid we would have to give up on the very convenient repr of 'normal' c_char_p instances:

>>> c_char_p("foo bar")
c_char_p('foo bar')
>>>

and only print the address (at least on non-windows).
History
Date User Action Args
2007-08-23 14:53:10adminlinkissue1701409 messages
2007-08-23 14:53:10admincreate