@@ -37,7 +37,7 @@ use crate::dictdatatype::Dict;
37
37
use crate :: exceptions:: { self , PyBaseExceptionRef } ;
38
38
use crate :: function:: { IntoFuncArgs , IntoPyNativeFunc } ;
39
39
use crate :: iterator;
40
- pub use crate :: pyobjectrc:: { PyObjectRef , PyObjectWeak , PyRef , PyWeakRef } ;
40
+ pub use crate :: pyobjectrc:: { PyObject , PyObjectRef , PyObjectWeak , PyRef , PyWeakRef } ;
41
41
use crate :: scope:: Scope ;
42
42
use crate :: slots:: { PyTpFlags , PyTypeSlots } ;
43
43
use crate :: types:: { create_type_with_slots, TypeZoo } ;
@@ -371,12 +371,7 @@ impl PyContext {
371
371
}
372
372
373
373
pub fn new_base_object ( & self , class : PyTypeRef , dict : Option < PyDictRef > ) -> PyObjectRef {
374
- PyObject {
375
- typ : PyRwLock :: new ( class) ,
376
- dict : dict. map ( PyRwLock :: new) ,
377
- payload : object:: PyBaseObject ,
378
- }
379
- . into_ref ( )
374
+ PyObject :: new ( object:: PyBaseObject , class, dict)
380
375
}
381
376
382
377
pub fn add_tp_new_wrapper ( & self , ty : & PyTypeRef ) {
@@ -399,19 +394,6 @@ impl Default for PyContext {
399
394
}
400
395
}
401
396
402
- /// This is an actual python object. It consists of a `typ` which is the
403
- /// python class, and carries some rust payload optionally. This rust
404
- /// payload can be a rust float or rust int in case of float and int objects.
405
- #[ repr( C ) ]
406
- pub struct PyObject < T >
407
- where
408
- T : ?Sized ,
409
- {
410
- pub ( crate ) typ : PyRwLock < PyTypeRef > , // __class__ member
411
- pub ( crate ) dict : Option < PyRwLock < PyDictRef > > , // __dict__ member
412
- pub payload : T ,
413
- }
414
-
415
397
impl < T > TryFromObject for PyRef < T >
416
398
where
417
399
T : PyValue ,
@@ -628,10 +610,10 @@ pub trait TypeProtocol {
628
610
}
629
611
}
630
612
631
- impl < T > TypeProtocol for PyObject < T > {
613
+ impl TypeProtocol for PyObjectRef {
632
614
fn class ( & self ) -> PyLease < ' _ , PyType > {
633
615
PyLease {
634
- inner : self . typ . read ( ) ,
616
+ inner : self . class_lock ( ) . read ( ) ,
635
617
}
636
618
}
637
619
}
@@ -676,12 +658,6 @@ where
676
658
}
677
659
}
678
660
679
- impl < T : fmt:: Debug > fmt:: Debug for PyObject < T > {
680
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
681
- write ! ( f, "[PyObj {:?}]" , & self . payload)
682
- }
683
- }
684
-
685
661
/// An iterable Python object.
686
662
///
687
663
/// `PyIterable` implements `FromArgs` so that a built-in function can accept
@@ -882,43 +858,6 @@ where
882
858
}
883
859
}
884
860
885
- impl < T > PyObject < T >
886
- where
887
- T : Sized + PyObjectPayload ,
888
- {
889
- #[ allow( clippy:: new_ret_no_self) ]
890
- pub fn new ( payload : T , typ : PyTypeRef , dict : Option < PyDictRef > ) -> PyObjectRef {
891
- PyObject {
892
- typ : PyRwLock :: new ( typ) ,
893
- dict : dict. map ( PyRwLock :: new) ,
894
- payload,
895
- }
896
- . into_ref ( )
897
- }
898
-
899
- // Move this object into a reference object, transferring ownership.
900
- pub fn into_ref ( self ) -> PyObjectRef {
901
- PyObjectRef :: new ( self )
902
- }
903
- }
904
-
905
- impl < T > PyObject < T > {
906
- pub fn dict ( & self ) -> Option < PyDictRef > {
907
- self . dict . as_ref ( ) . map ( |mu| mu. read ( ) . clone ( ) )
908
- }
909
- /// Set the dict field. Returns `Err(dict)` if this object does not have a dict field
910
- /// in the first place.
911
- pub fn set_dict ( & self , dict : PyDictRef ) -> Result < ( ) , PyDictRef > {
912
- match self . dict {
913
- Some ( ref mu) => {
914
- * mu. write ( ) = dict;
915
- Ok ( ( ) )
916
- }
917
- None => Err ( dict) ,
918
- }
919
- }
920
- }
921
-
922
861
cfg_if:: cfg_if! {
923
862
if #[ cfg( feature = "threading" ) ] {
924
863
pub trait PyThreadingConstraint : Send + Sync { }
0 commit comments