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 theller
Date 2018-02-01.19:54:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517514890.15.0.467229070634.issue32745@psf.upfronthosting.co.za>
In-reply-to
Content
ctypes Structure fields of type c_char_p or c_wchar_p used to accept strings with embedded null characters.  I noticed that Python 3.6.4 does refuse them.  It seems this has been changed in recent version(s).

There ARE use-cases for this:  The Windows-API OPENFILENAME structure is one example.  The Microsoft docs for the lpstrFilter field:

"""
lpstrFilter

    Type: LPCTSTR

    A buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.
"""

I have attached a simple script which demonstrates this new behaviour; the output with Python 3.6.4 is this:

Traceback (most recent call last):
  File "nullchars.py", line 8, in <module>
    t.unicode = u"foo\0bar"
ValueError: embedded null character
History
Date User Action Args
2018-02-01 19:54:50thellersetrecipients: + theller
2018-02-01 19:54:50thellersetmessageid: <1517514890.15.0.467229070634.issue32745@psf.upfronthosting.co.za>
2018-02-01 19:54:50thellerlinkissue32745 messages
2018-02-01 19:54:49thellercreate