@@ -863,6 +863,13 @@ sys_exit_impl(PyObject *module, PyObject *status)
863
863
}
864
864
865
865
866
+ static PyObject *
867
+ get_utf8_unicode (void )
868
+ {
869
+ _Py_DECLARE_STR (utf_8 , "utf-8" );
870
+ PyObject * ret = & _Py_STR (utf_8 );
871
+ return Py_NewRef (ret );
872
+ }
866
873
867
874
/*[clinic input]
868
875
sys.getdefaultencoding
@@ -874,9 +881,7 @@ static PyObject *
874
881
sys_getdefaultencoding_impl (PyObject * module )
875
882
/*[clinic end generated code: output=256d19dfcc0711e6 input=d416856ddbef6909]*/
876
883
{
877
- _Py_DECLARE_STR (utf_8 , "utf-8" );
878
- PyObject * ret = & _Py_STR (utf_8 );
879
- return Py_NewRef (ret );
884
+ return get_utf8_unicode ();
880
885
}
881
886
882
887
/*[clinic input]
@@ -891,7 +896,17 @@ sys_getfilesystemencoding_impl(PyObject *module)
891
896
{
892
897
PyInterpreterState * interp = _PyInterpreterState_GET ();
893
898
const PyConfig * config = _PyInterpreterState_GetConfig (interp );
894
- return PyUnicode_FromWideChar (config -> filesystem_encoding , -1 );
899
+
900
+ if (wcscmp (config -> filesystem_encoding , L"utf-8" ) == 0 ) {
901
+ return get_utf8_unicode ();
902
+ }
903
+
904
+ PyObject * u = PyUnicode_FromWideChar (config -> filesystem_encoding , -1 );
905
+ if (u == NULL ) {
906
+ return NULL ;
907
+ }
908
+ _PyUnicode_InternInPlace (interp , & u );
909
+ return u ;
895
910
}
896
911
897
912
/*[clinic input]
@@ -906,7 +921,12 @@ sys_getfilesystemencodeerrors_impl(PyObject *module)
906
921
{
907
922
PyInterpreterState * interp = _PyInterpreterState_GET ();
908
923
const PyConfig * config = _PyInterpreterState_GetConfig (interp );
909
- return PyUnicode_FromWideChar (config -> filesystem_errors , -1 );
924
+ PyObject * u = PyUnicode_FromWideChar (config -> filesystem_errors , -1 );
925
+ if (u == NULL ) {
926
+ return NULL ;
927
+ }
928
+ _PyUnicode_InternInPlace (interp , & u );
929
+ return u ;
910
930
}
911
931
912
932
/*[clinic input]
0 commit comments