mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
fix: infinite recursion bug
This commit is contained in:
parent
50cfc43081
commit
cd9973e800
2 changed files with 14 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::thread::ThreadId;
|
||||
// use std::rc::Rc;
|
||||
pub use parking_lot::{
|
||||
|
@ -292,6 +293,7 @@ pub struct Forkable<T: Send + Clone> {
|
|||
last_borrowed_at: Arc<ThreadLocal<RefCell<BorrowInfo>>>,
|
||||
#[cfg(any(feature = "backtrace", feature = "debug"))]
|
||||
last_mut_borrowed_at: Arc<ThreadLocal<RefCell<BorrowInfo>>>,
|
||||
recursion_counter: Arc<AtomicU32>,
|
||||
}
|
||||
|
||||
impl<T: fmt::Debug + Send + Clone> fmt::Debug for Forkable<T> {
|
||||
|
@ -326,9 +328,18 @@ impl<T: Send + Clone> Forkable<T> {
|
|||
last_borrowed_at: Arc::new(ThreadLocal::new()),
|
||||
#[cfg(any(feature = "backtrace", feature = "debug"))]
|
||||
last_mut_borrowed_at: Arc::new(ThreadLocal::new()),
|
||||
recursion_counter: Arc::new(AtomicU32::new(0)),
|
||||
}
|
||||
}
|
||||
|
||||
/// return 1 if the recursion limit is reached.
|
||||
pub fn dec_recursion_counter(&self) -> u32 {
|
||||
if self.recursion_counter.load(Ordering::SeqCst) == 0 {
|
||||
self.recursion_counter.store(256, Ordering::SeqCst);
|
||||
}
|
||||
self.recursion_counter.fetch_sub(1, Ordering::SeqCst)
|
||||
}
|
||||
|
||||
pub fn update_init(&mut self) {
|
||||
let clone = self.clone_inner();
|
||||
// NG: self.init = Arc::new(clone);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue