1
1
use rustpython_common:: lock:: PyMutex ;
2
2
3
+ use crate :: types:: Constructor ;
3
4
use crate :: { Context , PyRef , class:: PyClassImpl , frame:: FrameRef , source:: LineNumber } ;
5
+ use crate :: { PyPayload , PyResult , VirtualMachine } ;
6
+
7
+ use super :: PyTypeRef ;
4
8
5
9
#[ pyclass( module = false , name = "traceback" , traverse, ctx = traceback_type) ]
6
10
#[ derive( Debug ) ]
@@ -15,7 +19,26 @@ pub struct PyTraceback {
15
19
16
20
pub type PyTracebackRef = PyRef < PyTraceback > ;
17
21
18
- #[ pyclass]
22
+ impl Constructor for PyTraceback {
23
+ type Args = ( Option < PyRef < Self > > , FrameRef , u32 , usize ) ;
24
+
25
+ fn py_new (
26
+ cls : PyTypeRef ,
27
+ ( next, frame, lasti, lineno) : Self :: Args ,
28
+ vm : & VirtualMachine ,
29
+ ) -> PyResult {
30
+ Self :: new (
31
+ next,
32
+ frame,
33
+ lasti,
34
+ LineNumber :: new ( lineno) . unwrap_or ( LineNumber :: MIN ) ,
35
+ )
36
+ . into_ref_with_type ( vm, cls)
37
+ . map ( Into :: into)
38
+ }
39
+ }
40
+
41
+ #[ pyclass( with( Constructor ) ) ]
19
42
impl PyTraceback {
20
43
pub fn new ( next : Option < PyRef < Self > > , frame : FrameRef , lasti : u32 , lineno : LineNumber ) -> Self {
21
44
PyTraceback {
@@ -42,19 +65,19 @@ impl PyTraceback {
42
65
}
43
66
44
67
#[ pygetset]
45
- fn tb_next ( & self ) -> Option < PyRef < Self > > {
46
- self . next . lock ( ) . as_ref ( ) . cloned ( )
68
+ pub fn tb_next ( & self ) -> Option < PyRef < Self > > {
69
+ self . next . lock ( ) . clone ( )
47
70
}
48
71
49
72
#[ pygetset( setter) ]
50
- fn set_tb_next ( & self , value : Option < PyRef < Self > > ) {
73
+ pub fn set_tb_next ( & self , value : Option < PyRef < Self > > ) {
51
74
* self . next . lock ( ) = value;
52
75
}
53
76
}
54
77
55
78
impl PyTracebackRef {
56
79
pub fn iter ( & self ) -> impl Iterator < Item = PyTracebackRef > {
57
- std:: iter:: successors ( Some ( self . clone ( ) ) , |tb| tb. next . lock ( ) . clone ( ) )
80
+ std:: iter:: successors ( Some ( self . clone ( ) ) , |tb| tb. tb_next ( ) )
58
81
}
59
82
}
60
83
0 commit comments