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 gergely.erdelyi
Recipients gergely.erdelyi
Date 2013-12-02.19:36:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1386013006.0.0.412572088185.issue19865@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2013-12-02 19:36:46gergely.erdelyisetrecipients: + gergely.erdelyi
2013-12-02 19:36:46gergely.erdelyisetmessageid: <1386013006.0.0.412572088185.issue19865@psf.upfronthosting.co.za>
2013-12-02 19:36:45gergely.erdelyilinkissue19865 messages
2013-12-02 19:36:45gergely.erdelyicreate