]> Repositorios git - scryer-prolog.git/commitdiff
Update src/read.rs
authorPeter Mikkelsen <[email protected]>
Sun, 24 Aug 2025 12:17:41 +0000 (14:17 +0200)
committerPeter Mikkelsen <[email protected]>
Sun, 24 Aug 2025 12:27:33 +0000 (14:27 +0200)
Co-authored-by: Bennet Bleßmann <[email protected]>
src/read.rs

index 636a6f491d28d272db91233f7495c12e14d4990e..586ab7384534342fecc76c36e20ace4f43be0b51 100644 (file)
@@ -107,27 +107,25 @@ fn get_prompt() -> &'static str {
     }
 }
 
-static mut RAW_READ: bool = false;
+thread_local! {
+    static RAW_READ: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
+}
 
 pub struct RawReadGuard;
 
 impl RawReadGuard {
     pub fn new() -> RawReadGuard {
-        unsafe {
-            if RAW_READ {
-                panic!("Nested RawReadGuards");
-            }
-            RAW_READ = true;
+        if RAW_READ.get() {
+            panic!("Nested RawReadGuards");
         }
+        RAW_READ.set(true);
         RawReadGuard
     }
 }
 
 impl Drop for RawReadGuard {
     fn drop(&mut self) {
-        unsafe {
-            RAW_READ = false;
-        }
+        RAW_READ.set(false);
     }
 }
 
@@ -196,8 +194,7 @@ impl ReadlineStream {
 
     #[cfg(feature = "repl")]
     fn call_readline(&mut self) -> std::io::Result<usize> {
-        let raw = unsafe { RAW_READ };
-        let text = if raw {
+        let text = if RAW_READ.get() {
             let mut buffer = String::new();
             let stdin = std::io::stdin();
             match stdin.read_line(&mut buffer) {