Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest Rust #435

Merged
merged 10 commits into from May 10, 2013
Submodule rust updated from 9d966a to d54649
@@ -25,6 +25,6 @@ pub struct LayerBufferSet {
/// submit them to be drawn to the display.
pub trait Compositor {
fn begin_drawing(&self, next_dt: comm::Chan<LayerBufferSet>);
fn draw(&self, next_dt: comm::Chan<LayerBufferSet>, +draw_me: LayerBufferSet);
fn draw(&self, next_dt: comm::Chan<LayerBufferSet>, draw_me: LayerBufferSet);
}

@@ -386,7 +386,7 @@ pub impl Font {
advance += glyph.advance();
}
let bounds = Rect(Point2D(Au(0), -self.metrics.ascent),
Size2D(advance, self.metrics.ascent + self.metrics.descent));
Size2D(advance, self.metrics.ascent + self.metrics.descent));

// TODO(Issue #125): support loose and tight bounding boxes; using the
// ascent+descent and advance is sometimes too generous and
@@ -96,10 +96,9 @@ impl FontFamily {
}

fn load_family_variations(@mut self, list: &FontListHandle) {
let this : &mut FontFamily = self; // FIXME: borrow checker workaround
if this.entries.len() > 0 { return; }
if self.entries.len() > 0 { return; }
list.load_variations_for_family(self);
assert!(this.entries.len() > 0);
assert!(self.entries.len() > 0);
}

pub fn find_font_for_style(@mut self, list: &FontListHandle, style: &SpecifiedFontStyle)
@@ -22,8 +22,8 @@ impl Mul<Au,Au> for Au {
fn mul(&self, other: &Au) -> Au { Au(**self * **other) }
}

