Skip to content

Commit 790090d

Browse files
committed
Apply review comments
1 parent af7ec41 commit 790090d

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

vm/src/pyobjectrc.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ impl PyObjVTable {
8484
/// payload can be a rust float or rust int in case of float and int objects.
8585
#[repr(C)]
8686
struct PyInner<T> {
87-
refcount: RefCount,
87+
ref_count: RefCount,
8888
// TODO: move typeid into vtable once TypeId::of is const
8989
typeid: TypeId,
9090
vtable: &'static PyObjVTable,
9191

9292
typ: PyRwLock<PyTypeRef>, // __class__ member
9393
dict: Option<InstanceDict>,
94-
weaklist: WeakRefList,
94+
weak_list: WeakRefList,
9595

9696
payload: T,
9797
}
@@ -160,7 +160,7 @@ impl WeakRefList {
160160
if is_generic {
161161
if let Some(generic_weakref) = inner.generic_weakref {
162162
let generic_weakref = unsafe { generic_weakref.as_ref() };
163-
if generic_weakref.0.refcount.get() != 0 {
163+
if generic_weakref.0.ref_count.get() != 0 {
164164
return PyObjectWeak {
165165
weak: generic_weakref.to_owned(),
166166
};
@@ -171,7 +171,7 @@ impl WeakRefList {
171171
pointers: Pointers::new(),
172172
parent: inner_ptr,
173173
callback: UnsafeCell::new(callback),
174-
hash: Radium::new(-1),
174+
hash: Radium::new(crate::common::hash::SENTINEL),
175175
};
176176
let weak = PyRef::new_ref(obj, cls, dict);
177177
// SAFETY: we don't actually own the PyObjectWeaks inside `list`, and every time we take
@@ -266,7 +266,7 @@ impl WeakRefList {
266266

267267
impl WeakListInner {
268268
fn iter(&self) -> impl Iterator<Item = &PyObjectView<PyWeak>> {
269-
self.list.iter().filter(|wr| wr.0.refcount.get() > 0)
269+
self.list.iter().filter(|wr| wr.0.ref_count.get() > 0)
270270
}
271271
}
272272

@@ -317,7 +317,7 @@ impl PyWeak {
317317
let guard = unsafe { self.parent.as_ref().lock() };
318318
let obj_ptr = guard.obj?;
319319
unsafe {
320-
if !obj_ptr.as_ref().0.refcount.safe_inc() {
320+
if !obj_ptr.as_ref().0.ref_count.safe_inc() {
321321
return None;
322322
}
323323
Some(PyObjectRef::from_raw(obj_ptr.as_ptr()))
@@ -399,12 +399,12 @@ impl InstanceDict {
399399
impl<T: PyObjectPayload> PyInner<T> {
400400
fn new(payload: T, typ: PyTypeRef, dict: Option<PyDictRef>) -> Box<Self> {
401401
Box::new(PyInner {
402-
refcount: RefCount::new(),
402+
ref_count: RefCount::new(),
403403
typeid: TypeId::of::<T>(),
404404
vtable: PyObjVTable::of::<T>(),
405405
typ: PyRwLock::new(typ),
406406
dict: dict.map(InstanceDict::new),
407-
weaklist: WeakRefList::new(),
407+
weak_list: WeakRefList::new(),
408408
payload,
409409
})
410410
}
@@ -455,7 +455,7 @@ impl ToOwned for PyObject {
455455

456456
#[inline(always)]
457457
fn to_owned(&self) -> Self::Owned {
458-
self.0.refcount.inc();
458+
self.0.ref_count.inc();
459459
PyObjectRef {
460460
ptr: NonNull::from(self),
461461
}
@@ -554,7 +554,7 @@ impl PyObjectRef {
554554
impl PyObject {
555555
#[inline]
556556
fn weak_ref_list(&self) -> Option<&WeakRefList> {
557-
Some(&self.0.weaklist)
557+
Some(&self.0.weak_list)
558558
}
559559

560560
pub(crate) fn downgrade_with_weakref_typ_opt(
@@ -684,7 +684,7 @@ impl PyObject {
684684

685685
#[inline]
686686
pub fn strong_count(&self) -> usize {
687-
self.0.refcount.get()
687+
self.0.ref_count.get()
688688
}
689689

690690
#[inline]
@@ -702,14 +702,14 @@ impl PyObject {
702702
// CPython-compatible drop implementation
703703
if let Some(slot_del) = self.class().mro_find_map(|cls| cls.slots.del.load()) {
704704
let ret = crate::vm::thread::with_vm(self, |vm| {
705-
self.0.refcount.inc();
705+
self.0.ref_count.inc();
706706
if let Err(e) = slot_del(self, vm) {
707707
print_del_error(e, self, vm);
708708
}
709-
self.0.refcount.dec()
709+
self.0.ref_count.dec()
710710
});
711711
match ret {
712-
// the decref right above set refcount back to 0
712+
// the decref right above set ref_count back to 0
713713
Some(true) => {}
714714
// we've been resurrected by __del__
715715
Some(false) => return Err(()),
@@ -725,7 +725,7 @@ impl PyObject {
725725
Ok(())
726726
}
727727

728-
/// Can only be called when refcount has dropped to zero. `ptr` must be valid
728+
/// Can only be called when ref_count has dropped to zero. `ptr` must be valid
729729
#[inline(never)]
730730
#[cold]
731731
unsafe fn drop_slow(ptr: NonNull<PyObject>) {
@@ -797,7 +797,7 @@ impl PyObjectWeak {
797797

798798
impl Drop for PyObjectRef {
799799
fn drop(&mut self) {
800-
if self.0.refcount.dec() {
800+
if self.0.ref_count.dec() {
801801
unsafe { PyObject::drop_slow(self.ptr) }
802802
}
803803
}
@@ -863,7 +863,7 @@ impl<T: PyObjectPayload> ToOwned for PyObjectView<T> {
863863

864864
#[inline(always)]
865865
fn to_owned(&self) -> Self::Owned {
866-
self.0.refcount.inc();
866+
self.0.ref_count.inc();
867867
PyRef {
868868
ptr: NonNull::from(self),
869869
}
@@ -923,7 +923,7 @@ impl<T: PyObjectPayload> fmt::Debug for PyRef<T> {
923923
impl<T: PyObjectPayload> Drop for PyRef<T> {
924924
#[inline]
925925
fn drop(&mut self) {
926-
if self.0.refcount.dec() {
926+
if self.0.ref_count.dec() {
927927
unsafe { PyObject::drop_slow(self.ptr.cast::<PyObject>()) }
928928
}
929929
}
@@ -1078,22 +1078,22 @@ pub(crate) fn init_type_hierarchy() -> (PyTypeRef, PyTypeRef, PyTypeRef) {
10781078
};
10791079
let type_type_ptr = Box::into_raw(Box::new(partially_init!(
10801080
PyInner::<PyType> {
1081-
refcount: RefCount::new(),
1081+
ref_count: RefCount::new(),
10821082
typeid: TypeId::of::<PyType>(),
10831083
vtable: PyObjVTable::of::<PyType>(),
10841084
dict: None,
1085-
weaklist: WeakRefList::new(),
1085+
weak_list: WeakRefList::new(),
10861086
payload: type_payload,
10871087
},
10881088
Uninit { typ }
10891089
)));
10901090
let object_type_ptr = Box::into_raw(Box::new(partially_init!(
10911091
PyInner::<PyType> {
1092-
refcount: RefCount::new(),
1092+
ref_count: RefCount::new(),
10931093
typeid: TypeId::of::<PyType>(),
10941094
vtable: PyObjVTable::of::<PyType>(),
10951095
dict: None,
1096-
weaklist: WeakRefList::new(),
1096+
weak_list: WeakRefList::new(),
10971097
payload: object_payload,
10981098
},
10991099
Uninit { typ },
@@ -1105,12 +1105,12 @@ pub(crate) fn init_type_hierarchy() -> (PyTypeRef, PyTypeRef, PyTypeRef) {
11051105
type_type_ptr as *mut MaybeUninit<PyInner<PyType>> as *mut PyInner<PyType>;
11061106

11071107
unsafe {
1108-
(*type_type_ptr).refcount.inc();
1108+
(*type_type_ptr).ref_count.inc();
11091109
ptr::write(
11101110
&mut (*object_type_ptr).typ as *mut PyRwLock<PyTypeRef> as *mut UninitRef<PyType>,
11111111
PyRwLock::new(NonNull::new_unchecked(type_type_ptr)),
11121112
);
1113-
(*type_type_ptr).refcount.inc();
1113+
(*type_type_ptr).ref_count.inc();
11141114
ptr::write(
11151115
&mut (*type_type_ptr).typ as *mut PyRwLock<PyTypeRef> as *mut UninitRef<PyType>,
11161116
PyRwLock::new(NonNull::new_unchecked(type_type_ptr)),

0 commit comments

Comments
 (0)