-
Notifications
You must be signed in to change notification settings - Fork 19
socket.ioctl, if_nameindex over IP Helper, _locale.getencoding, the legacy Windows filesystem codec, and 13 posix interpreter-release guards #1415
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
Changes from 12 commits
6e94c40
6868945
19c7054
7b5ba41
bfcdda3
482a21f
751ebff
69ac9a4
3bd4195
f1eddfd
305e309
6422815
a835177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -415,11 +415,14 @@ impl W_TextIOWrapper { | |
| Ok(()) | ||
| } | ||
|
|
||
| /// `encoding="locale"` selects the current locale's encoding; the sandbox | ||
| /// and default environment resolve that to UTF-8. | ||
| /// `encoding="locale"` selects the current locale's encoding, which is | ||
| /// what `_Py_GetLocaleEncodingObject` answers for it and for the | ||
| /// unspecified argument that resolves to it. A sandbox build has no host | ||
| /// locale to ask and reads utf-8, the answer a `_Py_FORCE_UTF8_LOCALE` | ||
| /// build gives without asking one. | ||
| fn resolve_locale_encoding(encoding: String) -> String { | ||
| if encoding == "locale" { | ||
| "utf-8".to_string() | ||
| crate::module::_locale::interp_locale::locale_encoding() | ||
| } else { | ||
| encoding | ||
| } | ||
|
|
@@ -1050,25 +1053,47 @@ impl W_TextIOWrapper { | |
| #[default(pyre_object::w_bool_from(false))] line_buffering: PyObjectRef, | ||
| #[default(pyre_object::w_bool_from(false))] write_through: PyObjectRef, | ||
| ) -> Result<(), crate::PyError> { | ||
| // Every argument is converted before the body runs, in the order the | ||
| // signature gives them: `encoding` and `newline` are accepted only as | ||
| // `str` or `None`, and the two flags are truth-tested. 3.14's | ||
| // constructor uses the `bool` converter for those, unlike | ||
| // `reconfigure`'s `int` one — an object with `__bool__` but no | ||
| // `__index__` is accepted here — and a `__bool__` that raises ends | ||
| // the call before `self->ok = 0`, leaving a stream that was already | ||
| // open still open. | ||
| let unspecified = if crate::importing::utf8_mode_flag() != 0 { | ||
| "utf-8" | ||
| } else { | ||
| "locale" | ||
| }; | ||
| let encoding_text = Self::checked_text0(encoding, unspecified, "encoding")?; | ||
| if !unsafe { pyre_object::is_none(newline) || pyre_object::is_str(newline) } { | ||
| return Err(crate::PyError::type_error("illegal newline type")); | ||
| } | ||
| let line_buffering = crate::baseobjspace::is_true(line_buffering)?; | ||
| let write_through = crate::baseobjspace::is_true(write_through)?; | ||
|
|
||
| // PyPy starts every initialization attempt in STATE_ZERO. A failed | ||
| // reinitialization must leave all I/O operations uninitialized. | ||
| self.state = STATE_ZERO; | ||
| self.w_buffer = PY_NULL; | ||
| pyre_object::gc_hook::try_gc_write_barrier(self as *mut Self as *mut u8); | ||
|
|
||
| let encoding = | ||
| Self::resolve_locale_encoding(Self::checked_text0(encoding, "utf-8", "encoding")?); | ||
| // An unspecified `encoding` reads the locale's, unless UTF-8 mode has | ||
| // already answered the question. `_io.text_encoding` is not on this | ||
| // path - a direct `TextIOWrapper(...)` call reaches the constructor | ||
| // itself - so the warning that argument's absence carries is raised | ||
| // here, at this frame. | ||
| if unsafe { pyre_object::is_none(encoding) } | ||
| && crate::importing::warn_default_encoding_flag() | ||
| { | ||
| crate::warn::warn_category("'encoding' argument not specified", "EncodingWarning", 1)?; | ||
| } | ||
| let errors = Self::checked_text0(errors, "strict", "errors")?; | ||
| Self::io_check_errors(&errors)?; | ||
| let newline_value = Self::unwrap_newline(newline)?; | ||
| let encoding = Self::resolve_locale_encoding(encoding_text); | ||
| let codec = Self::lookup_text_codec(&encoding)?; | ||
|
Comment on lines
+1056
to
1096
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial Consolidate the duplicated default-encoding/warning logic with This block recomputes the same default ("utf-8" vs "locale" based on UTF-8 mode) and re-emits the same Extract the "resolve default encoding, optionally warn" logic into one shared helper both call sites use. 🤖 Prompt for AI Agents |
||
| // 3.14's constructor uses the `bool` Argument Clinic converter (truth | ||
| // testing), unlike `reconfigure`'s `int` converter — an object with | ||
| // `__bool__` but no `__index__` is accepted here. Argument parsing | ||
| // runs before the body, so an object whose `__bool__` raises leaves | ||
| // the stream unattached rather than half filled in. | ||
| let line_buffering = crate::baseobjspace::is_true(line_buffering)?; | ||
| let write_through = crate::baseobjspace::is_true(write_through)?; | ||
|
|
||
| self.attach_buffer( | ||
| buffer, | ||
|
|
||
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.
On Windows after
PYTHONLEGACYWINDOWSFSENCODINGorsys._enablelegacywindowsfsencoding(), this helper is only wired intopath_or_fd_w;PyUnicode_DecodeFSDefaultandPyUnicode_DecodeFSDefaultAndSizestill call the UTF-8-onlyfsdecode_filename_bytes, whilePyUnicode_EncodeFSDefaultstill calls the UTF-8-onlyfsencodeincpyext/unicodeobject.rs. Native extensions consequently seesysreportmbcs/replacebut encode and decode filesystem names as UTF-8, potentially addressing a different path; route those filesystem-codec entry points through the mode-aware conversions as well.AGENTS.md reference: AGENTS.md:L172-L176
Useful? React with 👍 / 👎.