Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab83328

Browse files
committedApr 24, 2024·
Address review.
1 parent 4db179f commit ab83328

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed
 

‎src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ mod poll_timeout;
190190
target_os = "haiku",
191191
target_os = "linux",
192192
target_os = "netbsd",
193-
target_os = "macos",
194-
target_os = "ios"
193+
apple_targets
195194
))]
196195
feature! {
197196
#![feature = "process"]

‎src/spawn.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ impl PosixSpawnAttr {
8585
/// Get spawn flags. See
8686
/// [posix_spawnattr_getflags](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_getflags.html).
8787
#[doc(alias("posix_spawnattr_getflags"))]
88-
pub fn flags(&mut self) -> Result<PosixSpawnFlags> {
88+
pub fn flags(&self) -> Result<PosixSpawnFlags> {
8989
let mut flags: libc::c_short = 0;
9090
let res = unsafe {
9191
libc::posix_spawnattr_getflags(
92-
&mut self.attr as *mut libc::posix_spawnattr_t,
92+
&self.attr as *const libc::posix_spawnattr_t,
9393
&mut flags,
9494
)
9595
};
@@ -120,12 +120,12 @@ impl PosixSpawnAttr {
120120
/// Get spawn pgroup. See
121121
/// [posix_spawnattr_getpgroup](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_getpgroup.html).
122122
#[doc(alias("posix_spawnattr_getpgroup"))]
123-
pub fn pgroup(&mut self) -> Result<Pid> {
123+
pub fn pgroup(&self) -> Result<Pid> {
124124
let mut pid: libc::pid_t = 0;
125125

126126
let res = unsafe {
127127
libc::posix_spawnattr_getpgroup(
128-
&mut self.attr as *mut libc::posix_spawnattr_t,
128+
&self.attr as *const libc::posix_spawnattr_t,
129129
&mut pid,
130130
)
131131
};
@@ -158,12 +158,12 @@ impl PosixSpawnAttr {
158158
/// Get spawn sigdefault. See
159159
/// [posix_spawnattr_getsigdefault](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_getsigdefault.html).
160160
#[doc(alias("posix_spawnattr_getsigdefault"))]
161-
pub fn sigdefault(&mut self) -> Result<SigSet> {
161+
pub fn sigdefault(&self) -> Result<SigSet> {
162162
let mut sigset = mem::MaybeUninit::uninit();
163163

164164
let res = unsafe {
165165
libc::posix_spawnattr_getsigdefault(
166-
&mut self.attr as *mut libc::posix_spawnattr_t,
166+
&self.attr as *const libc::posix_spawnattr_t,
167167
sigset.as_mut_ptr(),
168168
)
169169
};
@@ -196,12 +196,12 @@ impl PosixSpawnAttr {
196196
/// Get spawn sigmask. See
197197
/// [posix_spawnattr_getsigmask](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_getsigmask.html).
198198
#[doc(alias("posix_spawnattr_getsigmask"))]
199-
pub fn sigmask(&mut self) -> Result<SigSet> {
199+
pub fn sigmask(&self) -> Result<SigSet> {
200200
let mut sigset = mem::MaybeUninit::uninit();
201201

202202
let res = unsafe {
203203
libc::posix_spawnattr_getsigmask(
204-
&mut self.attr as *mut libc::posix_spawnattr_t,
204+
&self.attr as *const libc::posix_spawnattr_t,
205205
sigset.as_mut_ptr(),
206206
)
207207
};
@@ -387,14 +387,19 @@ impl Drop for PosixSpawnFileActions {
387387
}
388388
}
389389

390-
// Specifically for use with posix_spawn and posix_spawnp.
391-
// https://github.com/rust-lang/libc/issues/1272
390+
// The POSIX standard requires those `args` and `envp` to be of type `*const *mut [c_char]`,
391+
// but implementations won't modify them, making the `mut` type redundant. Considering this,
392+
// Nix does not expose this mutability, but we have to change the interface when calling the
393+
// underlying libc interfaces , this helper function does the conversion job.
394+
//
395+
// SAFETY:
396+
// It is safe to add the mutability in types as implementations won't mutable them.
392397
unsafe fn to_exec_array<S: AsRef<CStr>>(args: &[S]) -> Vec<*mut libc::c_char> {
393398
let mut v: Vec<*mut libc::c_char> = args
394399
.iter()
395-
.map(|s| s.as_ref().as_ptr() as *mut libc::c_char)
400+
.map(|s| s.as_ref().as_ptr().cast_mut())
396401
.collect();
397-
v.push(std::ptr::null::<libc::c_char>() as *mut libc::c_char);
402+
v.push(std::ptr::null_mut());
398403
v
399404
}
400405

0 commit comments

Comments
 (0)
Please sign in to comment.