mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Use PyUnicode_AsUnicodeAndSize() instead of PyUnicode_GET_SIZE()
This commit is contained in:
parent
e459a0877e
commit
beac78bb24
3 changed files with 15 additions and 9 deletions
|
@ -2529,10 +2529,9 @@ posix_listdir(PyObject *self, PyObject *args)
|
||||||
po_wchars = L".";
|
po_wchars = L".";
|
||||||
len = 1;
|
len = 1;
|
||||||
} else {
|
} else {
|
||||||
po_wchars = PyUnicode_AsUnicode(po);
|
po_wchars = PyUnicode_AsUnicodeAndSize(po, &len);
|
||||||
if (po_wchars == NULL)
|
if (po_wchars == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
len = PyUnicode_GET_SIZE(po);
|
|
||||||
}
|
}
|
||||||
/* Overallocate for \\*.*\0 */
|
/* Overallocate for \\*.*\0 */
|
||||||
wnamebuf = malloc((len + 5) * sizeof(wchar_t));
|
wnamebuf = malloc((len + 5) * sizeof(wchar_t));
|
||||||
|
|
|
@ -982,10 +982,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
STORE_SIZE(0);
|
STORE_SIZE(0);
|
||||||
}
|
}
|
||||||
else if (PyUnicode_Check(arg)) {
|
else if (PyUnicode_Check(arg)) {
|
||||||
*p = PyUnicode_AS_UNICODE(arg);
|
Py_ssize_t len;
|
||||||
|
*p = PyUnicode_AsUnicodeAndSize(arg, &len);
|
||||||
if (*p == NULL)
|
if (*p == NULL)
|
||||||
RETURN_ERR_OCCURRED;
|
RETURN_ERR_OCCURRED;
|
||||||
STORE_SIZE(PyUnicode_GET_SIZE(arg));
|
STORE_SIZE(len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return converterr("str or None", arg, msgbuf, bufsize);
|
return converterr("str or None", arg, msgbuf, bufsize);
|
||||||
|
@ -995,10 +996,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
if (c == 'Z' && arg == Py_None)
|
if (c == 'Z' && arg == Py_None)
|
||||||
*p = NULL;
|
*p = NULL;
|
||||||
else if (PyUnicode_Check(arg)) {
|
else if (PyUnicode_Check(arg)) {
|
||||||
*p = PyUnicode_AS_UNICODE(arg);
|
Py_ssize_t len;
|
||||||
|
*p = PyUnicode_AsUnicodeAndSize(arg, &len);
|
||||||
if (*p == NULL)
|
if (*p == NULL)
|
||||||
RETURN_ERR_OCCURRED;
|
RETURN_ERR_OCCURRED;
|
||||||
if (Py_UNICODE_strlen(*p) != PyUnicode_GET_SIZE(arg))
|
if (Py_UNICODE_strlen(*p) != len)
|
||||||
return converterr(
|
return converterr(
|
||||||
"str without null character or None",
|
"str without null character or None",
|
||||||
arg, msgbuf, bufsize);
|
arg, msgbuf, bufsize);
|
||||||
|
|
|
@ -2282,6 +2282,8 @@ case_ok(PyObject *filename, Py_ssize_t prefix_delta, PyObject *name)
|
||||||
WIN32_FIND_DATAW data;
|
WIN32_FIND_DATAW data;
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
int cmp;
|
int cmp;
|
||||||
|
wchar_t *wname;
|
||||||
|
Py_ssizet wname_len;
|
||||||
|
|
||||||
if (Py_GETENV("PYTHONCASEOK") != NULL)
|
if (Py_GETENV("PYTHONCASEOK") != NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -2294,9 +2296,12 @@ case_ok(PyObject *filename, Py_ssize_t prefix_delta, PyObject *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
FindClose(h);
|
FindClose(h);
|
||||||
cmp = wcsncmp(data.cFileName,
|
|
||||||
PyUnicode_AS_UNICODE(name),
|
wname = PyUnicode_AsUnicodeAndSize(name, &wname_len);
|
||||||
PyUnicode_GET_SIZE(name));
|
if (wname == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
cmp = wcsncmp(data.cFileName, wname, wname_len);
|
||||||
return cmp == 0;
|
return cmp == 0;
|
||||||
#elif defined(USE_CASE_OK_BYTES)
|
#elif defined(USE_CASE_OK_BYTES)
|
||||||
int match;
|
int match;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue