[New-bugs-announce] [issue22323] Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString()

STINNER Victor report at bugs.python.org
Mon Sep 1 23:32:14 CEST 2014


New submission from STINNER Victor:

I would like to deprecate PyUnicode_AsUnicode(), see the issue #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()).

----------
messages: 226244
nosy: haypo, loewis
priority: normal
severity: normal
status: open
title: Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString()
type: enhancement
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22323>
_______________________________________


More information about the New-bugs-announce mailing list