Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
bpo-47000: Make io.text_encoding() respects UTF-8 mode#32003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
96eeaebb8f751fbafa263de5867f52045fc37f640aaddff8711c614ce6f46faff8eb27ce48c4aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Make :func:`io.text_encoding` returns "utf-8" when UTF-8 mode is enabled. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -457,8 +457,9 @@ _io.text_encoding | ||
| A helper function to choose the text encoding. | ||
| When encoding is not None, just return it. | ||
| Otherwise, return the default text encoding (i.e. "locale"). | ||
| When encoding is not None, this function returns it. | ||
| Otherwise, this function returns the default text encoding | ||
| (i.e. "locale" or "utf-8" depends on UTF-8 mode). | ||
| This function emits an EncodingWarning if encoding is None and | ||
| sys.flags.warn_default_encoding is true. | ||
| @@ -469,7 +470,7 @@ However, please consider using encoding="utf-8" for new APIs. | ||
| static PyObject * | ||
| _io_text_encoding_impl(PyObject *module, PyObject *encoding, int stacklevel) | ||
| /*[clinic end generated code: output=91b2cfea6934cc0c input=bf70231213e2a7b4]*/ | ||
| /*[clinic end generated code: output=91b2cfea6934cc0c input=4999aa8b3d90f3d4]*/ | ||
| { | ||
| if (encoding == NULL || encoding == Py_None) { | ||
| PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
| @@ -479,7 +480,14 @@ _io_text_encoding_impl(PyObject *module, PyObject *encoding, int stacklevel) | ||
| return NULL; | ||
| } | ||
| } | ||
| return &_Py_ID(locale); | ||
| const PyPreConfig *preconfig = &_PyRuntime.preconfig; | ||
| if (preconfig->utf8_mode) { | ||
| _Py_DECLARE_STR(utf_8, "utf-8"); | ||
| encoding = &_Py_STR(utf_8); | ||
methane marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| else { | ||
| encoding = &_Py_ID(locale); | ||
| } | ||
| } | ||
| Py_INCREF(encoding); | ||
| return encoding; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericsnowcurrently We need to incref this until we implement immortal object. Am I correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of. Currently all statically allocated global objects have their refcount initialized to a really large value. So we haven't been bothering with the incref if we know the object is one of those, which it is in this case. Incref'ing it won't hurt. However, it is effectively unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid breaking refleak buildbot.
Would you tell my why this
return &_Py_ID(locale);don't break refleak test?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refcount of static objects is not directly included in
_Py_RefTotal, which is used for refleak detection. (_Py_RefTotalwill still ensure that refcount operations are balanced though, regardless of the objects involved.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So skipping INCREF here might cause in-balance of
_Py_RefTotal. Doesn't it break refleak test?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. It didn't cause a problem before. I'd have to look into why not.