servo: Merge #19035 - Introduce nsStaticAtom (from nnethercote:bug-1411893); r=emilio

It's a sub-class of nsAtom, useful for cases where you know you are dealing
exclusively with static atoms. The nice thing about it is that you can use
raw nsStaticAtom pointers instead of RefPtr<>. (In fact, the AddRef/Release
implementations ensure that we'll crash if we use RefPtr<nsStaticAtom>.)

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix https://bugzilla.mozilla.org/show_bug.cgi?id=1411893

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because tested on the Gecko side.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 8f171058f8d4ee1009134ea574ba771a3be5d6f1

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 7393725da8af4a2e9a9c45cff6af6ae569c76244
This commit is contained in:
Nicholas Nethercote 2017-10-27 04:34:17 -05:00
Родитель 6a75b6bf98
Коммит e2f87d712f
5 изменённых файлов: 12525 добавлений и 12503 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -2423,7 +2423,7 @@ pub mod root {
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Element_MappedAttributeEntry {
pub attribute: *mut *mut root::nsAtom,
pub attribute: *mut *mut root::nsStaticAtom,
}
#[test]
fn bindgen_test_layout_Element_MappedAttributeEntry() {
@ -14854,6 +14854,18 @@ pub mod root {
"::" , stringify ! ( mStorageSize ) ));
}
#[repr(C)]
#[derive(Debug)]
pub struct nsStaticAtom {
pub _base: root::nsAtom,
}
#[test]
fn bindgen_test_layout_nsStaticAtom() {
assert_eq!(::std::mem::size_of::<nsStaticAtom>() , 24usize , concat !
( "Size of: " , stringify ! ( nsStaticAtom ) ));
assert_eq! (::std::mem::align_of::<nsStaticAtom>() , 8usize , concat !
( "Alignment of " , stringify ! ( nsStaticAtom ) ));
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct nsIPrincipal {
pub _base: root::nsISerializable,
@ -19305,7 +19317,7 @@ pub mod root {
/// @param aCaseSensitive Whether to do a case-sensitive compare on the values.
/// @return ATTR_MISSING, ATTR_VALUE_NO_MATCH or the non-negative index
/// indicating the first value of aValues that matched
pub type nsIContent_AttrValuesArray = *const *const root::nsAtom;
pub type nsIContent_AttrValuesArray = *const *const root::nsStaticAtom;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum nsIContent_FlattenedParentType {
@ -31834,7 +31846,7 @@ pub mod root {
#[repr(C)]
#[derive(Debug, Copy)]
pub struct nsMediaFeature {
pub mName: *mut *mut root::nsAtom,
pub mName: *mut *mut root::nsStaticAtom,
pub mRangeType: root::nsMediaFeature_RangeType,
pub mValueType: root::nsMediaFeature_ValueType,
pub mReqFlags: u8,

Просмотреть файл

@ -638,7 +638,7 @@ impl Expression {
};
let atom = Atom::from(feature_name);
match find_feature(|f| atom.as_ptr() == unsafe { *f.mName }) {
match find_feature(|f| atom.as_ptr() == unsafe { *f.mName as *mut _ }) {
Some(f) => Ok((f, range)),
None => Err(()),
}

Просмотреть файл

@ -20,7 +20,7 @@ PRELUDE = """
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Autogenerated file created by components/style/binding_tools/regen_atoms.py, DO NOT EDIT DIRECTLY */
/* Autogenerated file created by components/style/gecko/binding_tools/regen_atoms.py, DO NOT EDIT DIRECTLY */
"""[1:]
@ -42,14 +42,14 @@ class GkAtomSource:
PATTERN = re.compile('^(GK_ATOM)\((.+),\s*"(.*)"\)')
FILE = "include/nsGkAtomList.h"
CLASS = "nsGkAtoms"
TYPE = "nsAtom"
TYPE = "nsStaticAtom"
class CSSPseudoElementsAtomSource:
PATTERN = re.compile('^(CSS_PSEUDO_ELEMENT)\((.+),\s*"(.*)",')
FILE = "include/nsCSSPseudoElementList.h"
CLASS = "nsCSSPseudoElements"
# NB: nsICSSPseudoElement is effectively the same as a nsAtom, but we need
# NB: nsICSSPseudoElement is effectively the same as a nsStaticAtom, but we need
# this for MSVC name mangling.
TYPE = "nsICSSPseudoElement"
@ -163,14 +163,14 @@ class FileAvoidWrite(BytesIO):
self.close()
IMPORTS = ("\nuse gecko_bindings::structs::nsAtom;"
IMPORTS = ("\nuse gecko_bindings::structs::nsStaticAtom;"
"\nuse string_cache::Atom;\n\n")
ATOM_TEMPLATE = (" #[link_name = \"{link_name}\"]\n"
" pub static {name}: *mut {type};")
UNSAFE_STATIC = ("#[inline(always)]\n"
"pub unsafe fn atom_from_static(ptr: *mut nsAtom) -> Atom {\n"
"pub unsafe fn atom_from_static(ptr: *mut nsStaticAtom) -> Atom {\n"
" Atom::from_static(ptr)\n"
"}\n\n")
@ -220,7 +220,7 @@ def write_atom_macro(atoms, file_name):
f.write(IMPORTS)
for source in SOURCES:
if source.TYPE != "nsAtom":
if source.TYPE != "nsStaticAtom":
f.write("pub enum {} {{}}\n\n".format(source.TYPE))
f.write(UNSAFE_STATIC)

Просмотреть файл

@ -10,7 +10,7 @@ use gecko_bindings::bindings::Gecko_AddRefAtom;
use gecko_bindings::bindings::Gecko_Atomize;
use gecko_bindings::bindings::Gecko_Atomize16;
use gecko_bindings::bindings::Gecko_ReleaseAtom;
use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind};
use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind, nsStaticAtom};
use nsstring::{nsAString, nsStr};
use precomputed_hash::PrecomputedHash;
use std::ascii::AsciiExt;
@ -254,7 +254,7 @@ impl Atom {
/// that way, now we have sugar for is_static, creating atoms using
/// Atom::from should involve almost no overhead.
#[inline]
unsafe fn from_static(ptr: *mut nsAtom) -> Self {
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!");
@ -389,4 +389,14 @@ impl From<*mut nsAtom> for Atom {
}
}
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);