Skip to content

Commit a0204c2

Browse files
committed
Use _Py_STR for "utf-8"
1 parent 8b50eb1 commit a0204c2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Modules/_io/textio.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,10 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
11451145
}
11461146
}
11471147
if (encoding == NULL && self->encoding == NULL) {
1148-
const PyPreConfig *preconfig = &_PyRuntime.preconfig;
1149-
if (preconfig->utf8_mode) {
1150-
// TODO: Use _Py_STR
1151-
self->encoding = PyUnicode_FromString("utf-8");
1148+
if (_PyRuntime.preconfig.utf8_mode) {
1149+
_Py_DECLARE_STR(utf_8, "utf-8");
1150+
self->encoding = &_Py_STR(utf_8);
1151+
Py_INCREF(self->encoding);
11521152
}
11531153
else {
11541154
self->encoding = _Py_GetLocaleEncodingObject();

Python/fileutils.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ _Py_device_encoding(int fd)
9494
return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
9595
#else
9696
if (_PyRuntime.preconfig.utf8_mode) {
97-
return PyUnicode_FromString("utf-8"); //TODO: Use _Py_STR
97+
_Py_DECLARE_STR(utf_8, "utf-8");
98+
PyObject *encoding = &_Py_STR(utf_8);
99+
Py_INCREF(encoding);
100+
return encoding;
98101
}
99102
return _Py_GetLocaleEncodingObject();
100103
#endif

0 commit comments

Comments
 (0)