New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctypes string pointer fields should accept embedded null characters #76926
Comments
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: """
""" 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 |
PyUnicode_AsWideCharString was updated to raise ValueError for embedded nulls if the
|
This is a regression. Eryk's solution LGTM. Do you mind to create a PR? But u"foo\0bar" is not terminated by two NULL characters. If this is used in real code, it contains a bug. And the getter of this field will return the string only to the first null character. More work is needed for making this more reliable. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: