mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #12631 - Manishearth:stylo-unsafe-coord, r=bholley
stylo: Use unsafe accessors for coord data depends on https://bugzilla.mozilla.org/show_bug.cgi?id=1290061 r? @bholley <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12631) <!-- Reviewable:end -->
This commit is contained in:
commit
7e39efa2df
4 changed files with 150 additions and 31 deletions
|
@ -661,9 +661,10 @@ fn static_assert() {
|
|||
use gecko_bindings::structs::nsStyleUnit;
|
||||
// z-index is never a calc(). If it were, we'd be leaking here, so
|
||||
// assert that it isn't.
|
||||
debug_assert!(self.gecko.mZIndex.mUnit != nsStyleUnit::eStyleUnit_Calc);
|
||||
self.gecko.mZIndex.mUnit = other.gecko.mZIndex.mUnit;
|
||||
self.gecko.mZIndex.mValue = other.gecko.mZIndex.mValue;
|
||||
debug_assert!(self.gecko.mZIndex.unit() != nsStyleUnit::eStyleUnit_Calc);
|
||||
unsafe {
|
||||
self.gecko.mZIndex.copy_from_unchecked(&other.gecko.mZIndex);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T {
|
||||
|
|
|
@ -5150,11 +5150,24 @@ pub type nsStyleUnion = nsStyleCoord_h_unnamed_18;
|
|||
* the unit is a must before asking for the value in any particular
|
||||
* form.
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct nsStyleCoord {
|
||||
pub mUnit: nsStyleUnit,
|
||||
pub mValue: nsStyleUnion,
|
||||
mUnit: nsStyleUnit,
|
||||
mValue: nsStyleUnion,
|
||||
}
|
||||
impl nsStyleCoord {
|
||||
#[inline]
|
||||
pub unsafe fn get_mUnit(&self) -> &nsStyleUnit { &self.mUnit }
|
||||
pub unsafe fn get_mUnit_mut(&mut self) -> &mut nsStyleUnit {
|
||||
&mut self.mUnit
|
||||
}
|
||||
#[inline]
|
||||
pub unsafe fn get_mValue(&self) -> &nsStyleUnion { &self.mValue }
|
||||
pub unsafe fn get_mValue_mut(&mut self) -> &mut nsStyleUnion {
|
||||
&mut self.mValue
|
||||
}
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy)]
|
||||
|
@ -5195,11 +5208,26 @@ fn bindgen_test_layout_nsStyleCoord() {
|
|||
* This is commonly used to hold the widths of the borders, margins,
|
||||
* or paddings of a box.
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct nsStyleSides {
|
||||
pub mUnits: [nsStyleUnit; 4usize],
|
||||
pub mValues: [nsStyleUnion; 4usize],
|
||||
mUnits: [nsStyleUnit; 4usize],
|
||||
mValues: [nsStyleUnion; 4usize],
|
||||
}
|
||||
impl nsStyleSides {
|
||||
#[inline]
|
||||
pub unsafe fn get_mUnits(&self) -> &[nsStyleUnit; 4usize] { &self.mUnits }
|
||||
pub unsafe fn get_mUnits_mut(&mut self) -> &mut [nsStyleUnit; 4usize] {
|
||||
&mut self.mUnits
|
||||
}
|
||||
#[inline]
|
||||
pub unsafe fn get_mValues(&self) -> &[nsStyleUnion; 4usize] {
|
||||
&self.mValues
|
||||
}
|
||||
pub unsafe fn get_mValues_mut(&mut self) -> &mut [nsStyleUnion; 4usize] {
|
||||
&mut self.mValues
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_nsStyleSides() {
|
||||
|
@ -5211,11 +5239,26 @@ fn bindgen_test_layout_nsStyleSides() {
|
|||
* nsStyleCoord pairs. This is used to hold the dimensions of the
|
||||
* corners of a box (for, e.g., border-radius and outline-radius).
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct nsStyleCorners {
|
||||
pub mUnits: [nsStyleUnit; 8usize],
|
||||
pub mValues: [nsStyleUnion; 8usize],
|
||||
mUnits: [nsStyleUnit; 8usize],
|
||||
mValues: [nsStyleUnion; 8usize],
|
||||
}
|
||||
impl nsStyleCorners {
|
||||
#[inline]
|
||||
pub unsafe fn get_mUnits(&self) -> &[nsStyleUnit; 8usize] { &self.mUnits }
|
||||
pub unsafe fn get_mUnits_mut(&mut self) -> &mut [nsStyleUnit; 8usize] {
|
||||
&mut self.mUnits
|
||||
}
|
||||
#[inline]
|
||||
pub unsafe fn get_mValues(&self) -> &[nsStyleUnion; 8usize] {
|
||||
&self.mValues
|
||||
}
|
||||
pub unsafe fn get_mValues_mut(&mut self) -> &mut [nsStyleUnion; 8usize] {
|
||||
&mut self.mValues
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_nsStyleCorners() {
|
||||
|
|
|
@ -5129,11 +5129,24 @@ pub type nsStyleUnion = nsStyleCoord_h_unnamed_18;
|
|||
* the unit is a must before asking for the value in any particular
|
||||
* form.
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct nsStyleCoord {
|
||||
pub mUnit: nsStyleUnit,
|
||||
pub mValue: nsStyleUnion,
|
||||
mUnit: nsStyleUnit,
|
||||
mValue: nsStyleUnion,
|
||||
}
|
||||
impl nsStyleCoord {
|
||||
#[inline]
|
||||
pub unsafe fn get_mUnit(&self) -> &nsStyleUnit { &self.mUnit }
|
||||
pub unsafe fn get_mUnit_mut(&mut self) -> &mut nsStyleUnit {
|
||||
&mut self.mUnit
|
||||
}
|
||||
#[inline]
|
||||
pub unsafe fn get_mValue(&self) -> &nsStyleUnion { &self.mValue }
|
||||
pub unsafe fn get_mValue_mut(&mut self) -> &mut nsStyleUnion {
|
||||
&mut self.mValue
|
||||
}
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy)]
|
||||
|
@ -5174,11 +5187,26 @@ fn bindgen_test_layout_nsStyleCoord() {
|
|||
* This is commonly used to hold the widths of the borders, margins,
|
||||
* or paddings of a box.
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct nsStyleSides {
|
||||
pub mUnits: [nsStyleUnit; 4usize],
|
||||
pub mValues: [nsStyleUnion; 4usize],
|
||||
mUnits: [nsStyleUnit; 4usize],
|
||||
mValues: [nsStyleUnion; 4usize],
|
||||
}
|
||||
impl nsStyleSides {
|
||||
#[inline]
|
||||
pub unsafe fn get_mUnits(&self) -> &[nsStyleUnit; 4usize] { &self.mUnits }
|
||||
pub unsafe fn get_mUnits_mut(&mut self) -> &mut [nsStyleUnit; 4usize] {
|
||||
&mut self.mUnits
|
||||
}
|
||||
#[inline]
|
||||
pub unsafe fn get_mValues(&self) -> &[nsStyleUnion; 4usize] {
|
||||
&self.mValues
|
||||
}
|
||||
pub unsafe fn get_mValues_mut(&mut self) -> &mut [nsStyleUnion; 4usize] {
|
||||
&mut self.mValues
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_nsStyleSides() {
|
||||
|
@ -5190,11 +5218,26 @@ fn bindgen_test_layout_nsStyleSides() {
|
|||
* nsStyleCoord pairs. This is used to hold the dimensions of the
|
||||
* corners of a box (for, e.g., border-radius and outline-radius).
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct nsStyleCorners {
|
||||
pub mUnits: [nsStyleUnit; 8usize],
|
||||
pub mValues: [nsStyleUnion; 8usize],
|
||||
mUnits: [nsStyleUnit; 8usize],
|
||||
mValues: [nsStyleUnion; 8usize],
|
||||
}
|
||||
impl nsStyleCorners {
|
||||
#[inline]
|
||||
pub unsafe fn get_mUnits(&self) -> &[nsStyleUnit; 8usize] { &self.mUnits }
|
||||
pub unsafe fn get_mUnits_mut(&mut self) -> &mut [nsStyleUnit; 8usize] {
|
||||
&mut self.mUnits
|
||||
}
|
||||
#[inline]
|
||||
pub unsafe fn get_mValues(&self) -> &[nsStyleUnion; 8usize] {
|
||||
&self.mValues
|
||||
}
|
||||
pub unsafe fn get_mValues_mut(&mut self) -> &mut [nsStyleUnion; 8usize] {
|
||||
&mut self.mValues
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_nsStyleCorners() {
|
||||
|
|
|
@ -3,24 +3,29 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use bindings::{Gecko_ResetStyleCoord, Gecko_SetStyleCoordCalcValue, Gecko_AddRefCalcArbitraryThread};
|
||||
use std::mem::transmute;
|
||||
use structs::{nsStyleCoord_Calc, nsStyleUnit, nsStyleUnion, nsStyleCoord, nsStyleSides, nsStyleCorners};
|
||||
use structs::{nsStyleCoord_CalcValue, nscoord};
|
||||
|
||||
impl CoordData for nsStyleCoord {
|
||||
#[inline]
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
self.mUnit
|
||||
unsafe {
|
||||
*self.get_mUnit()
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
self.mValue
|
||||
unsafe {
|
||||
*self.get_mValue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CoordDataMut for nsStyleCoord {
|
||||
unsafe fn values_mut(&mut self) -> (&mut nsStyleUnit, &mut nsStyleUnion) {
|
||||
(&mut self.mUnit, &mut self.mValue)
|
||||
let unit = self.get_mUnit_mut() as *mut _;
|
||||
let value = self.get_mValue_mut() as *mut _;
|
||||
(&mut *unit, &mut *value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,26 +58,36 @@ pub struct SidesDataMut<'a> {
|
|||
impl<'a> CoordData for SidesData<'a> {
|
||||
#[inline]
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
self.sides.mUnits[self.index]
|
||||
unsafe {
|
||||
self.sides.get_mUnits()[self.index]
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
self.sides.mValues[self.index]
|
||||
unsafe {
|
||||
self.sides.get_mValues()[self.index]
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> CoordData for SidesDataMut<'a> {
|
||||
#[inline]
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
self.sides.mUnits[self.index]
|
||||
unsafe {
|
||||
self.sides.get_mUnits()[self.index]
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
self.sides.mValues[self.index]
|
||||
unsafe {
|
||||
self.sides.get_mValues()[self.index]
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> CoordDataMut for SidesDataMut<'a> {
|
||||
unsafe fn values_mut(&mut self) -> (&mut nsStyleUnit, &mut nsStyleUnion) {
|
||||
(&mut self.sides.mUnits[self.index], &mut self.sides.mValues[self.index])
|
||||
let unit = &mut self.sides.get_mUnits_mut()[self.index] as *mut _;
|
||||
let value = &mut self.sides.get_mValues_mut()[self.index] as *mut _;
|
||||
(&mut *unit, &mut *value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,23 +119,33 @@ pub struct CornersDataMut<'a> {
|
|||
|
||||
impl<'a> CoordData for CornersData<'a> {
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
self.corners.mUnits[self.index]
|
||||
unsafe {
|
||||
self.corners.get_mUnits()[self.index]
|
||||
}
|
||||
}
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
self.corners.mValues[self.index]
|
||||
unsafe {
|
||||
self.corners.get_mValues()[self.index]
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> CoordData for CornersDataMut<'a> {
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
self.corners.mUnits[self.index]
|
||||
unsafe {
|
||||
self.corners.get_mUnits()[self.index]
|
||||
}
|
||||
}
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
self.corners.mValues[self.index]
|
||||
unsafe {
|
||||
self.corners.get_mValues()[self.index]
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> CoordDataMut for CornersDataMut<'a> {
|
||||
unsafe fn values_mut(&mut self) -> (&mut nsStyleUnit, &mut nsStyleUnion) {
|
||||
(&mut self.corners.mUnits[self.index], &mut self.corners.mValues[self.index])
|
||||
let unit = &mut self.corners.get_mUnits_mut()[self.index] as *mut _;
|
||||
let value = &mut self.corners.get_mValues_mut()[self.index] as *mut _;
|
||||
(&mut *unit, &mut *value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,6 +204,13 @@ pub trait CoordDataMut : CoordData {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn copy_from_unchecked<T: CoordData>(&mut self, other: &T) {
|
||||
let (unit, union) = self.values_mut();
|
||||
*unit = other.unit();
|
||||
*union = other.union();
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn set_value(&mut self, value: CoordDataValue) {
|
||||
use self::CoordDataValue::*;
|
||||
|
@ -254,7 +286,7 @@ pub trait CoordDataMut : CoordData {
|
|||
#[inline]
|
||||
unsafe fn as_calc_mut(&mut self) -> &mut nsStyleCoord_Calc {
|
||||
debug_assert!(self.unit() == nsStyleUnit::eStyleUnit_Calc);
|
||||
transmute(*self.union().mPointer.as_mut() as *mut nsStyleCoord_Calc)
|
||||
&mut *(*self.union().mPointer.as_mut() as *mut nsStyleCoord_Calc)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -328,6 +360,6 @@ pub trait CoordData {
|
|||
#[inline]
|
||||
unsafe fn as_calc(&self) -> &nsStyleCoord_Calc {
|
||||
debug_assert!(self.unit() == nsStyleUnit::eStyleUnit_Calc);
|
||||
transmute(*self.union().mPointer.as_ref() as *const nsStyleCoord_Calc)
|
||||
&*(*self.union().mPointer.as_ref() as *const nsStyleCoord_Calc)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue