Message31816
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). |
|
Date |
User |
Action |
Args |
2007-08-23 14:53:10 | admin | link | issue1701409 messages |
2007-08-23 14:53:10 | admin | create | |
|