-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
ctypes: remove use of legacy unicode API #12340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1293,8 +1293,6 @@ static int | |
WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored)) | ||
{ | ||
Py_ssize_t result = 0; | ||
Py_UNICODE *wstr; | ||
Py_ssize_t len; | ||
|
||
if (value == NULL) { | ||
PyErr_SetString(PyExc_TypeError, | ||
|
@@ -1309,12 +1307,14 @@ WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored | |
} else | ||
Py_INCREF(value); | ||
|
||
wstr = PyUnicode_AsUnicodeAndSize(value, &len); | ||
if (wstr == NULL) | ||
Py_ssize_t len = PyUnicode_AsWideChar(value, NULL, 0); | ||
if (len < 0) { | ||
return -1; | ||
if ((size_t)len > self->b_size/sizeof(wchar_t)) { | ||
PyErr_SetString(PyExc_ValueError, | ||
"string too long"); | ||
} | ||
// 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)) { | ||
methane marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
PyErr_SetString(PyExc_ValueError, "string too long"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"). |
||
result = -1; | ||
goto done; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.