diff --git a/conversions.rs b/conversions.rs index 77031fb..9fe7de7 100644 --- a/conversions.rs +++ b/conversions.rs @@ -8,7 +8,7 @@ // except according to those terms. use wapcaplet::LwcString; -use wapcaplet::ll::lwc_string; +use wapcaplet::ll::{lwc_string, rust_lwc_string_ref}; use core::libc::{c_void, c_char}; use core::libc::types::common::c99::{uint32_t}; use core::cast::transmute; @@ -198,6 +198,7 @@ impl AsLl for CssStylesheetParams { extern fn resolve(_pw: *c_void, _base: *c_char, rel: *lwc_string, abs: *mut *lwc_string) -> css_error { unsafe { // TODO + rust_lwc_string_ref(rel); *abs = rel; } CSS_OK diff --git a/netsurfcss.rc b/netsurfcss.rc index 9784dbc..afa0137 100644 --- a/netsurfcss.rc +++ b/netsurfcss.rc @@ -15,6 +15,8 @@ extern mod std; extern mod wapcaplet; use core::libc::{c_void, size_t}; +use core::libc; +use core::ptr; use ll::errors::*; use errors::CssError; use util::VoidPtrLike; @@ -49,7 +51,15 @@ pub fn require_ok(code: css_error, what: &str) { } pub extern fn realloc(ptr: *c_void, len: size_t, _pw: *c_void) -> *c_void { - unsafe { libc::realloc(ptr, len) } + unsafe { + if len == 0 { + // Needed to prevent a memory leak on Mac. + libc::free(ptr); + ptr::null() + } else { + libc::realloc(ptr, len) + } + } } pub mod types { @@ -253,7 +263,9 @@ pub mod stylesheet { fn append_data(&mut self, data: &[u8]) { // FIXME: For some reason to_const_ptr isn't accessible - let code = unsafe { css_stylesheet_append_data(self.sheet, transmute(vec::raw::to_ptr(data)), data.len() as size_t) }; + let code = unsafe { + css_stylesheet_append_data(self.sheet, transmute(vec::raw::to_ptr(data)), data.len() as size_t) + }; match code { e if e == CSS_NEEDDATA => { /* fine */ }, _ => require_ok(code, "appending styleshet data") @@ -842,9 +854,12 @@ pub mod select { CSS_OK } } - pub extern fn node_is_focus(_pw: *c_void, _node: *c_void, _match_: *bool) -> css_error { + pub extern fn node_is_focus(_pw: *c_void, _node: *c_void, match_: *mut bool) -> css_error { unimpl_warn("node_is_focus"); - CSS_OK + unsafe { + *match_ = false; + CSS_OK + } } pub extern fn node_is_enabled(_pw: *c_void, _node: *c_void, _match_: *bool) -> css_error { unimpl("node_is_enabled") @@ -855,8 +870,12 @@ pub mod select { pub extern fn node_is_checked(_pw: *c_void, _node: *c_void, _match_: *bool) -> css_error { unimpl("node_is_checked") } - pub extern fn node_is_target(_pw: *c_void, _node: *c_void, _match_: *bool) -> css_error { - unimpl("node_is_target") + pub extern fn node_is_target(_pw: *c_void, _node: *c_void, match_: *mut bool) -> css_error { + unimpl_warn("node_is_target"); + unsafe { + *match_ = false; + CSS_OK + } } pub extern fn node_is_lang(_pw: *c_void, _node: *c_void, _lang: *lwc_string, match_: *mut bool) -> css_error { unimpl_warn("node_is_lang");