Prevent tb_next loop (#6596)

This commit is contained in:
Jeong, YunWon
2025-12-30 17:36:15 +09:00
committed by GitHub
parent 7b9f0d9657
commit 9fcc471c94
2 changed files with 22 additions and 5 deletions

View File

@@ -244,7 +244,6 @@ class TestTracebackType(unittest.TestCase):
def raiser(self):
raise ValueError
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_attrs(self):
try:
self.raiser()

View File

@@ -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(())
}
}