Skip to content
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

Use OsString for Process Args and Env Vars #1227

Merged
merged 1 commit into from Mar 18, 2024

Conversation

CryZe
Copy link
Contributor

@CryZe CryZe commented Mar 18, 2024

This continues the "os stringification" on the Process type where now not only the process name, but also the arguments and environment variables are also done as OsString, mirroring std.

This continues the "os stringification" on the `Process` type where now
not only the process name, but also the arguments and environment
variables are also done as `OsString`, mirroring `std`.
@@ -661,7 +662,7 @@ fn get_all_pid_entries(
if !entry.is_dir() {
return None;
}
let pid = Pid::from(usize::from_str(&name.to_string_lossy()).ok()?);
let pid = Pid::from(usize::from_str(name.to_str()?).ok()?);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use to_str_lossy here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For lossiness, the Unicode replacement character (�) is used, but that never results in a validly parsed usize, so might as well skip directly to returning an error, instead of allocating and then erroring anyway.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Thanks for the explanations!

@GuillaumeGomez
Copy link
Owner

Just one question but otherwise changes look good. 👍

@GuillaumeGomez GuillaumeGomez merged commit 7735a81 into GuillaumeGomez:master Mar 18, 2024
67 checks passed
@CryZe CryZe deleted the process-env-args branch March 18, 2024 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants