Skip to content
Prev Previous commit
Next Next commit
Use _Py_STR for "utf-8"
  • Loading branch information
methane committed Apr 4, 2022
commit a0204c25f4cc6bd91beba56cba0395f6d4906ac6
8 changes: 4 additions & 4 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,10 +1145,10 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
}
}
if (encoding == NULL && self->encoding == NULL) {
const PyPreConfig *preconfig = &_PyRuntime.preconfig;
if (preconfig->utf8_mode) {
// TODO: Use _Py_STR
self->encoding = PyUnicode_FromString("utf-8");
if (_PyRuntime.preconfig.utf8_mode) {
_Py_DECLARE_STR(utf_8, "utf-8");
self->encoding = &_Py_STR(utf_8);
Py_INCREF(self->encoding);
Comment thread
methane marked this conversation as resolved.
Outdated
}
else {
self->encoding = _Py_GetLocaleEncodingObject();
Expand Down
5 changes: 4 additions & 1 deletion Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ _Py_device_encoding(int fd)
return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
#else
if (_PyRuntime.preconfig.utf8_mode) {
return PyUnicode_FromString("utf-8"); //TODO: Use _Py_STR
_Py_DECLARE_STR(utf_8, "utf-8");
PyObject *encoding = &_Py_STR(utf_8);
Py_INCREF(encoding);
return encoding;
}
return _Py_GetLocaleEncodingObject();
#endif
Expand Down