From 12ce441f5c9c9fc62a29b5a32efcf64154bb19d4 Mon Sep 17 00:00:00 2001
From: jD91mZM2 <me@krake.one>
Date: Fri, 22 Jun 2018 22:12:29 +0200
Subject: [PATCH] Use static mut over UnsafeCell

---
 src/stdio/src/default.rs | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/src/stdio/src/default.rs b/src/stdio/src/default.rs
index 25b584471..9337856c5 100644
--- a/src/stdio/src/default.rs
+++ b/src/stdio/src/default.rs
@@ -1,25 +1,12 @@
-use core::cell::UnsafeCell;
 use core::sync::atomic::AtomicBool;
 use core::ptr;
 use super::{constants, internal, BUFSIZ, FILE, UNGET};
 
-struct GlobalFile(UnsafeCell<FILE>);
-impl GlobalFile {
-    const fn new(file: FILE) -> Self {
-        GlobalFile(UnsafeCell::new(file))
-    }
-    fn get(&self) -> *mut FILE {
-        self.0.get()
-    }
-}
-// statics need to be Sync
-unsafe impl Sync for GlobalFile {}
-
 #[allow(non_upper_case_globals)]
 static mut default_stdin_buf: [u8; BUFSIZ as usize + UNGET] = [0; BUFSIZ as usize + UNGET];
 
 #[allow(non_upper_case_globals)]
-static mut default_stdin: GlobalFile = GlobalFile::new(FILE {
+static mut default_stdin: FILE = FILE {
     flags: constants::F_PERM | constants::F_NOWR | constants::F_BADJ,
     rpos: ptr::null_mut(),
     rend: ptr::null_mut(),
@@ -32,13 +19,13 @@ static mut default_stdin: GlobalFile = GlobalFile::new(FILE {
     buf_char: -1,
     unget: UNGET,
     lock: AtomicBool::new(false),
-});
+};
 
 #[allow(non_upper_case_globals)]
 static mut default_stdout_buf: [u8; BUFSIZ as usize] = [0; BUFSIZ as usize];
 
 #[allow(non_upper_case_globals)]
-static mut default_stdout: GlobalFile = GlobalFile::new(FILE {
+static mut default_stdout: FILE = FILE {
     flags: constants::F_PERM | constants::F_NORD | constants::F_BADJ,
     rpos: ptr::null_mut(),
     rend: ptr::null_mut(),
@@ -51,13 +38,13 @@ static mut default_stdout: GlobalFile = GlobalFile::new(FILE {
     buf_char: b'\n' as i8,
     unget: 0,
     lock: AtomicBool::new(false),
-});
+};
 
 #[allow(non_upper_case_globals)]
 static mut default_stderr_buf: [u8; BUFSIZ as usize] = [0; BUFSIZ as usize];
 
 #[allow(non_upper_case_globals)]
-static mut default_stderr: GlobalFile = GlobalFile::new(FILE {
+static mut default_stderr: FILE = FILE {
     flags: constants::F_PERM | constants::F_NORD | constants::F_BADJ,
     rpos: ptr::null_mut(),
     rend: ptr::null_mut(),
@@ -70,19 +57,19 @@ static mut default_stderr: GlobalFile = GlobalFile::new(FILE {
     buf_char: -1,
     unget: 0,
     lock: AtomicBool::new(false),
-});
+};
 
 #[no_mangle]
 pub extern "C" fn __stdin() -> *mut FILE {
-    unsafe { default_stdin.get() }
+    unsafe { &mut default_stdin }
 }
 
 #[no_mangle]
 pub extern "C" fn __stdout() -> *mut FILE {
-    unsafe { default_stdout.get() }
+    unsafe { &mut default_stdout }
 }
 
 #[no_mangle]
 pub extern "C" fn __stderr() -> *mut FILE {
-    unsafe { default_stderr.get() }
+    unsafe { &mut default_stderr }
 }
-- 
GitLab