Chose a name for a "get unicode as wide character, borrowed reference" function
Hi, With the PEP 393, the Py_UNICODE is now deprecated and scheduled for removal in Python 4. PyUnicode_AsUnicode() and PyUnicode_AsUnicodeAndSize() functions are still commonly used on Windows to get the string as wchar_t* without having to care of freeing the memory: it's a borrowed reference (pointer). I would like to add a new PyUnicode_AsWideChar() function which would return the borrowed reference, exactly as PyUnicode_AsUnicode(). The problem is that "PyUnicode_AsWideChar" already exists in Python 3.2, as PyUnicode_AsWideCharString. Do you have an suggestion for a name of such function? PyUnicode_AsWideCharBorrowed? PyUnicode_AsFastWideChar? PyUnicode_ToWideChar? PyUnicode_AsWchar_t? Victor
On Mon, 21 Nov 2011 12:53:17 +0100 Victor Stinner <victor.stinner@haypocalc.com> wrote:
I would like to add a new PyUnicode_AsWideChar() function which would return the borrowed reference, exactly as PyUnicode_AsUnicode(). The problem is that "PyUnicode_AsWideChar" already exists in Python 3.2, as PyUnicode_AsWideCharString.
This is not very clear. You are proposing to add a function which already exists, except that you have to free the pointer yourself? I don't think that's a good idea, the API is already large enough. Regards Antoine.
Le Lundi 21 Novembre 2011 16:04:06 Antoine Pitrou a écrit :
On Mon, 21 Nov 2011 12:53:17 +0100
Victor Stinner <victor.stinner@haypocalc.com> wrote:
I would like to add a new PyUnicode_AsWideChar() function which would return the borrowed reference, exactly as PyUnicode_AsUnicode(). The problem is that "PyUnicode_AsWideChar" already exists in Python 3.2, as PyUnicode_AsWideCharString.
This is not very clear. You are proposing to add a function which already exists, except that you have to free the pointer yourself? I don't think that's a good idea, the API is already large enough.
I want to rename PyUnicode_AsUnicode() and change its result type (Py_UNICODE* => wchar_t*). The result will be a "borrowed reference", ie. you don't have to free the memory, it will be done when the Unicode string will be destroyed (by Py_DECREF). The problem is that Py_UNICODE type is now deprecated. Victor
On Mon, 21 Nov 2011 16:53:10 +0100 Victor Stinner <victor.stinner@haypocalc.com> wrote:
Le Lundi 21 Novembre 2011 16:04:06 Antoine Pitrou a écrit :
On Mon, 21 Nov 2011 12:53:17 +0100
Victor Stinner <victor.stinner@haypocalc.com> wrote:
I would like to add a new PyUnicode_AsWideChar() function which would return the borrowed reference, exactly as PyUnicode_AsUnicode(). The problem is that "PyUnicode_AsWideChar" already exists in Python 3.2, as PyUnicode_AsWideCharString.
This is not very clear. You are proposing to add a function which already exists, except that you have to free the pointer yourself? I don't think that's a good idea, the API is already large enough.
I want to rename PyUnicode_AsUnicode() and change its result type (Py_UNICODE* => wchar_t*). The result will be a "borrowed reference", ie. you don't have to free the memory, it will be done when the Unicode string will be destroyed (by Py_DECREF).
But this is almost the same as PyUnicode_AsWideCharString, right?
Le Lundi 21 Novembre 2011 16:55:05 Antoine Pitrou a écrit :
I want to rename PyUnicode_AsUnicode() and change its result type (Py_UNICODE* => wchar_t*). The result will be a "borrowed reference", ie. you don't have to free the memory, it will be done when the Unicode string will be destroyed (by Py_DECREF).
But this is almost the same as PyUnicode_AsWideCharString, right?
You have to free the memory for PyUnicode_AsWideCharString(). With PyUnicode_AsWideCharXXX(), as PyUnicode_AsUnicode(), you don't have to. The memory is handled by the Unicode object. Victor
On Mon, 21 Nov 2011 18:02:36 +0100 Victor Stinner <victor.stinner@haypocalc.com> wrote:
Le Lundi 21 Novembre 2011 16:55:05 Antoine Pitrou a écrit :
I want to rename PyUnicode_AsUnicode() and change its result type (Py_UNICODE* => wchar_t*). The result will be a "borrowed reference", ie. you don't have to free the memory, it will be done when the Unicode string will be destroyed (by Py_DECREF).
But this is almost the same as PyUnicode_AsWideCharString, right?
You have to free the memory for PyUnicode_AsWideCharString().
That's why I said "almost". I don't think it's a good idea to add this function, for two reasons: - the unicode API is already big enough, we don't need redundant functions with differing refcount behaviours - the internal wchar_t representation is certainly meant to disappear in the long term; adding an API which *relies* on that representation is silly, especially after we deliberately deprecated the Py_UNICODE APIs Regards Antoine.
participants (2)
-
Antoine Pitrou
-
Victor Stinner