Message280875
The repr can't automatically dereference the string at the address because it may be an invalid pointer. ctypes was developed on Windows, for which, in Python 2, it (ab)uses the obsolete IsBadStringPtr[A|W] function [1]. This function should never be used in a multithreaded process.
On POSIX systems, the repr of c_char_p was special-cased to avoid dereferencing the pointer, but c_wchar_p was overlooked, and you can still easily crash Python 2 like this:
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.c_wchar_p(1)
Segmentation fault (core dumped
A while back the bogus use of WinAPI IsBadStringPtr was removed from the Python 3 branch, but apparently the docs weren't updated to reflect this change. I'm changing this to a documentation issue.
[1]: https://msdn.microsoft.com/en-us/library/aa366714 |
|
Date |
User |
Action |
Args |
2016-11-15 18:53:12 | eryksun | set | recipients:
+ eryksun, docs@python, Alex Wang |
2016-11-15 18:53:12 | eryksun | set | messageid: <1479235992.16.0.561556781345.issue28698@psf.upfronthosting.co.za> |
2016-11-15 18:53:12 | eryksun | link | issue28698 messages |
2016-11-15 18:53:11 | eryksun | create | |
|