impl Quot<Au,Au> for Au {
fn quot(&self, other: &Au) -> Au { Au(**self / **other) }
impl Div<Au,Au> for Au {
fn div(&self, other: &Au) -> Au { Au(**self / **other) }
}

impl Rem<Au,Au> for Au {
@@ -16,7 +16,7 @@ use geometry::Au;
use platform::macos::font_context::FontContextHandle;
use text::glyph::GlyphIndex;

use core_foundation::base::{CFIndex, CFWrapper};
use core_foundation::base::CFIndex;
use core_foundation::data::CFData;
use core_foundation::string::UniChar;
use core_graphics::data_provider::CGDataProvider;
@@ -106,7 +106,7 @@ impl FontHandleMethods for FontHandle {

fn boldness(&self) -> CSSFontWeight {
// -1.0 to 1.0
let normalized = unsafe { self.ctfont.all_traits().normalized_weight() };
let normalized = self.ctfont.all_traits().normalized_weight();
// 0.0 to 9.0
let normalized = (normalized + 1.0) / 2.0 * 9.0;
if normalized < 1.0 { return FontWeight100; }
@@ -146,13 +146,11 @@ impl FontHandleMethods for FontHandle {

fn glyph_h_advance(&self, glyph: GlyphIndex) -> Option<FractionalPixel> {
let glyphs = [glyph as CGGlyph];
unsafe {
let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation,
&glyphs[0],
ptr::null(),
1);
return Some(advance as FractionalPixel);
}
let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation,
&glyphs[0],
ptr::null(),
1);
Some(advance as FractionalPixel)
}

fn get_metrics(&self) -> FontMetrics {
@@ -42,11 +42,9 @@ pub impl FontListHandle {
}

fn load_variations_for_family(&self, family: @mut FontFamily) {
let fam: &mut FontFamily = family; // FIXME: borrow checker workaround
let family_name = &fam.family_name;
debug!("Looking for faces of family: %s", *family_name);
debug!("Looking for faces of family: %s", family.family_name);

let family_collection = core_text::font_collection::create_for_family(*family_name);
let family_collection = core_text::font_collection::create_for_family(family.family_name);
for family_collection.get_descriptors().each |descref: &CTFontDescriptorRef| {
let desc = CFWrapper::wrap_shared(*descref);
let font = core_text::font::new_from_descriptor(&desc, 0.0);
@@ -373,20 +373,13 @@ impl ImageCache {
}

priv fn purge_waiters(&self, url: Url, f: &fn() -> ImageResponseMsg) {
match self.wait_map.find(&url) {
Some(waiters) => {
let waiters = *waiters;
let mut new_waiters = ~[];
new_waiters <-> *waiters;

for new_waiters.each |response| {
response.send(f());
match self.wait_map.pop(&url) {
Some(waiters) => {
for waiters.each |response| {
response.send(f());
}
}

*waiters <-> new_waiters;
self.wait_map.remove(&url);
}
None => ()
None => ()
}
}

@@ -410,13 +403,11 @@ impl ImageCache {

Prefetching(DoDecode) | Decoding => {
// We don't have this image yet
match self.wait_map.find(&url) {
Some(waiters) => {
vec::push(*waiters, response);
}
None => {
self.wait_map.insert(url, @mut ~[response]);
}
if self.wait_map.contains_key(&url) {
let waiters = self.wait_map.find_mut(&url).unwrap();
waiters.push(response);
} else {
self.wait_map.insert(url, @mut ~[response]);
}
}

@@ -76,12 +76,9 @@ pub impl LocalImageCache {

match state.last_response {
ImageReady(ref image) => {
// FIXME: appease borrowck
unsafe {
let (port, chan) = comm::stream();
chan.send(ImageReady(clone_arc(image)));
return port;
}
let (port, chan) = comm::stream();
chan.send(ImageReady(clone_arc(image)));
return port;
}
ImageNotReady => {
if last_round == self.round_number {
@@ -138,18 +135,14 @@ pub impl LocalImageCache {
}

priv fn get_state(&self, url: &Url) -> @mut ImageState {
match self.state_map.find(url) {
Some(state) => *state,
None => {
let new_state = @mut ImageState {
prefetched: false,
decoded: false,
last_request_round: 0,
last_response: ImageNotReady
};
self.state_map.insert(copy *url, new_state);
self.get_state(url)
}
*do self.state_map.find_or_insert_with(url.clone()) |_| {
let new_state = @mut ImageState {
prefetched: false,
decoded: false,
last_request_round: 0,
last_response: ImageNotReady
};
new_state
}
}
}
@@ -17,7 +17,7 @@ Create a URL object from a string. Does various helpful browsery things like
*/
#[allow(non_implicitly_copyable_typarams)]
pub fn make_url(str_url: ~str, current_url: Option<Url>) -> Url {
let mut schm = url::get_scheme(str_url);
let schm = url::get_scheme(str_url);
let str_url = if result::is_err(&schm) {
if current_url.is_none() {
// Assume we've been given a file path. If it's absolute just return
@@ -288,7 +288,10 @@ fn Surface(backend: BackendType) -> Surface {
/// A function for spawning into the platform's main thread.
fn on_osmain<T: Owned>(f: ~fn(po: Port<T>)) -> Chan<T> {
let (setup_po, setup_ch) = comm::stream();
do task::task().sched_mode(task::PlatformThread).spawn {
// FIXME: rust#6399
let mut main_task = task::task();
main_task.sched_mode(task::PlatformThread);
do main_task.spawn {
let (po, ch) = comm::stream();
setup_ch.send(ch);
f(po);
@@ -65,7 +65,10 @@ pub fn ContentTask(layout_task: LayoutTask,
let dom_event_port = Cell(dom_event_port);
let dom_event_chan = Cell(dom_event_chan);

do task().sched_mode(SingleThreaded).spawn {
// FIXME: rust#6399
let mut the_task = task();
the_task.sched_mode(SingleThreaded);
do the_task.spawn {
let content = Content(layout_task.clone(),
control_port.take(),
control_chan_copy.clone(),
@@ -150,7 +153,7 @@ pub fn Content(layout_task: LayoutTask,
};

cx.set_cx_private(ptr::to_unsafe_ptr(&*content) as *());
unsafe { task::local_data::local_data_set(global_content_key, cast::transmute(content)); }
unsafe { local_data::local_data_set(global_content_key, cast::transmute(content)); }

content
}
@@ -159,7 +162,7 @@ fn global_content_key(_: @Content) {}

pub fn global_content() -> @Content {
unsafe {
return task::local_data::local_data_get(global_content_key).get();
return local_data::local_data_get(global_content_key).get();
}
}

@@ -170,7 +173,7 @@ pub fn task_from_context(cx: *JSContext) -> *mut Content {
#[unsafe_destructor]
impl Drop for Content {
fn finalize(&self) {
unsafe { task::local_data::local_data_pop(global_content_key) };
unsafe { local_data::local_data_pop(global_content_key) };
}
}

@@ -183,7 +186,7 @@ pub impl Content {
}

fn handle_msg(&mut self) -> bool {
match select2i(&self.control_port, &self.event_port) {
match select2i(&mut self.control_port, &mut self.event_port) {
either::Left(*) => {
let msg = self.control_port.recv();
self.handle_control_msg(msg)
@@ -608,8 +608,8 @@ pub fn WrapNewBindingObject(cx: *JSContext, scope: *JSObject,
mut value: @mut CacheableWrapper,
vp: *mut JSVal) -> bool {
unsafe {
let mut cache = value.get_wrappercache();
let mut obj = cache.get_wrapper();
let cache = value.get_wrappercache();
let obj = cache.get_wrapper();
if obj.is_not_null() /*&& js::GetObjectCompartment(obj) == js::GetObjectCompartment(scope)*/ {
*vp = RUST_OBJECT_TO_JSVAL(obj);
return true;
@@ -65,14 +65,12 @@ impl BlockLayout for FlowContext {
fn with_block_box(&self, callback: &fn(box: RenderBox) -> ()) -> () {
match *self {
BlockFlow(*) => {
let box = self.block().box;
for box.each |&b| {
for self.block().box.each |&b| {
callback(b);
}
},
RootFlow(*) => {
let mut box = self.root().box;
for box.each |&b| {
for self.root().box.each |&b| {
callback(b);
}
},
@@ -30,7 +30,7 @@ use servo_net::image::holder::ImageHolder;
use servo_net::local_image_cache::LocalImageCache;
use servo_util::range::*;
use std::arc;
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use std::net::url::Url;

/// Render boxes (`struct RenderBox`) are the leaves of the layout tree. They cannot position
@@ -168,15 +168,12 @@ pub impl RenderBox {
match *self {
GenericRenderBoxClass(generic_box) => callback(generic_box),
ImageRenderBoxClass(image_box) => {
let image_box = &*image_box; // FIXME: Borrow check workaround.
callback(&image_box.base)
}
TextRenderBoxClass(text_box) => {
let text_box = &*text_box; // FIXME: Borrow check workaround.
callback(&text_box.base)
}
UnscannedTextRenderBoxClass(unscanned_text_box) => {
let unscanned_text_box = &*unscanned_text_box; // FIXME: Borrow check workaround.
callback(&unscanned_text_box.base)
}
}
@@ -188,16 +185,12 @@ pub impl RenderBox {
match *self {
GenericRenderBoxClass(generic_box) => callback(generic_box),
ImageRenderBoxClass(image_box) => {
let image_box = &mut *image_box; // FIXME: Borrow check workaround.
callback(&mut image_box.base)
}
TextRenderBoxClass(text_box) => {
let text_box = &mut *text_box; // FIXME: Borrow check workaround.
callback(&mut text_box.base)
}
UnscannedTextRenderBoxClass(unscanned_text_box) => {
// FIXME: Borrow check workaround.
let unscanned_text_box = &mut *unscanned_text_box;
callback(&mut unscanned_text_box.base)
}
}
@@ -238,7 +231,6 @@ pub impl RenderBox {
fn is_whitespace_only(&self) -> bool {
match *self {
UnscannedTextRenderBoxClass(unscanned_text_box) => {
let mut unscanned_text_box = &mut *unscanned_text_box; // FIXME: Borrow check.
unscanned_text_box.text.is_whitespace()
}
_ => false
@@ -269,8 +261,6 @@ pub impl RenderBox {
}

TextRenderBoxClass(text_box) => {
let text_box = &mut *text_box; // FIXME: Borrow check.

let mut pieces_processed_count: uint = 0;
let mut remaining_width: Au = max_width;
let mut left_range = Range::new(text_box.text_data.range.begin(), 0);
@@ -379,7 +369,6 @@ pub impl RenderBox {
}

TextRenderBoxClass(text_box) => {
let mut text_box = &mut *text_box; // FIXME: Borrow check.
text_box.text_data.run.min_width_for_range(&text_box.text_data.range)
}

@@ -401,8 +390,6 @@ pub impl RenderBox {
}

TextRenderBoxClass(text_box) => {
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.

// A text box cannot span lines, so assume that this is an unsplit text box.
//
// TODO: If text boxes have been split to wrap lines, then they could report a
@@ -567,8 +554,6 @@ pub impl RenderBox {
match *self {
UnscannedTextRenderBoxClass(*) => fail!(~"Shouldn't see unscanned boxes here."),
TextRenderBoxClass(text_box) => {
let text_box = &mut *text_box; // FIXME: Borrow check bug.

let nearest_ancestor_element = self.nearest_ancestor_element();
let color = nearest_ancestor_element.style().color().to_gfx_color();

@@ -650,7 +635,7 @@ pub impl RenderBox {
let nearest_ancestor_element = self.nearest_ancestor_element();

let bgcolor = nearest_ancestor_element.style().background_color();
if !bgcolor.alpha.fuzzy_eq(&0.0) {
if !bgcolor.alpha.approx_eq(&0.0) {
let mut l = list.take(); // FIXME: use with_mut_ref when available
l.append_item(~DisplayItem::new_SolidColor(absolute_bounds, bgcolor.to_gfx_color()));
list.put_back(l);
@@ -783,13 +768,11 @@ impl DebugMethods for RenderBox {
GenericRenderBoxClass(*) => ~"GenericRenderBox",
ImageRenderBoxClass(*) => ~"ImageRenderBox",
TextRenderBoxClass(text_box) => {
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.
fmt!("TextRenderBox(text=%s)", str::substr(text_box.text_data.run.text,
text_box.text_data.range.begin(),
text_box.text_data.range.length()))
}
UnscannedTextRenderBoxClass(text_box) => {
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.
fmt!("UnscannedTextRenderBox(%s)", text_box.text)
}
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.