You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(): don't cache the result #66519
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:
assignee=Noneclosed_at=<Date2015-10-02.21:06:09.492>created_at=<Date2014-09-01.21:32:14.109>labels= ['type-feature']
title="Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(): don't cache the result"updated_at=<Date2018-07-23.20:12:05.868>user='https://github.com/vstinner'
I would like to deprecate PyUnicode_AsUnicode(), see the issue bpo-22271 for the rationale (hint: memory footprint). The first step is to rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() to not call PyUnicode_AsUnicode() anymore.
Attached patch implements this.
The code is based on PyUnicode_AsUnicode(), but it's more tricky because PyUnicode_AsWideChar() can truncate the string, and PyUnicode_AsUnicode() does no copy characters if kind == sizeof(wchar_t), PyASCIIObject.wstr "just" points to data.
I hate PyUnicode_AsWideChar(), but we must keep it for backward compatibility :-)
It would be possible to write an optimized PyUnicode_AsWideCharString() which computes the length, allocate memory and write wide characters, but I don't want to have 3 functions converting a Python string to a wide character string. There are already PyUnicode_AsUnicodeAndSize() and unicode_aswidechar() (+ unicode_aswidechar_len()).
changed the title [-]Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString()[/-][+]Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(): don't cache the result[/+]on Oct 9, 2014
Activity
vstinner commentedon Sep 1, 2014
I would like to deprecate PyUnicode_AsUnicode(), see the issue bpo-22271 for the rationale (hint: memory footprint). The first step is to rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() to not call PyUnicode_AsUnicode() anymore.
Attached patch implements this.
The code is based on PyUnicode_AsUnicode(), but it's more tricky because PyUnicode_AsWideChar() can truncate the string, and PyUnicode_AsUnicode() does no copy characters if kind == sizeof(wchar_t), PyASCIIObject.wstr "just" points to data.
I hate PyUnicode_AsWideChar(), but we must keep it for backward compatibility :-)
It would be possible to write an optimized PyUnicode_AsWideCharString() which computes the length, allocate memory and write wide characters, but I don't want to have 3 functions converting a Python string to a wide character string. There are already PyUnicode_AsUnicodeAndSize() and unicode_aswidechar() (+ unicode_aswidechar_len()).
pitrou commentedon Sep 2, 2014
There is no patch.
vstinner commentedon Sep 2, 2014
You're right. Here it is.
pitrou commentedon Sep 6, 2014
Hmm... sorry for the delay, there's no review link. Perhaps the patch is not against the latest default?
[-]Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString()[/-][+]Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(): don't cache the result[/+]serhiy-storchaka commentedon Jul 23, 2018
Oh, I have reimplemented this in bpo-30863.