@@ -106,7 +106,7 @@ cfg_if::cfg_if! {
106
106
107
107
unsafe fn drop_dealloc_obj < T : PyObjectPayload > ( x : * mut PyObject ) {
108
108
#[ cfg( feature = "gc_bacon" ) ]
109
- if x . as_ref ( ) . unwrap ( ) . header ( ) . buffered ( ) {
109
+ if ( * x ) . header ( ) . buffered ( ) {
110
110
error ! ( "Try to drop&dealloc a buffered object! Drop only for now!" ) ;
111
111
drop_only_obj :: < T > ( x) ;
112
112
} else {
@@ -130,7 +130,7 @@ macro_rules! partially_drop {
130
130
/// NOTE: `header` is not drop to prevent UB
131
131
#[ cfg( feature = "gc_bacon" ) ]
132
132
unsafe fn drop_only_obj < T : PyObjectPayload > ( x : * mut PyObject ) {
133
- let obj = x. cast :: < PyInner < T > > ( ) . as_ref ( ) . expect ( "Non-Null Pointer" ) ;
133
+ let obj = & * x. cast :: < PyInner < T > > ( ) ;
134
134
partially_drop ! (
135
135
obj.
136
136
#[ cfg( debug_assertions) ]
@@ -151,12 +151,12 @@ unsafe fn drop_only_obj<T: PyObjectPayload>(x: *mut PyObject) {
151
151
#[ cfg( feature = "gc_bacon" ) ]
152
152
unsafe fn dealloc_only_obj < T : PyObjectPayload > ( x : * mut PyObject ) {
153
153
{
154
- let obj = x. cast :: < PyInner < T > > ( ) . as_ref ( ) . expect ( "Non-Null Pointer" ) ;
154
+ let obj = & * x. cast :: < PyInner < T > > ( ) ;
155
155
partially_drop ! ( obj. header, vtable, weak_list) ;
156
156
} // don't want keep a ref to a to be deallocated object
157
157
std:: alloc:: dealloc (
158
158
x. cast ( ) ,
159
- std:: alloc:: Layout :: for_value ( x. cast :: < PyInner < T > > ( ) . as_ref ( ) . unwrap ( ) ) ,
159
+ std:: alloc:: Layout :: for_value ( & * x. cast :: < PyInner < T > > ( ) ) ,
160
160
) ;
161
161
}
162
162
@@ -165,6 +165,7 @@ unsafe fn debug_obj<T: PyObjectPayload>(x: &PyObject, f: &mut fmt::Formatter) ->
165
165
fmt:: Debug :: fmt ( x, f)
166
166
}
167
167
168
+ #[ cfg( feature = "gc_bacon" ) ]
168
169
unsafe fn try_trace_obj < T : PyObjectPayload > ( x : & PyObject , tracer_fn : & mut TracerFn ) {
169
170
let x = & * ( x as * const PyObject as * const PyInner < T > ) ;
170
171
let payload = & x. payload ;
@@ -185,6 +186,7 @@ impl PyObjVTable {
185
186
#[ cfg( feature = "gc_bacon" ) ]
186
187
dealloc_only : dealloc_only_obj :: < T > ,
187
188
debug : debug_obj :: < T > ,
189
+ #[ cfg( feature = "gc_bacon" ) ]
188
190
trace : {
189
191
if T :: IS_TRACE {
190
192
Some ( try_trace_obj :: < T > )
@@ -700,19 +702,17 @@ pub struct PyObject(PyInner<Erased>);
700
702
701
703
#[ cfg( feature = "gc_bacon" ) ]
702
704
impl PyObject {
703
- #[ cfg( feature = "gc_bacon" ) ]
704
- pub fn header ( & self ) -> & GcHeader {
705
+ pub ( in crate :: object) fn header ( & self ) -> & GcHeader {
705
706
& self . 0 . header
706
707
}
707
708
708
- pub fn inner_typeid ( & self ) -> TypeId {
709
- self . 0 . typeid
709
+ pub ( in crate :: object ) fn is_traceable ( & self ) -> bool {
710
+ self . 0 . vtable . trace . is_some ( )
710
711
}
711
-
712
- pub fn increment ( & self ) {
712
+ fn increment ( & self ) {
713
713
self . 0 . header . gc ( ) . increment ( self )
714
714
}
715
- pub fn decrement ( & self ) -> GcStatus {
715
+ fn decrement ( & self ) -> GcStatus {
716
716
self . 0 . header . gc ( ) . decrement ( self )
717
717
}
718
718
}
@@ -1135,23 +1135,6 @@ impl PyObject {
1135
1135
true
1136
1136
}
1137
1137
1138
- #[ cfg( feature = "gc_bacon" ) ]
1139
- #[ allow( unused) ]
1140
- pub ( crate ) unsafe fn drop_only ( ptr : NonNull < PyObject > ) -> bool {
1141
- let zelf = ptr. as_ref ( ) ;
1142
- if !zelf. header ( ) . check_set_drop_only ( ) {
1143
- return false ;
1144
- }
1145
-
1146
- // not set PyInner's is_drop because still havn't dealloc
1147
- let drop_only = zelf. 0 . vtable . drop_only ;
1148
-
1149
- drop_only ( ptr. as_ptr ( ) ) ;
1150
- // Safety: after drop_only, header should still remain undropped
1151
- zelf. header ( ) . set_done_drop ( true ) ;
1152
- true
1153
- }
1154
-
1155
1138
#[ cfg( feature = "gc_bacon" ) ]
1156
1139
/// run object's __del__ and then rust's destructor but doesn't dealloc
1157
1140
pub ( in crate :: object) unsafe fn del_drop ( ptr : NonNull < PyObject > ) -> bool {
0 commit comments