From 309477210c8be94f7015904fd556f70bf26c0198 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 16 May 2020 17:34:33 -0600 Subject: Make Errno::clear safe All it does is assign a value to a thread-local int. There's nothing unsafe about that. --- CHANGELOG.md | 2 ++ src/errno.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b58beb1..41cb121c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). `::nix::sys::reboot` now return `Result` instead of `Result` (#[1239](https://github.com/nix-rust/nix/pull/1239)) - `sys::socket::sockaddr_storage_to_addr` is no longer `unsafe`. So is `offset_of!`. +- `sys::socket::sockaddr_storage_to_addr`, `offset_of!`, and `Errno::clear` are + no longer `unsafe`. (#[1244](https://github.com/nix-rust/nix/pull/1244)) - Several `Inotify` methods now take `self` by value instead of by reference (#[1244](https://github.com/nix-rust/nix/pull/1244)) diff --git a/src/errno.rs b/src/errno.rs index 1fb66ac5..eda097d8 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -46,8 +46,11 @@ cfg_if! { } /// Sets the platform-specific errno to no-error -unsafe fn clear() { - *errno_location() = 0; +fn clear() { + // Safe because errno is a thread-local variable + unsafe { + *errno_location() = 0; + } } /// Returns the platform-specific value of errno @@ -70,7 +73,7 @@ impl Errno { from_i32(err) } - pub unsafe fn clear() { + pub fn clear() { clear() } -- cgit v1.2.3