bpo-36775: _PyCoreConfig only uses wchar_t* (GH-13062) · python/cpython@709d23d

11 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -207,8 +207,8 @@ typedef struct {

207207
208208

See Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors.

209209

*/

210-

char *filesystem_encoding;

211-

char *filesystem_errors;

210+

wchar_t *filesystem_encoding;

211+

wchar_t *filesystem_errors;

212212
213213

wchar_t *pycache_prefix; /* PYTHONPYCACHEPREFIX, -X pycache_prefix=PATH */

214214

wchar_t *program_name; /* Program name, see also Py_GetProgramName() */

@@ -334,13 +334,13 @@ typedef struct {

334334

Value set from PYTHONIOENCODING environment variable and

335335

Py_SetStandardStreamEncoding() function.

336336

See also 'stdio_errors' attribute. */

337-

char *stdio_encoding;

337+

wchar_t *stdio_encoding;

338338
339339

/* Error handler of sys.stdin and sys.stdout.

340340

Value set from PYTHONIOENCODING environment variable and

341341

Py_SetStandardStreamEncoding() function.

342342

See also 'stdio_encoding' attribute. */

343-

char *stdio_errors;

343+

wchar_t *stdio_errors;

344344
345345

#ifdef MS_WINDOWS

346346

/* If greater than zero, use io.FileIO instead of WindowsConsoleIO for sys

Original file line numberDiff line numberDiff line change

@@ -106,12 +106,9 @@ PyAPI_FUNC(_PyInitError) _PyCoreConfig_Copy(

106106

_PyCoreConfig *config,

107107

const _PyCoreConfig *config2);

108108

PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetString(

109-

char **config_str,

110-

const char *str);

111-

PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetWideString(

112109

wchar_t **config_str,

113110

const wchar_t *str);

114-

PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetWideStringFromString(

111+

PyAPI_FUNC(_PyInitError) _PyCoreConfig_DecodeLocale(

115112

wchar_t **config_str,

116113

const char *str);

117114

PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig(_PyCoreConfig *config);

Original file line numberDiff line numberDiff line change

@@ -21,6 +21,9 @@ extern int _Py_SetFileSystemEncoding(

2121

const char *errors);

2222

extern void _Py_ClearFileSystemEncoding(void);

2323

extern _PyInitError _PyUnicode_InitEncodings(PyInterpreterState *interp);

24+

#ifdef MS_WINDOWS

25+

extern int _PyUnicode_EnableLegacyWindowsFSEncoding(void);

26+

#endif

2427
2528

PyAPI_FUNC(void) _Py_ClearStandardStreamEncoding(void);

2629
Original file line numberDiff line numberDiff line change

@@ -56,7 +56,14 @@ struct _is {

5656

PyObject *codec_search_cache;

5757

PyObject *codec_error_registry;

5858

int codecs_initialized;

59-

int fscodec_initialized;

59+
60+

/* fs_codec.encoding is initialized to NULL.

61+

Later, it is set to a non-NULL string by _PyUnicode_InitEncodings(). */

62+

struct {

63+

char *encoding; /* Filesystem encoding (encoded to UTF-8) */

64+

char *errors; /* Filesystem errors (encoded to UTF-8) */

65+

_Py_error_handler error_handler;

66+

} fs_codec;

6067
6168

_PyCoreConfig core_config;

6269

#ifdef HAVE_DLOPEN

Original file line numberDiff line numberDiff line change

@@ -260,6 +260,7 @@ Py_LOCAL_INLINE(PyObject *)

260260

STRINGLIB(utf8_encoder)(PyObject *unicode,

261261

STRINGLIB_CHAR *data,

262262

Py_ssize_t size,

263+

_Py_error_handler error_handler,

263264

const char *errors)

264265

{

265266

Py_ssize_t i; /* index into data of next input character */

@@ -268,7 +269,6 @@ STRINGLIB(utf8_encoder)(PyObject *unicode,

268269

PyObject *error_handler_obj = NULL;

269270

PyObject *exc = NULL;

270271

PyObject *rep = NULL;

271-

_Py_error_handler error_handler = _Py_ERROR_UNKNOWN;

272272

#endif

273273

#if STRINGLIB_SIZEOF_CHAR == 1

274274

const Py_ssize_t max_char_size = 2;