@@ -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 ;
@@ -42,6 +42,7 @@ use crate::obj::objstr;
42
42
use crate :: obj:: objsuper;
43
43
use crate :: obj:: objtuple:: { self , PyTuple } ;
44
44
use crate :: obj:: objtype:: { self , PyClass } ;
45
+ use crate :: obj:: objweakref;
45
46
use crate :: obj:: objzip;
46
47
use crate :: vm:: VirtualMachine ;
47
48
@@ -66,9 +67,6 @@ Basically reference counting, but then done by rust.
66
67
/// to the python object by 1.
67
68
pub type PyObjectRef = Rc < PyObject > ;
68
69
69
- /// Same as PyObjectRef, except for being a weak reference.
70
- pub type PyObjectWeakRef = Weak < PyObject > ;
71
-
72
70
/// Use this type for function which return a python object or and exception.
73
71
/// Both the python object and the python exception are `PyObjectRef` types
74
72
/// since exceptions are also python objects.
@@ -151,6 +149,7 @@ pub struct PyContext {
151
149
pub readonly_property_type : PyObjectRef ,
152
150
pub module_type : PyObjectRef ,
153
151
pub bound_method_type : PyObjectRef ,
152
+ pub weakref_type : PyObjectRef ,
154
153
pub object : PyObjectRef ,
155
154
pub exceptions : exceptions:: ExceptionZoo ,
156
155
}
@@ -195,6 +194,7 @@ impl PyContext {
195
194
let readonly_property_type =
196
195
create_type ( "readonly_property" , & type_type, & object_type, & dict_type) ;
197
196
let super_type = create_type ( "super" , & type_type, & object_type, & dict_type) ;
197
+ let weakref_type = create_type ( "ref" , & type_type, & object_type, & dict_type) ;
198
198
let generator_type = create_type ( "generator" , & type_type, & object_type, & dict_type) ;
199
199
let bound_method_type = create_type ( "method" , & type_type, & object_type, & dict_type) ;
200
200
let str_type = create_type ( "str" , & type_type, & object_type, & dict_type) ;
@@ -294,6 +294,7 @@ impl PyContext {
294
294
generator_type,
295
295
module_type,
296
296
bound_method_type,
297
+ weakref_type,
297
298
type_type,
298
299
exceptions,
299
300
} ;
@@ -326,6 +327,7 @@ impl PyContext {
326
327
objbool:: init ( & context) ;
327
328
objcode:: init ( & context) ;
328
329
objframe:: init ( & context) ;
330
+ objweakref:: init ( & context) ;
329
331
objnone:: init ( & context) ;
330
332
objmodule:: init ( & context) ;
331
333
exceptions:: init ( & context) ;
@@ -460,6 +462,10 @@ impl PyContext {
460
462
self . bound_method_type . clone ( )
461
463
}
462
464
465
+ pub fn weakref_type ( & self ) -> PyObjectRef {
466
+ self . weakref_type . clone ( )
467
+ }
468
+
463
469
pub fn type_type ( & self ) -> PyObjectRef {
464
470
self . type_type . clone ( )
465
471
}
@@ -475,6 +481,7 @@ impl PyContext {
475
481
pub fn not_implemented ( & self ) -> PyObjectRef {
476
482
self . not_implemented . clone ( )
477
483
}
484
+
478
485
pub fn object ( & self ) -> PyObjectRef {
479
486
self . object . clone ( )
480
487
}
@@ -1522,9 +1529,6 @@ pub enum PyObjectPayload {
1522
1529
name : String ,
1523
1530
scope : ScopeRef ,
1524
1531
} ,
1525
- WeakRef {
1526
- referent : PyObjectWeakRef ,
1527
- } ,
1528
1532
RustFunction {
1529
1533
function : PyNativeFunc ,
1530
1534
} ,
@@ -1545,7 +1549,6 @@ impl fmt::Debug for PyObjectPayload {
1545
1549
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1546
1550
match self {
1547
1551
PyObjectPayload :: MemoryView { ref obj } => write ! ( f, "bytes/bytearray {:?}" , obj) ,
1548
- PyObjectPayload :: WeakRef { .. } => write ! ( f, "weakref" ) ,
1549
1552
PyObjectPayload :: Iterator { .. } => write ! ( f, "iterator" ) ,
1550
1553
PyObjectPayload :: EnumerateIterator { .. } => write ! ( f, "enumerate" ) ,
1551
1554
PyObjectPayload :: FilterIterator { .. } => write ! ( f, "filter" ) ,
0 commit comments