ctypes: remove use of legacy unicode API by methane · Pull Request #12340 · python/cpython

Conversation

@methane

PyUnicode_AsUnicodeAndSize() -> PyUnicode_AsWideChar()

PyUnicode_AsUnicodeAndSize() -> PyUnicode_AsWideChar()

auvipy

brettcannon

// PyUnicode_AsWideChar() returns number of wchars including trailing NUL,
// when it is called with NULL.
if ((size_t)len-1 > self->b_size/sizeof(wchar_t)) {
PyErr_SetString(PyExc_ValueError, "string too long");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth providing in the exception message the provided length and what the max length actually is?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe yes. But this file has similar codes which are not relating to wchar_t APIs. ("bytes string too long").
I want to keep this pull request simple.

Co-Authored-By: methane <songofacandy@gmail.com>

@methane methane deleted the ctypes-legacy-api branch

April 19, 2019 07:07

Labels