mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Remove usage of unstable feature "raw"
This commit is contained in:
parent
4727b92754
commit
e13ae77daf
4 changed files with 43 additions and 6 deletions
|
@ -44,7 +44,7 @@ use multicol::MulticolFlow;
|
||||||
use parallel::FlowParallelInfo;
|
use parallel::FlowParallelInfo;
|
||||||
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
use servo_geometry::{au_rect_to_f32_rect, f32_rect_to_au_rect, max_rect};
|
use servo_geometry::{au_rect_to_f32_rect, f32_rect_to_au_rect, max_rect};
|
||||||
use std::{fmt, mem, raw};
|
use std::{fmt, mem};
|
||||||
use std::iter::Zip;
|
use std::iter::Zip;
|
||||||
use std::slice::IterMut;
|
use std::slice::IterMut;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -453,7 +453,7 @@ pub trait Flow: fmt::Debug + Sync + Send + 'static {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn base<T: ?Sized + Flow>(this: &T) -> &BaseFlow {
|
pub fn base<T: ?Sized + Flow>(this: &T) -> &BaseFlow {
|
||||||
unsafe {
|
unsafe {
|
||||||
let obj = mem::transmute::<&&T, &raw::TraitObject>(&this);
|
let obj = mem::transmute::<&&T, &::TraitObject>(&this);
|
||||||
mem::transmute::<*mut (), &BaseFlow>(obj.data)
|
mem::transmute::<*mut (), &BaseFlow>(obj.data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -467,7 +467,7 @@ pub fn child_iter<'a>(flow: &'a Flow) -> FlowListIterator {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn mut_base<T: ?Sized + Flow>(this: &mut T) -> &mut BaseFlow {
|
pub fn mut_base<T: ?Sized + Flow>(this: &mut T) -> &mut BaseFlow {
|
||||||
unsafe {
|
unsafe {
|
||||||
let obj = mem::transmute::<&&mut T, &raw::TraitObject>(&this);
|
let obj = mem::transmute::<&&mut T, &::TraitObject>(&this);
|
||||||
mem::transmute::<*mut (), &mut BaseFlow>(obj.data)
|
mem::transmute::<*mut (), &mut BaseFlow>(obj.data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1422,7 +1422,7 @@ impl OpaqueFlow {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn from_flow(flow: &Flow) -> OpaqueFlow {
|
pub fn from_flow(flow: &Flow) -> OpaqueFlow {
|
||||||
unsafe {
|
unsafe {
|
||||||
let object = mem::transmute::<&Flow, raw::TraitObject>(flow);
|
let object = mem::transmute::<&Flow, ::TraitObject>(flow);
|
||||||
OpaqueFlow(object.data as usize)
|
OpaqueFlow(object.data as usize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
#![feature(raw)]
|
|
||||||
|
|
||||||
extern crate app_units;
|
extern crate app_units;
|
||||||
extern crate atomic_refcell;
|
extern crate atomic_refcell;
|
||||||
|
@ -92,3 +91,12 @@ pub use self::data::LayoutData;
|
||||||
// We can't use servo_arc for everything in layout, because the Flow stuff uses
|
// We can't use servo_arc for everything in layout, because the Flow stuff uses
|
||||||
// weak references.
|
// weak references.
|
||||||
use servo_arc::Arc as ServoArc;
|
use servo_arc::Arc as ServoArc;
|
||||||
|
|
||||||
|
/// Stable copy of std::raw::TraitObject
|
||||||
|
/// test/unit/layout/lib.rs asserts that the memory layout matches.
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct TraitObject {
|
||||||
|
pub data: *mut (),
|
||||||
|
pub vtable: *mut (),
|
||||||
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ googlevr = ["webvr/googlevr"]
|
||||||
oculusvr = ["webvr/oculusvr"]
|
oculusvr = ["webvr/oculusvr"]
|
||||||
unstable = [
|
unstable = [
|
||||||
"euclid/unstable",
|
"euclid/unstable",
|
||||||
"msg/unstable",
|
|
||||||
"gfx/unstable",
|
"gfx/unstable",
|
||||||
|
"msg/unstable",
|
||||||
"profile/unstable",
|
"profile/unstable",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,36 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#![feature(raw)]
|
||||||
|
|
||||||
extern crate layout;
|
extern crate layout;
|
||||||
#[macro_use] extern crate size_of_test;
|
#[macro_use] extern crate size_of_test;
|
||||||
|
|
||||||
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
|
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
|
||||||
|
|
||||||
|
use std::mem;
|
||||||
|
use std::ptr;
|
||||||
|
use std::raw;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_trait_object_layout() {
|
||||||
|
assert_eq!(mem::size_of::<raw::TraitObject>(), mem::size_of::<layout::TraitObject>());
|
||||||
|
let null: *mut () = ptr::null_mut();
|
||||||
|
let a = raw::TraitObject {
|
||||||
|
data: null,
|
||||||
|
vtable: null,
|
||||||
|
};
|
||||||
|
let b = layout::TraitObject {
|
||||||
|
data: null,
|
||||||
|
vtable: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn offset<T, U>(struct_: &T, field: &U) -> usize {
|
||||||
|
let addr_struct = struct_ as *const T as usize;
|
||||||
|
let addr_field = field as *const U as usize;
|
||||||
|
addr_field - addr_struct
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(offset(&a, &a.data), offset(&b, &b.data));
|
||||||
|
assert_eq!(offset(&a, &a.vtable), offset(&b, &b.vtable));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue