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

Remove unused unsafe #396

Merged
merged 2 commits into from Apr 23, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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;
@@ -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
}
@@ -74,21 +74,19 @@ 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;
assert!(glyph_infos.is_not_null());
let pos_count = 0;
let pos_infos = hb_buffer_get_glyph_positions(buffer, &pos_count);
assert!(pos_infos.is_not_null());
assert!(glyph_count == pos_count as uint);

ShapedGlyphData {
count: glyph_count,
glyph_infos: glyph_infos,
pos_infos: pos_infos,
}
let glyph_count = 0;
let glyph_infos = hb_buffer_get_glyph_infos(buffer, &glyph_count);
let glyph_count = glyph_count as uint;
assert!(glyph_infos.is_not_null());
let pos_count = 0;
let pos_infos = hb_buffer_get_glyph_positions(buffer, &pos_count);
assert!(pos_infos.is_not_null());
assert!(glyph_count == pos_count as uint);

ShapedGlyphData {
count: glyph_count,
glyph_infos: glyph_infos,
pos_infos: pos_infos,
}
}

@@ -167,35 +165,33 @@ 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,
null());
let hb_font: *hb_font_t = hb_font_create(hb_face);

// Set points-per-em. if zero, performs no hinting in that direction.
let pt_size = font.style.pt_size;
hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint);

// Set scaling. Note that this takes 16.16 fixed point.
hb_font_set_scale(hb_font,
Shaper::float_to_fixed(pt_size) as c_int,
Shaper::float_to_fixed(pt_size) as c_int);

// configure static function callbacks.
// NB. This funcs structure could be reused globally, as it never changes.
let hb_funcs: *hb_font_funcs_t = hb_font_funcs_create();
hb_font_funcs_set_glyph_func(hb_funcs, glyph_func, null(), null());
hb_font_funcs_set_glyph_h_advance_func(hb_funcs, glyph_h_advance_func, null(), null());
hb_font_set_funcs(hb_font, hb_funcs, font_ptr as *c_void, null());

Shaper {
font: font,
hb_face: hb_face,
hb_font: hb_font,
hb_funcs: hb_funcs,
}
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,
null());
let hb_font: *hb_font_t = hb_font_create(hb_face);

// Set points-per-em. if zero, performs no hinting in that direction.
let pt_size = font.style.pt_size;
hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint);

// Set scaling. Note that this takes 16.16 fixed point.
hb_font_set_scale(hb_font,
Shaper::float_to_fixed(pt_size) as c_int,
Shaper::float_to_fixed(pt_size) as c_int);

// configure static function callbacks.
// NB. This funcs structure could be reused globally, as it never changes.
let hb_funcs: *hb_font_funcs_t = hb_font_funcs_create();
hb_font_funcs_set_glyph_func(hb_funcs, glyph_func, null(), null());
hb_font_funcs_set_glyph_h_advance_func(hb_funcs, glyph_h_advance_func, null(), null());
hb_font_set_funcs(hb_font, hb_funcs, font_ptr as *c_void, null());

Shaper {
font: font,
hb_face: hb_face,
hb_font: hb_font,
hb_funcs: hb_funcs,
}
}

@@ -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
}
JS_GetContextPrivate(cx) as *mut Content
}

#[allow(non_implicitly_copyable_typarams)]
@@ -2142,7 +2142,7 @@ def __init__(self, descriptors, dictionaries, declareImports, defineImports, chi
# TODO imports to cover descriptors, etc.

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,
declarePre=_useString(sorted(declareImports)))

@@ -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));
}
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;
}
@@ -372,38 +372,36 @@ 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,
protoClass, methods,
properties, constants);
if proto.is_null() {
return ptr::null();
}

JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
RUST_PRIVATE_TO_JSVAL(domClass as *libc::c_void));
let mut proto = ptr::null();
if protoClass.is_not_null() {
proto = CreateInterfacePrototypeObject(cx, global, protoProto,
protoClass, methods,
properties, constants);
if proto.is_null() {
return ptr::null();
}

let mut interface = ptr::null();
if constructorClass.is_not_null() || constructor.is_not_null() {
interface = do str::as_c_str(name) |s| {
CreateInterfaceObject(cx, global, receiver, constructorClass,
constructor, ctorNargs, proto,
staticMethods, constants, s)
};
if interface.is_null() {
return ptr::null();
}
}
JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
RUST_PRIVATE_TO_JSVAL(domClass as *libc::c_void));
}

if protoClass.is_not_null() {
proto
} else {
interface
let mut interface = ptr::null();
if constructorClass.is_not_null() || constructor.is_not_null() {
interface = do str::as_c_str(name) |s| {
CreateInterfaceObject(cx, global, receiver, constructorClass,
constructor, ctorNargs, proto,
staticMethods, constants, s)
};
if interface.is_null() {
return ptr::null();
}
}

if protoClass.is_not_null() {
proto
} 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 {
@@ -335,18 +335,13 @@ 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)
}
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())
}
fmt!("%?", self.type_id())
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.