mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Prevent tb_next loop (#6596)
This commit is contained in:
1
Lib/test/test_raise.py
vendored
1
Lib/test/test_raise.py
vendored
@@ -244,7 +244,6 @@ class TestTracebackType(unittest.TestCase):
|
||||
def raiser(self):
|
||||
raise ValueError
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_attrs(self):
|
||||
try:
|
||||
self.raiser()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::PyType;
|
||||
use crate::{
|
||||
Context, Py, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, frame::FrameRef,
|
||||
types::Constructor,
|
||||
AsObject, Context, Py, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl,
|
||||
frame::FrameRef, types::Constructor,
|
||||
};
|
||||
use rustpython_common::lock::PyMutex;
|
||||
use rustpython_compiler_core::OneIndexed;
|
||||
@@ -63,8 +63,26 @@ impl PyTraceback {
|
||||
}
|
||||
|
||||
#[pygetset(setter)]
|
||||
fn set_tb_next(&self, value: Option<PyRef<Self>>) {
|
||||
*self.next.lock() = value;
|
||||
fn set_tb_next(
|
||||
zelf: &Py<Self>,
|
||||
value: Option<PyRef<Self>>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
if let Some(ref new_next) = value {
|
||||
let mut cursor = new_next.clone();
|
||||
loop {
|
||||
if cursor.is(zelf) {
|
||||
return Err(vm.new_value_error("traceback loop detected".to_owned()));
|
||||
}
|
||||
let next = cursor.next.lock().clone();
|
||||
match next {
|
||||
Some(n) => cursor = n,
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
*zelf.next.lock() = value;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user