Remove unneeded unsafe blocks.

This commit is contained in:
Jack Moffitt 2013-04-22 20:15:46 -06:00
parent 4aec737c11
commit 868c7407a8
10 changed files with 276 additions and 301 deletions

View file

@ -125,7 +125,7 @@ impl FontHandleMethods for FontHandle {
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } {
default_weight
} 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 };
if valid {
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
// recursive structural types
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 x_scale = (metrics.x_ppem as float) / em_size as float;

View file

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

View file

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

View file

@ -202,10 +202,8 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj {
node.get_wrappercache().set_wrapper(obj.ptr);
unsafe {
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));
}
return obj;
}

View file

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

View file

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

View file

@ -224,7 +224,6 @@ pub fn parse_html(url: Url,
let url2 = url.clone(), url3 = url.clone();
unsafe {
// Build the root node.
let root = ~HTMLHtmlElement { parent: Element::new(HTMLHtmlElementTypeId, ~"html") };
let root = unsafe { Node::as_abstract_node(root) };
@ -329,9 +328,7 @@ pub fn parse_html(url: Url,
_ => {}
}
unsafe {
node.to_hubbub_node()
}
},
create_text: |data: ~str| {
debug!("create text");
@ -361,10 +358,8 @@ pub fn parse_html(url: Url,
},
clone_node: |_node, deep| {
debug!("clone node");
unsafe {
if deep { error!("-- deep clone unimplemented"); }
fail!(~"clone node unimplemented")
}
},
reparent_children: |_node, _new_parent| {
debug!("reparent children");
@ -435,6 +430,5 @@ pub fn parse_html(url: Url,
js_chan.send(JSTaskExit);
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 {
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 {
flow: flow,
range_stack: ~[]
@ -208,7 +208,7 @@ struct BuilderContext {
impl 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 {
default_collector: collector,
inline_collector: None,

View file

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