Skip to content

Commit

Permalink
Rename unchecked_refmut -> unchecked_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu committed Feb 18, 2020
1 parent 98d810e commit 5e28f7c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
32 changes: 16 additions & 16 deletions src/pycell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
unsafe fn unchecked_ref(&self) -> &T {
&*((&self) as *const &Self as *const _)
}
unsafe fn unchecked_refmut(&self) -> &mut T {
unsafe fn unchecked_mut(&self) -> &mut T {
&mut *((&self) as *const &Self as *const _ as *mut _)
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ unsafe impl<T: PyClass> PyObjectLayout<T> for PyCellInner<T> {
unsafe fn unchecked_ref(&self) -> &T {
&*self.value.get()
}
unsafe fn unchecked_refmut(&self) -> &mut T {
unsafe fn unchecked_mut(&self) -> &mut T {
&mut *self.value.get()
}
unsafe fn py_init(&mut self, value: T) {
Expand Down Expand Up @@ -202,8 +202,8 @@ unsafe impl<T: PyClass> PyObjectLayout<T> for PyCell<T> {
unsafe fn unchecked_ref(&self) -> &T {
self.inner.unchecked_ref()
}
unsafe fn unchecked_refmut(&self) -> &mut T {
self.inner.unchecked_refmut()
unsafe fn unchecked_mut(&self) -> &mut T {
self.inner.unchecked_mut()
}
unsafe fn py_init(&mut self, value: T) {
self.inner.value = ManuallyDrop::new(UnsafeCell::new(value));
Expand Down Expand Up @@ -273,11 +273,11 @@ where
U: PyClass,
{
pub fn into_super(self) -> PyRef<'p, U> {
let res = PyRef {
inner: &self.inner.ob_base,
};
std::mem::forget(self); // Avoid drop
res
let PyRef { inner } = self;
std::mem::forget(self);
PyRef {
inner: &inner.ob_base,
}
}
}

Expand Down Expand Up @@ -331,7 +331,7 @@ impl<'p, T: PyClass> PyRefMut<'p, T> {
unsafe { self.inner.ob_base.unchecked_ref() }
}
pub fn as_super_mut(&'p mut self) -> &'p mut T::BaseType {
unsafe { self.inner.ob_base.unchecked_refmut() }
unsafe { self.inner.ob_base.unchecked_mut() }
}
}

Expand All @@ -341,11 +341,11 @@ where
U: PyClass,
{
pub fn into_super(self) -> PyRefMut<'p, U> {
let res = PyRefMut {
inner: &self.inner.ob_base,
};
std::mem::forget(self); // Avoid drop
res
let PyRefMut { inner } = self;
std::mem::forget(self);
PyRefMut {
inner: &inner.ob_base,
}
}
}

Expand All @@ -361,7 +361,7 @@ impl<'p, T: PyClass> Deref for PyRefMut<'p, T> {
impl<'p, T: PyClass> DerefMut for PyRefMut<'p, T> {
#[inline]
fn deref_mut(&mut self) -> &mut T {
unsafe { self.inner.unchecked_refmut() }
unsafe { self.inner.unchecked_mut() }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub unsafe trait PyObjectLayout<T: PyTypeInfo> {
unsafe fn py_init(&mut self, _value: T) {}
unsafe fn py_drop(&mut self, _py: Python) {}
unsafe fn unchecked_ref(&self) -> &T;
unsafe fn unchecked_refmut(&self) -> &mut T;
unsafe fn unchecked_mut(&self) -> &mut T;
}

/// `T: PyObjectSizedLayout<U>` represents `T` is not a instance of
Expand Down
2 changes: 1 addition & 1 deletion src/types/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ unsafe impl crate::type_object::PyObjectLayout<PyAny> for ffi::PyObject {
unsafe fn unchecked_ref(&self) -> &PyAny {
&*((&self) as *const &Self as *const _)
}
unsafe fn unchecked_refmut(&self) -> &mut PyAny {
unsafe fn unchecked_mut(&self) -> &mut PyAny {
&mut *((&self) as *const &Self as *const _ as *mut _)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ macro_rules! impl_layout {
unsafe fn unchecked_ref(&self) -> &$name {
&*((&self) as *const &Self as *const _)
}
unsafe fn unchecked_refmut(&self) -> &mut $name {
unsafe fn unchecked_mut(&self) -> &mut $name {
&mut *((&self) as *const &Self as *const _ as *mut _)
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn inheritance_with_new_methods_with_drop() {
let obj: &PyCell<SubClassWithDrop> = inst.try_into().unwrap();
let mut obj_ref_mut = obj.borrow_mut();
obj_ref_mut.data = Some(Arc::clone(&drop_called1));
let super_ = obj_ref_mut.get_super_mut();
let mut super_ = obj_ref_mut.into_super();
super_.data = Some(Arc::clone(&drop_called2));
}

Expand Down

0 comments on commit 5e28f7c

Please sign in to comment.