@@ -3,7 +3,7 @@ use std::collections::HashMap;
3
3
use std:: fmt;
4
4
use std:: iter;
5
5
use std:: ops:: RangeInclusive ;
6
- use std:: rc:: { Rc , Weak } ;
6
+ use std:: rc:: Rc ;
7
7
8
8
use num_bigint:: BigInt ;
9
9
use num_bigint:: ToBigInt ;
@@ -43,6 +43,7 @@ use crate::obj::objstr;
43
43
use crate :: obj:: objsuper;
44
44
use crate :: obj:: objtuple:: { self , PyTuple } ;
45
45
use crate :: obj:: objtype:: { self , PyClass } ;
46
+ use crate :: obj:: objweakref;
46
47
use crate :: obj:: objzip;
47
48
use crate :: vm:: VirtualMachine ;
48
49
@@ -67,9 +68,6 @@ Basically reference counting, but then done by rust.
67
68
/// to the python object by 1.
68
69
pub type PyObjectRef = Rc < PyObject > ;
69
70
70
- /// Same as PyObjectRef, except for being a weak reference.
71
- pub type PyObjectWeakRef = Weak < PyObject > ;
72
-
73
71
/// Use this type for function which return a python object or and exception.
74
72
/// Both the python object and the python exception are `PyObjectRef` types
75
73
/// since exceptions are also python objects.
@@ -141,6 +139,7 @@ pub struct PyContext {
141
139
pub readonly_property_type : PyObjectRef ,
142
140
pub module_type : PyObjectRef ,
143
141
pub bound_method_type : PyObjectRef ,
142
+ pub weakref_type : PyObjectRef ,
144
143
pub object : PyObjectRef ,
145
144
pub exceptions : exceptions:: ExceptionZoo ,
146
145
}
@@ -185,6 +184,7 @@ impl PyContext {
185
184
let readonly_property_type =
186
185
create_type ( "readonly_property" , & type_type, & object_type, & dict_type) ;
187
186
let super_type = create_type ( "super" , & type_type, & object_type, & dict_type) ;
187
+ let weakref_type = create_type ( "ref" , & type_type, & object_type, & dict_type) ;
188
188
let generator_type = create_type ( "generator" , & type_type, & object_type, & dict_type) ;
189
189
let bound_method_type = create_type ( "method" , & type_type, & object_type, & dict_type) ;
190
190
let str_type = create_type ( "str" , & type_type, & object_type, & dict_type) ;
@@ -284,6 +284,7 @@ impl PyContext {
284
284
generator_type,
285
285
module_type,
286
286
bound_method_type,
287
+ weakref_type,
287
288
type_type,
288
289
exceptions,
289
290
} ;
@@ -316,6 +317,7 @@ impl PyContext {
316
317
objbool:: init ( & context) ;
317
318
objcode:: init ( & context) ;
318
319
objframe:: init ( & context) ;
320
+ objweakref:: init ( & context) ;
319
321
objnone:: init ( & context) ;
320
322
objmodule:: init ( & context) ;
321
323
exceptions:: init ( & context) ;
@@ -450,6 +452,10 @@ impl PyContext {
450
452
self . bound_method_type . clone ( )
451
453
}
452
454
455
+ pub fn weakref_type ( & self ) -> PyObjectRef {
456
+ self . weakref_type . clone ( )
457
+ }
458
+
453
459
pub fn type_type ( & self ) -> PyObjectRef {
454
460
self . type_type . clone ( )
455
461
}
@@ -465,6 +471,7 @@ impl PyContext {
465
471
pub fn not_implemented ( & self ) -> PyObjectRef {
466
472
self . not_implemented . clone ( )
467
473
}
474
+
468
475
pub fn object ( & self ) -> PyObjectRef {
469
476
self . object . clone ( )
470
477
}
@@ -1481,7 +1488,6 @@ into_py_native_func_tuple!((a, A), (b, B), (c, C), (d, D), (e, E));
1481
1488
/// of rust data for a particular python object. Determine the python type
1482
1489
/// by using for example the `.typ()` method on a python object.
1483
1490
pub enum PyObjectPayload {
1484
- WeakRef { referent : PyObjectWeakRef } ,
1485
1491
AnyRustValue { value : Box < dyn std:: any:: Any > } ,
1486
1492
}
1487
1493
@@ -1510,7 +1516,6 @@ impl PyObjectPayload2 for PyIteratorValue {
1510
1516
impl fmt:: Debug for PyObjectPayload {
1511
1517
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1512
1518
match self {
1513
- PyObjectPayload :: WeakRef { .. } => write ! ( f, "weakref" ) ,
1514
1519
PyObjectPayload :: AnyRustValue { value } => value. fmt ( f) ,
1515
1520
}
1516
1521
}
0 commit comments