Merge pull request #396 from metajack/remove-unused-unsafe

Remove unused unsafe
This commit is contained in:
Brian Anderson 2013-04-22 19:30:31 -07:00
commit df598a7f1e
11 changed files with 277 additions and 302 deletions

View file

@ -125,7 +125,7 @@ impl FontHandleMethods for FontHandle {
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } { if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } {
default_weight default_weight
} else { } else {
let os2 = unsafe { FT_Get_Sfnt_Table(self.face, ft_sfnt_os2) as *TT_OS2 }; let os2 = FT_Get_Sfnt_Table(self.face, ft_sfnt_os2) as *TT_OS2;
let valid = os2.is_not_null() && unsafe { (*os2).version != 0xffff }; let valid = os2.is_not_null() && unsafe { (*os2).version != 0xffff };
if valid { if valid {
let weight = unsafe { (*os2).usWeightClass }; let weight = unsafe { (*os2).usWeightClass };
@ -283,7 +283,7 @@ pub impl<'self> FontHandle {
// face.size is a *c_void in the bindings, presumably to avoid // face.size is a *c_void in the bindings, presumably to avoid
// recursive structural types // recursive structural types
let size: &FT_SizeRec = unsafe { cast::transmute(&(*face.size)) }; let size: &FT_SizeRec = unsafe { cast::transmute(&(*face.size)) };
let metrics: &FT_Size_Metrics = unsafe { &((*size).metrics) }; let metrics: &FT_Size_Metrics = &(*size).metrics;
let em_size = face.units_per_EM as float; let em_size = face.units_per_EM as float;
let x_scale = (metrics.x_ppem as float) / em_size as float; let x_scale = (metrics.x_ppem as float) / em_size as float;

View file

@ -54,7 +54,7 @@ pub enum ImageResponseMsg {
impl ImageResponseMsg { impl ImageResponseMsg {
fn clone(&self) -> ImageResponseMsg { fn clone(&self) -> ImageResponseMsg {
match *self { match *self {
ImageReady(ref img) => ImageReady(unsafe { clone_arc(img) }), ImageReady(ref img) => ImageReady(clone_arc(img)),
ImageNotReady => ImageNotReady, ImageNotReady => ImageNotReady,
ImageFailed => ImageFailed ImageFailed => ImageFailed
} }

View file

@ -74,7 +74,6 @@ pub struct ShapedGlyphEntry {
impl ShapedGlyphData { impl ShapedGlyphData {
pub fn new(buffer: *hb_buffer_t) -> ShapedGlyphData { pub fn new(buffer: *hb_buffer_t) -> ShapedGlyphData {
unsafe {
let glyph_count = 0; let glyph_count = 0;
let glyph_infos = hb_buffer_get_glyph_infos(buffer, &glyph_count); let glyph_infos = hb_buffer_get_glyph_infos(buffer, &glyph_count);
let glyph_count = glyph_count as uint; let glyph_count = glyph_count as uint;
@ -90,7 +89,6 @@ impl ShapedGlyphData {
pos_infos: pos_infos, pos_infos: pos_infos,
} }
} }
}
#[inline(always)] #[inline(always)]
fn byte_offset_of_glyph(&self, i: uint) -> uint { fn byte_offset_of_glyph(&self, i: uint) -> uint {
@ -167,7 +165,6 @@ impl Drop for Shaper {
impl Shaper { impl Shaper {
pub fn new(font: @mut Font) -> Shaper { pub fn new(font: @mut Font) -> Shaper {
unsafe {
let font_ptr: *mut Font = &mut *font; let font_ptr: *mut Font = &mut *font;
let hb_face: *hb_face_t = hb_face_create_for_tables(get_font_table_func, let hb_face: *hb_face_t = hb_face_create_for_tables(get_font_table_func,
font_ptr as *c_void, font_ptr as *c_void,
@ -197,7 +194,6 @@ impl Shaper {
hb_funcs: hb_funcs, hb_funcs: hb_funcs,
} }
} }
}
fn float_to_fixed(f: float) -> i32 { fn float_to_fixed(f: float) -> i32 {
float_to_fixed(16, f) float_to_fixed(16, f)

View file

@ -156,9 +156,7 @@ pub fn Content(layout_task: LayoutTask,
} }
pub fn task_from_context(cx: *JSContext) -> *mut Content { pub fn task_from_context(cx: *JSContext) -> *mut Content {
unsafe {
JS_GetContextPrivate(cx) as *mut Content JS_GetContextPrivate(cx) as *mut Content
}
} }
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]

View file

@ -2142,7 +2142,7 @@ class CGImports(CGWrapper):
# TODO imports to cover descriptors, etc. # TODO imports to cover descriptors, etc.
def _useString(imports): def _useString(imports):
return '#[allow(unused_imports,unused_variable)];' + ''.join(['use %s;\n' % i for i in imports]) + '\n' return '#[allow(unused_imports,unused_variable,unused_unsafe)];' + ''.join(['use %s;\n' % i for i in imports]) + '\n'
CGWrapper.__init__(self, child, CGWrapper.__init__(self, child,
declarePre=_useString(sorted(declareImports))) declarePre=_useString(sorted(declareImports)))

View file

@ -202,10 +202,8 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj {
node.get_wrappercache().set_wrapper(obj.ptr); node.get_wrappercache().set_wrapper(obj.ptr);
unsafe {
let raw_ptr = ptr::addr_of(node) as *libc::c_void; let raw_ptr = ptr::addr_of(node) as *libc::c_void;
JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr)); JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
}
return obj; return obj;
} }

View file

@ -372,7 +372,6 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
constants: *ConstantSpec, constants: *ConstantSpec,
staticMethods: *JSFunctionSpec, staticMethods: *JSFunctionSpec,
name: &str) -> *JSObject { name: &str) -> *JSObject {
unsafe {
let mut proto = ptr::null(); let mut proto = ptr::null();
if protoClass.is_not_null() { if protoClass.is_not_null() {
proto = CreateInterfacePrototypeObject(cx, global, protoProto, proto = CreateInterfacePrototypeObject(cx, global, protoProto,
@ -403,7 +402,6 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
} else { } else {
interface interface
} }
}
} }
fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject, fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
@ -412,7 +410,6 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
staticMethods: *JSFunctionSpec, staticMethods: *JSFunctionSpec,
constants: *ConstantSpec, constants: *ConstantSpec,
name: *libc::c_char) -> *JSObject { name: *libc::c_char) -> *JSObject {
unsafe {
let constructor = if constructorClass.is_not_null() { let constructor = if constructorClass.is_not_null() {
let functionProto = JS_GetFunctionPrototype(cx, global); let functionProto = JS_GetFunctionPrototype(cx, global);
if functionProto.is_null() { if functionProto.is_null() {
@ -482,7 +479,6 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
} }
return constructor; return constructor;
}
} }
fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> bool { fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> bool {
@ -506,11 +502,11 @@ fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) ->
} }
fn DefineMethods(cx: *JSContext, obj: *JSObject, methods: *JSFunctionSpec) -> bool { fn DefineMethods(cx: *JSContext, obj: *JSObject, methods: *JSFunctionSpec) -> bool {
unsafe { JS_DefineFunctions(cx, obj, methods) != 0 } JS_DefineFunctions(cx, obj, methods) != 0
} }
fn DefineProperties(cx: *JSContext, obj: *JSObject, properties: *JSPropertySpec) -> bool { fn DefineProperties(cx: *JSContext, obj: *JSObject, properties: *JSPropertySpec) -> bool {
unsafe { JS_DefineProperties(cx, obj, properties) != 0 } JS_DefineProperties(cx, obj, properties) != 0
} }
fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject, fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject,
@ -571,7 +567,7 @@ pub impl WrapperCache {
} }
fn set_wrapper(&mut self, wrapper: *JSObject) { fn set_wrapper(&mut self, wrapper: *JSObject) {
unsafe { self.wrapper = wrapper; } self.wrapper = wrapper;
} }
fn new() -> WrapperCache { fn new() -> WrapperCache {

View file

@ -335,19 +335,14 @@ impl DebugMethods for AbstractNode {
debug!("%s", s); debug!("%s", s);
// FIXME: this should have a pure version? // FIXME: this should have a pure version?
unsafe {
for self.each_child() |kid| { for self.each_child() |kid| {
kid.dump_indent(indent + 1u) kid.dump_indent(indent + 1u)
} }
} }
}
fn debug_str(&self) -> ~str { fn debug_str(&self) -> ~str {
// Unsafe due to the call to type_id().
unsafe {
fmt!("%?", self.type_id()) fmt!("%?", self.type_id())
} }
}
} }
impl Node { impl Node {

View file

@ -224,7 +224,6 @@ pub fn parse_html(url: Url,
let url2 = url.clone(), url3 = url.clone(); let url2 = url.clone(), url3 = url.clone();
unsafe {
// Build the root node. // Build the root node.
let root = ~HTMLHtmlElement { parent: Element::new(HTMLHtmlElementTypeId, ~"html") }; let root = ~HTMLHtmlElement { parent: Element::new(HTMLHtmlElementTypeId, ~"html") };
let root = unsafe { Node::as_abstract_node(root) }; let root = unsafe { Node::as_abstract_node(root) };
@ -329,9 +328,7 @@ pub fn parse_html(url: Url,
_ => {} _ => {}
} }
unsafe {
node.to_hubbub_node() node.to_hubbub_node()
}
}, },
create_text: |data: ~str| { create_text: |data: ~str| {
debug!("create text"); debug!("create text");
@ -361,10 +358,8 @@ pub fn parse_html(url: Url,
}, },
clone_node: |_node, deep| { clone_node: |_node, deep| {
debug!("clone node"); debug!("clone node");
unsafe {
if deep { error!("-- deep clone unimplemented"); } if deep { error!("-- deep clone unimplemented"); }
fail!(~"clone node unimplemented") fail!(~"clone node unimplemented")
}
}, },
reparent_children: |_node, _new_parent| { reparent_children: |_node, _new_parent| {
debug!("reparent children"); debug!("reparent children");
@ -435,6 +430,5 @@ pub fn parse_html(url: Url,
js_chan.send(JSTaskExit); js_chan.send(JSTaskExit);
return HtmlParserResult { root: root, style_port: css_port, js_port: js_port }; return HtmlParserResult { root: root, style_port: css_port, js_port: js_port };
}
} }

View file

@ -83,7 +83,7 @@ priv fn simulate_UA_display_rules(node: AbstractNode) -> CSSDisplay {
impl BoxGenerator { impl BoxGenerator {
fn new(flow: @mut FlowContext) -> BoxGenerator { fn new(flow: @mut FlowContext) -> BoxGenerator {
unsafe { debug!("Creating box generator for flow: %s", flow.debug_str()); } debug!("Creating box generator for flow: %s", flow.debug_str());
BoxGenerator { BoxGenerator {
flow: flow, flow: flow,
range_stack: ~[] range_stack: ~[]
@ -208,7 +208,7 @@ struct BuilderContext {
impl BuilderContext { impl BuilderContext {
fn new(collector: @mut BoxGenerator) -> BuilderContext { fn new(collector: @mut BoxGenerator) -> BuilderContext {
unsafe { debug!("Creating new BuilderContext for flow: %s", collector.flow.debug_str()); } debug!("Creating new BuilderContext for flow: %s", collector.flow.debug_str());
BuilderContext { BuilderContext {
default_collector: collector, default_collector: collector,
inline_collector: None, inline_collector: None,

View file

@ -279,12 +279,10 @@ impl BoxedMutDebugMethods for FlowContext {
debug!("%s", s); debug!("%s", s);
// FIXME: this should have a pure/const version? // FIXME: this should have a pure/const version?
unsafe {
for FlowTree.each_child(self) |child| { for FlowTree.each_child(self) |child| {
child.dump_indent(indent + 1u) child.dump_indent(indent + 1u)
} }
} }
}
fn debug_str(@mut self) -> ~str { fn debug_str(@mut self) -> ~str {
let repr = match *self { let repr = match *self {