Skip to content

Commit 1ee43e1

Browse files
Merge branch 'master' of https://github.com/nix-rust/nix into posix_fallocate
2 parents 9edda30 + 1662466 commit 1ee43e1

29 files changed

+281
-275
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ matrix:
8585
rust: 1.36.0
8686

8787
# Make sure stable is always working too
88+
# FIXME: Travis's "stable" images are stuck on 1.35.0. Until that's fixed,
89+
# explicitly request 1.37.0, which is as of this writing the latest stable
90+
# release.
91+
# https://travis-ci.community/t/stable-rust-channel-outdated/4213
8892
- env: TARGET=x86_64-unknown-linux-gnu
89-
rust: stable
93+
rust: 1.37.0
9094

9195
# Test that we can build with the lowest version of all dependencies.
9296
# "cargo test" doesn't work because some of our dev-dependencies, like

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1313
([#1107](https://github.com/nix-rust/nix/pull/1107))
1414

1515
### Changed
16+
- `Signal::from_c_int` has been replaced by `Signal::try_from`
17+
([#1113](https://github.com/nix-rust/nix/pull/1113))
18+
1619
- Changed `readlink` and `readlinkat` to return `OsString`
1720
([#1109](https://github.com/nix-rust/nix/pull/1109))
1821

@@ -40,6 +43,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4043
([#1107](https://github.com/nix-rust/nix/pull/1107))
4144

4245
### Fixed
46+
- Fix length of abstract socket addresses
47+
([#1120](https://github.com/nix-rust/nix/pull/1120))
48+
4349
### Removed
4450

4551
## [0.15.0] - 10 August 2019

CONVENTIONS.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,11 @@ to parameters of functions by [enumerations][enum].
7676

7777
Whenever we need to use a [libc][libc] function to properly initialize a
7878
variable and said function allows us to use uninitialized memory, we use
79-
[`std::mem::uninitialized`][std_uninitialized] (or [`core::mem::uninitialized`][core_uninitialized])
80-
when defining the variable. This allows us to avoid the overhead incurred by
81-
zeroing or otherwise initializing the variable.
79+
[`std::mem::MaybeUninit`][std_MaybeUninit] when defining the variable. This
80+
allows us to avoid the overhead incurred by zeroing or otherwise initializing
81+
the variable.
8282

8383
[bitflags]: https://crates.io/crates/bitflags/
84-
[core_uninitialized]: https://doc.rust-lang.org/core/mem/fn.uninitialized.html
8584
[enum]: https://doc.rust-lang.org/reference.html#enumerations
8685
[libc]: https://crates.io/crates/libc/
87-
[std_uninitialized]: https://doc.rust-lang.org/std/mem/fn.uninitialized.html
86+
[std_MaybeUninit]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html

src/dir.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,18 @@ impl<'d> Iterator for Iter<'d> {
102102
// for the NUL byte. It doesn't look like the std library does this; it just uses
103103
// fixed-sized buffers (and libc's dirent seems to be sized so this is appropriate).
104104
// Probably fine here too then.
105-
let mut ent: Entry = Entry(::std::mem::uninitialized());
105+
let mut ent = std::mem::MaybeUninit::<dirent>::uninit();
106106
let mut result = ptr::null_mut();
107-
if let Err(e) = Errno::result(readdir_r((self.0).0.as_ptr(), &mut ent.0, &mut result)) {
107+
if let Err(e) = Errno::result(
108+
readdir_r((self.0).0.as_ptr(), ent.as_mut_ptr(), &mut result))
109+
{
108110
return Some(Err(e));
109111
}
110112
if result.is_null() {
111113
return None;
112114
}
113-
assert_eq!(result, &mut ent.0 as *mut dirent);
114-
Some(Ok(ent))
115+
assert_eq!(result, ent.as_mut_ptr());
116+
Some(Ok(Entry(ent.assume_init())))
115117
}
116118
}
117119
}
@@ -126,6 +128,7 @@ impl<'d> Drop for Iter<'d> {
126128
///
127129
/// Note that unlike the std version, this may represent the `.` or `..` entries.
128130
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
131+
#[repr(transparent)]
129132
pub struct Entry(dirent);
130133

131134
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]

src/ifaddrs.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ impl Iterator for InterfaceAddressIterator {
125125
/// }
126126
/// ```
127127
pub fn getifaddrs() -> Result<InterfaceAddressIterator> {
128-
let mut addrs: *mut libc::ifaddrs = unsafe { mem::uninitialized() };
129-
Errno::result(unsafe { libc::getifaddrs(&mut addrs) }).map(|_| {
130-
InterfaceAddressIterator {
131-
base: addrs,
132-
next: addrs,
133-
}
134-
})
128+
let mut addrs = mem::MaybeUninit::<*mut libc::ifaddrs>::uninit();
129+
unsafe {
130+
Errno::result(libc::getifaddrs(addrs.as_mut_ptr())).map(|_| {
131+
InterfaceAddressIterator {
132+
base: addrs.assume_init(),
133+
next: addrs.assume_init(),
134+
}
135+
})
136+
}
135137
}
136138

137139
#[cfg(test)]

src/macros.rs

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -81,59 +81,26 @@ macro_rules! libc_bitflags {
8181
/// }
8282
/// ```
8383
macro_rules! libc_enum {
84-
// (non-pub) Exit rule.
84+
// Exit rule.
8585
(@make_enum
8686
{
87+
$v:vis
8788
name: $BitFlags:ident,
8889
attrs: [$($attrs:tt)*],
8990
entries: [$($entries:tt)*],
9091
}
9192
) => {
9293
$($attrs)*
9394
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
94-
enum $BitFlags {
95+
$v enum $BitFlags {
9596
$($entries)*
9697
}
9798
};
9899

99-
// (pub) Exit rule.
100-
(@make_enum
101-
{
102-
pub,
103-
name: $BitFlags:ident,
104-
attrs: [$($attrs:tt)*],
105-
entries: [$($entries:tt)*],
106-
}
107-
) => {
108-
$($attrs)*
109-
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
110-
pub enum $BitFlags {
111-
$($entries)*
112-
}
113-
};
114-
115-
// (non-pub) Done accumulating.
116-
(@accumulate_entries
117-
{
118-
name: $BitFlags:ident,
119-
attrs: $attrs:tt,
120-
},
121-
$entries:tt;
122-
) => {
123-
libc_enum! {
124-
@make_enum
125-
{
126-
name: $BitFlags,
127-
attrs: $attrs,
128-
entries: $entries,
129-
}
130-
}
131-
};
132-
133-
// (pub) Done accumulating.
100+
// Done accumulating.
134101
(@accumulate_entries
135102
{
136-
pub,
103+
$v:vis
137104
name: $BitFlags:ident,
138105
attrs: $attrs:tt,
139106
},
@@ -142,7 +109,7 @@ macro_rules! libc_enum {
142109
libc_enum! {
143110
@make_enum
144111
{
145-
pub,
112+
$v
146113
name: $BitFlags,
147114
attrs: $attrs,
148115
entries: $entries,
@@ -217,35 +184,17 @@ macro_rules! libc_enum {
217184
}
218185
};
219186

220-
// (non-pub) Entry rule.
221-
(
222-
$(#[$attr:meta])*
223-
enum $BitFlags:ident {
224-
$($vals:tt)*
225-
}
226-
) => {
227-
libc_enum! {
228-
@accumulate_entries
229-
{
230-
name: $BitFlags,
231-
attrs: [$(#[$attr])*],
232-
},
233-
[];
234-
$($vals)*
235-
}
236-
};
237-
238-
// (pub) Entry rule.
187+
// Entry rule.
239188
(
240189
$(#[$attr:meta])*
241-
pub enum $BitFlags:ident {
190+
$v:vis enum $BitFlags:ident {
242191
$($vals:tt)*
243192
}
244193
) => {
245194
libc_enum! {
246195
@accumulate_entries
247196
{
248-
pub,
197+
$v
249198
name: $BitFlags,
250199
attrs: [$(#[$attr])*],
251200
},

src/mqueue.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ impl MqAttr {
3939
mq_maxmsg: c_long,
4040
mq_msgsize: c_long,
4141
mq_curmsgs: c_long)
42-
-> MqAttr {
43-
let mut attr = unsafe { mem::uninitialized::<libc::mq_attr>() };
44-
attr.mq_flags = mq_flags;
45-
attr.mq_maxmsg = mq_maxmsg;
46-
attr.mq_msgsize = mq_msgsize;
47-
attr.mq_curmsgs = mq_curmsgs;
48-
MqAttr { mq_attr: attr }
42+
-> MqAttr
43+
{
44+
let mut attr = mem::MaybeUninit::<libc::mq_attr>::uninit();
45+
unsafe {
46+
let p = attr.as_mut_ptr();
47+
(*p).mq_flags = mq_flags;
48+
(*p).mq_maxmsg = mq_maxmsg;
49+
(*p).mq_msgsize = mq_msgsize;
50+
(*p).mq_curmsgs = mq_curmsgs;
51+
MqAttr { mq_attr: attr.assume_init() }
52+
}
4953
}
5054

5155
pub fn flags(&self) -> c_long {
@@ -123,9 +127,9 @@ pub fn mq_send(mqdes: mqd_t, message: &[u8], msq_prio: u32) -> Result<()> {
123127
///
124128
/// See also [`mq_getattr(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html)
125129
pub fn mq_getattr(mqd: mqd_t) -> Result<MqAttr> {
126-
let mut attr = unsafe { mem::uninitialized::<libc::mq_attr>() };
127-
let res = unsafe { libc::mq_getattr(mqd, &mut attr) };
128-
Errno::result(res).map(|_| MqAttr { mq_attr: attr })
130+
let mut attr = mem::MaybeUninit::<libc::mq_attr>::uninit();
131+
let res = unsafe { libc::mq_getattr(mqd, attr.as_mut_ptr()) };
132+
Errno::result(res).map(|_| unsafe{MqAttr { mq_attr: attr.assume_init() }})
129133
}
130134

131135
/// Set the attributes of the message queue. Only `O_NONBLOCK` can be set, everything else will be ignored
@@ -134,9 +138,11 @@ pub fn mq_getattr(mqd: mqd_t) -> Result<MqAttr> {
134138
///
135139
/// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_setattr.html)
136140
pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
137-
let mut attr = unsafe { mem::uninitialized::<libc::mq_attr>() };
138-
let res = unsafe { libc::mq_setattr(mqd, &newattr.mq_attr as *const libc::mq_attr, &mut attr) };
139-
Errno::result(res).map(|_| MqAttr { mq_attr: attr })
141+
let mut attr = mem::MaybeUninit::<libc::mq_attr>::uninit();
142+
let res = unsafe {
143+
libc::mq_setattr(mqd, &newattr.mq_attr as *const libc::mq_attr, attr.as_mut_ptr())
144+
};
145+
Errno::result(res).map(|_| unsafe{ MqAttr { mq_attr: attr.assume_init() }})
140146
}
141147

142148
/// Convenience function.

src/pty.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,16 @@ pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
218218
pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>>>(winsize: T, termios: U) -> Result<OpenptyResult> {
219219
use std::ptr;
220220

221-
let mut slave: libc::c_int = unsafe { mem::uninitialized() };
222-
let mut master: libc::c_int = unsafe { mem::uninitialized() };
221+
let mut slave = mem::MaybeUninit::<libc::c_int>::uninit();
222+
let mut master = mem::MaybeUninit::<libc::c_int>::uninit();
223223
let ret = {
224224
match (termios.into(), winsize.into()) {
225225
(Some(termios), Some(winsize)) => {
226226
let inner_termios = termios.get_libc_termios();
227227
unsafe {
228228
libc::openpty(
229-
&mut master,
230-
&mut slave,
229+
master.as_mut_ptr(),
230+
slave.as_mut_ptr(),
231231
ptr::null_mut(),
232232
&*inner_termios as *const libc::termios as *mut _,
233233
winsize as *const Winsize as *mut _,
@@ -237,8 +237,8 @@ pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
237237
(None, Some(winsize)) => {
238238
unsafe {
239239
libc::openpty(
240-
&mut master,
241-
&mut slave,
240+
master.as_mut_ptr(),
241+
slave.as_mut_ptr(),
242242
ptr::null_mut(),
243243
ptr::null_mut(),
244244
winsize as *const Winsize as *mut _,
@@ -249,8 +249,8 @@ pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
249249
let inner_termios = termios.get_libc_termios();
250250
unsafe {
251251
libc::openpty(
252-
&mut master,
253-
&mut slave,
252+
master.as_mut_ptr(),
253+
slave.as_mut_ptr(),
254254
ptr::null_mut(),
255255
&*inner_termios as *const libc::termios as *mut _,
256256
ptr::null_mut(),
@@ -260,8 +260,8 @@ pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
260260
(None, None) => {
261261
unsafe {
262262
libc::openpty(
263-
&mut master,
264-
&mut slave,
263+
master.as_mut_ptr(),
264+
slave.as_mut_ptr(),
265265
ptr::null_mut(),
266266
ptr::null_mut(),
267267
ptr::null_mut(),
@@ -273,10 +273,12 @@ pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
273273

274274
Errno::result(ret)?;
275275

276-
Ok(OpenptyResult {
277-
master,
278-
slave,
279-
})
276+
unsafe {
277+
Ok(OpenptyResult {
278+
master: master.assume_init(),
279+
slave: slave.assume_init(),
280+
})
281+
}
280282
}
281283

282284
/// Create a new pseudoterminal, returning the master file descriptor and forked pid.
@@ -294,7 +296,7 @@ pub fn forkpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
294296
use unistd::Pid;
295297
use unistd::ForkResult::*;
296298

297-
let mut master: libc::c_int = unsafe { mem::uninitialized() };
299+
let mut master = mem::MaybeUninit::<libc::c_int>::uninit();
298300

299301
let term = match termios.into() {
300302
Some(termios) => {
@@ -310,17 +312,19 @@ pub fn forkpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
310312
.unwrap_or(ptr::null_mut());
311313

312314
let res = unsafe {
313-
libc::forkpty(&mut master, ptr::null_mut(), term, win)
315+
libc::forkpty(master.as_mut_ptr(), ptr::null_mut(), term, win)
314316
};
315317

316318
let fork_result = Errno::result(res).map(|res| match res {
317319
0 => Child,
318320
res => Parent { child: Pid::from_raw(res) },
319321
})?;
320322

321-
Ok(ForkptyResult {
322-
master,
323-
fork_result,
324-
})
323+
unsafe {
324+
Ok(ForkptyResult {
325+
master: master.assume_init(),
326+
fork_result,
327+
})
328+
}
325329
}
326330

src/sys/ptrace/linux.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,15 @@ pub fn setregs(pid: Pid, regs: user_regs_struct) -> Result<()> {
221221
/// and therefore use the data field to return values. This function handles these
222222
/// requests.
223223
fn ptrace_get_data<T>(request: Request, pid: Pid) -> Result<T> {
224-
// Creates an uninitialized pointer to store result in
225-
let data: T = unsafe { mem::uninitialized() };
224+
let mut data = mem::MaybeUninit::uninit();
226225
let res = unsafe {
227226
libc::ptrace(request as RequestType,
228227
libc::pid_t::from(pid),
229228
ptr::null_mut::<T>(),
230-
&data as *const _ as *const c_void)
229+
data.as_mut_ptr() as *const _ as *const c_void)
231230
};
232231
Errno::result(res)?;
233-
Ok(data)
232+
Ok(unsafe{ data.assume_init() })
234233
}
235234

236235
unsafe fn ptrace_other(request: Request, pid: Pid, addr: AddressType, data: *mut c_void) -> Result<c_long> {

0 commit comments

Comments
 (0)