mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Let PyUnicode_FromWideChar calculate the input length (GH-134045)
This commit is contained in:
parent
1c4b34c6cb
commit
74c4e35ff1
6 changed files with 11 additions and 11 deletions
|
@ -1389,7 +1389,7 @@ static PyObject *format_error(PyObject *self, PyObject *args)
|
||||||
code = GetLastError();
|
code = GetLastError();
|
||||||
lpMsgBuf = FormatError(code);
|
lpMsgBuf = FormatError(code);
|
||||||
if (lpMsgBuf) {
|
if (lpMsgBuf) {
|
||||||
result = PyUnicode_FromWideChar(lpMsgBuf, wcslen(lpMsgBuf));
|
result = PyUnicode_FromWideChar(lpMsgBuf, -1);
|
||||||
LocalFree(lpMsgBuf);
|
LocalFree(lpMsgBuf);
|
||||||
} else {
|
} else {
|
||||||
result = PyUnicode_FromString("<no description>");
|
result = PyUnicode_FromString("<no description>");
|
||||||
|
|
|
@ -1253,7 +1253,7 @@ Z_get(void *ptr, Py_ssize_t size)
|
||||||
wchar_t *p;
|
wchar_t *p;
|
||||||
p = *(wchar_t **)ptr;
|
p = *(wchar_t **)ptr;
|
||||||
if (p) {
|
if (p) {
|
||||||
return PyUnicode_FromWideChar(p, wcslen(p));
|
return PyUnicode_FromWideChar(p, -1);
|
||||||
} else {
|
} else {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1633,7 +1633,7 @@ _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle)
|
||||||
if (! result)
|
if (! result)
|
||||||
return PyErr_SetFromWindowsErr(GetLastError());
|
return PyErr_SetFromWindowsErr(GetLastError());
|
||||||
|
|
||||||
return PyUnicode_FromWideChar(filename, wcslen(filename));
|
return PyUnicode_FromWideChar(filename, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
|
#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
|
||||||
|
|
|
@ -128,7 +128,7 @@ pymain_get_importer(const wchar_t *filename, PyObject **importer_p, int *exitcod
|
||||||
{
|
{
|
||||||
PyObject *sys_path0 = NULL, *importer;
|
PyObject *sys_path0 = NULL, *importer;
|
||||||
|
|
||||||
sys_path0 = PyUnicode_FromWideChar(filename, wcslen(filename));
|
sys_path0 = PyUnicode_FromWideChar(filename, -1);
|
||||||
if (sys_path0 == NULL) {
|
if (sys_path0 == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ pymain_run_module(const wchar_t *modname, int set_argv0)
|
||||||
fprintf(stderr, "Could not import runpy._run_module_as_main\n");
|
fprintf(stderr, "Could not import runpy._run_module_as_main\n");
|
||||||
return pymain_exit_err_print();
|
return pymain_exit_err_print();
|
||||||
}
|
}
|
||||||
module = PyUnicode_FromWideChar(modname, wcslen(modname));
|
module = PyUnicode_FromWideChar(modname, -1);
|
||||||
if (module == NULL) {
|
if (module == NULL) {
|
||||||
fprintf(stderr, "Could not convert module name to unicode\n");
|
fprintf(stderr, "Could not convert module name to unicode\n");
|
||||||
Py_DECREF(runmodule);
|
Py_DECREF(runmodule);
|
||||||
|
@ -439,7 +439,7 @@ pymain_run_startup(PyConfig *config, int *exitcode)
|
||||||
if (env == NULL || env[0] == L'\0') {
|
if (env == NULL || env[0] == L'\0') {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
startup = PyUnicode_FromWideChar(env, wcslen(env));
|
startup = PyUnicode_FromWideChar(env, -1);
|
||||||
if (startup == NULL) {
|
if (startup == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1782,7 +1782,7 @@ convertenviron(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
v = PyUnicode_FromWideChar(p+1, wcslen(p+1));
|
v = PyUnicode_FromWideChar(p+1, -1);
|
||||||
#else
|
#else
|
||||||
v = PyBytes_FromStringAndSize(p+1, strlen(p+1));
|
v = PyBytes_FromStringAndSize(p+1, strlen(p+1));
|
||||||
#endif
|
#endif
|
||||||
|
@ -5052,7 +5052,7 @@ os__getfullpathname_impl(PyObject *module, path_t *path)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *str = PyUnicode_FromWideChar(abspath, wcslen(abspath));
|
PyObject *str = PyUnicode_FromWideChar(abspath, -1);
|
||||||
PyMem_RawFree(abspath);
|
PyMem_RawFree(abspath);
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -5168,7 +5168,7 @@ os__findfirstfile_impl(PyObject *module, path_t *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
wRealFileName = wFileData.cFileName;
|
wRealFileName = wFileData.cFileName;
|
||||||
result = PyUnicode_FromWideChar(wRealFileName, wcslen(wRealFileName));
|
result = PyUnicode_FromWideChar(wRealFileName, -1);
|
||||||
FindClose(hFindFile);
|
FindClose(hFindFile);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -5212,7 +5212,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path)
|
||||||
result = win32_error_object("_getvolumepathname", path->object);
|
result = win32_error_object("_getvolumepathname", path->object);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
result = PyUnicode_FromWideChar(mountpath, wcslen(mountpath));
|
result = PyUnicode_FromWideChar(mountpath, -1);
|
||||||
if (PyBytes_Check(path->object))
|
if (PyBytes_Check(path->object))
|
||||||
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
||||||
|
|
||||||
|
|
|
@ -1290,7 +1290,7 @@ winreg_ExpandEnvironmentStrings_impl(PyObject *module, const wchar_t *string)
|
||||||
return PyErr_SetFromWindowsErrWithFunction(retValueSize,
|
return PyErr_SetFromWindowsErrWithFunction(retValueSize,
|
||||||
"ExpandEnvironmentStrings");
|
"ExpandEnvironmentStrings");
|
||||||
}
|
}
|
||||||
o = PyUnicode_FromWideChar(retValue, wcslen(retValue));
|
o = PyUnicode_FromWideChar(retValue, -1);
|
||||||
PyMem_Free(retValue);
|
PyMem_Free(retValue);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue