style: Remove unsound Atom From implementations.

Fixes #20158
This commit is contained in:
Emilio Cobos Álvarez 2018-03-19 11:06:23 +01:00
parent 52205e8483
commit 55e2cd5dc3
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
7 changed files with 85 additions and 100 deletions

View file

@ -99,7 +99,9 @@ impl WeakAtom {
/// Clone this atom, bumping the refcount if the atom is not static.
#[inline]
pub fn clone(&self) -> Atom {
Atom::from(self.as_ptr())
unsafe {
Atom::from_raw(self.as_ptr())
}
}
/// Get the atom hash.
@ -267,15 +269,25 @@ impl Atom {
///
/// Right now it's only used by the atom macro, and ideally it should keep
/// that way, now we have sugar for is_static, creating atoms using
/// Atom::from should involve almost no overhead.
/// Atom::from_raw should involve almost no overhead.
#[inline]
unsafe fn from_static(ptr: *mut nsStaticAtom) -> Self {
pub unsafe fn from_static(ptr: *mut nsStaticAtom) -> Self {
let atom = Atom(ptr as *mut WeakAtom);
debug_assert!(atom.is_static(),
"Called from_static for a non-static atom!");
atom
}
/// Creates an atom from an atom pointer.
#[inline(always)]
pub unsafe fn from_raw(ptr: *mut nsAtom) -> Self {
let atom = Atom(ptr as *mut WeakAtom);
if !atom.is_static() {
Gecko_AddRefAtom(ptr);
}
atom
}
/// Creates an atom from a dynamic atom pointer that has already had AddRef
/// called on it.
#[inline]
@ -308,7 +320,9 @@ impl Hash for WeakAtom {
impl Clone for Atom {
#[inline(always)]
fn clone(&self) -> Atom {
Atom::from(self.as_ptr())
unsafe {
Atom::from_raw(self.as_ptr())
}
}
}
@ -388,28 +402,4 @@ impl From<String> for Atom {
}
}
impl From<*mut nsAtom> for Atom {
#[inline]
fn from(ptr: *mut nsAtom) -> Atom {
assert!(!ptr.is_null());
unsafe {
let ret = Atom(WeakAtom::new(ptr));
if !ret.is_static() {
Gecko_AddRefAtom(ptr);
}
ret
}
}
}
impl From<*mut nsStaticAtom> for Atom {
#[inline]
fn from(ptr: *mut nsStaticAtom) -> Atom {
assert!(!ptr.is_null());
unsafe {
Atom::from_static(ptr)
}
}
}
malloc_size_of_is_0!(Atom);