mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
bpo-36775: _PyCoreConfig only uses wchar_t* (GH-13062)
_PyCoreConfig: Change filesystem_encoding, filesystem_errors, stdio_encoding and stdio_errors fields type from char* to wchar_t*. Changes: * PyInterpreterState: replace fscodec_initialized (int) with fs_codec structure. * Add get_error_handler_wide() and unicode_encode_utf8() helper functions. * Add error_handler parameter to unicode_encode_locale() and unicode_decode_locale(). * Remove _PyCoreConfig_SetString(). * Rename _PyCoreConfig_SetWideString() to _PyCoreConfig_SetString(). * Rename _PyCoreConfig_SetWideStringFromString() to _PyCoreConfig_DecodeLocale().
This commit is contained in:
parent
6ae2bbbdfc
commit
709d23dee6
11 changed files with 357 additions and 220 deletions
|
@ -424,7 +424,7 @@ sys_getfilesystemencoding_impl(PyObject *module)
|
|||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
|
||||
const _PyCoreConfig *config = &interp->core_config;
|
||||
return PyUnicode_FromString(config->filesystem_encoding);
|
||||
return PyUnicode_FromWideChar(config->filesystem_encoding, -1);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
@ -439,7 +439,7 @@ sys_getfilesystemencodeerrors_impl(PyObject *module)
|
|||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
|
||||
const _PyCoreConfig *config = &interp->core_config;
|
||||
return PyUnicode_FromString(config->filesystem_errors);
|
||||
return PyUnicode_FromWideChar(config->filesystem_errors, -1);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
@ -1211,30 +1211,9 @@ static PyObject *
|
|||
sys__enablelegacywindowsfsencoding_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=f5c3855b45e24fe9 input=2bfa931a20704492]*/
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
|
||||
_PyCoreConfig *config = &interp->core_config;
|
||||
|
||||
/* Set the filesystem encoding to mbcs/replace (PEP 529) */
|
||||
char *encoding = _PyMem_RawStrdup("mbcs");
|
||||
char *errors = _PyMem_RawStrdup("replace");
|
||||
if (encoding == NULL || errors == NULL) {
|
||||
PyMem_Free(encoding);
|
||||
PyMem_Free(errors);
|
||||
PyErr_NoMemory();
|
||||
if (_PyUnicode_EnableLegacyWindowsFSEncoding() < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyMem_RawFree(config->filesystem_encoding);
|
||||
config->filesystem_encoding = encoding;
|
||||
PyMem_RawFree(config->filesystem_errors);
|
||||
config->filesystem_errors = errors;
|
||||
|
||||
if (_Py_SetFileSystemEncoding(config->filesystem_encoding,
|
||||
config->filesystem_errors) < 0) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue