Message205045
create_unicode_buffer() fails on Windows if the initializer string contains unicode code points outside of the Basic Multilingual Plane and an explicit length is not specified.
The problem appears to be rooted in the fact that, since PEP 393, len() returns the number of code points, which does not always correspond to the number of 16-bit wchar words needed for the encoding on Windows. Because of that, the preallocated c_wchar buffer will be too short for the UTF-16 string.
The following small snippet demonstrates the problem:
from ctypes import create_unicode_buffer
b = create_unicode_buffer("\U00028318\U00028319")
print(b)
File "c:\Python33\lib\ctypes\__init__.py", line 294, in create_unicode_buffer
buf.value = init
ValueError: string too long |
|
Date |
User |
Action |
Args |
2013-12-02 19:36:46 | gergely.erdelyi | set | recipients:
+ gergely.erdelyi |
2013-12-02 19:36:46 | gergely.erdelyi | set | messageid: <1386013006.0.0.412572088185.issue19865@psf.upfronthosting.co.za> |
2013-12-02 19:36:45 | gergely.erdelyi | link | issue19865 messages |
2013-12-02 19:36:45 | gergely.erdelyi | create | |
|