Repository navigation
Conversation
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Just waiting for libc 0.2.191. |
OpenBSD 8.0 adds getexecpath(3), which returns the absolute path to the current executable. Prefer it over std::env::current_exe(), which has no reliable implementation on OpenBSD. In future, std::env::current_exe() should do the same under the hood, but this is blocked on rust-lang/rust#161000. Fixes #9086
b30a2cb to
4dc700e
Compare
This comment has been minimized.
This comment has been minimized.
4dc700e to
335f67b
Compare
OpenBSD added getexecpath(3) to libc, which returns an already-canonicalized executable path directly. Replace the sysctl(KERN_PROC_ARGV)-based implementation. This was the last user of div_exact in std, so drop the exact_div feature gate.
335f67b to
5fbbf47
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Just a question : any particular reason to diverge from the patch currently used downstream ? see lang/rust/patches/patch-library_std_src_sys_paths_unix_rs |
|
@semarie from how I'm reading the code, the downstream code does one extra heap allocation. The downstream one does:
The one suggested here does:
Due to type-erasure during compile, the last two steps in the later approach are effectively no-ops at runtime, if I'm not mistaken. |
| let len = CStr::from_ptr(path.as_ptr().cast()).count_bytes(); | ||
| path.truncate(len); | ||
| } | ||
| Ok(PathBuf::from(OsString::from_vec(path))) |
There was a problem hiding this comment.
Probably I've missed why do we need truncate here. I think it should be as simple as:
let mut path = vec![0; libc::PATH_MAX as usize];
unsafe {
cvt(getexecpath(path.as_mut_ptr(), path.len()))?;
let path = CStr::from_ptr(path.as_ptr()).to_bytes();
Ok(PathBuf::from(OsStr::from_bytes(path)))
}
There was a problem hiding this comment.
This code does two heap allocations instead of just one, see this comment: #163393 (comment)
|
|
@JohnTitor Ping. |
|
@JohnTitor Thanks! |
OpenBSD added getexecpath(3) to libc, which returns an
already-canonicalized executable path directly. Replace the
sysctl(KERN_PROC_ARGV)-based implementation.
This was the last user of div_exact in std, so drop the
exact_div feature gate.