Eryk Sun added the comment:

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

----------
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python, eryksun
versions: +Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28698>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to