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 <rep...@bugs.python.org>
<http://bugs.python.org/issue22323>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to