auto merge of #3785 : zmike/servo/embedding-fixups-for-string_list, r=larsbergstrom

r+ @jdm @larsbergstrom  ?
This commit is contained in:
bors-servo 2014-10-23 15:12:37 -06:00
commit 3c97438bdc

View file

@ -8,6 +8,11 @@ use std::mem;
use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set}; use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set};
use types::{cef_string_list_t,cef_string_t}; use types::{cef_string_list_t,cef_string_t};
fn string_map_to_vec(lt: *mut cef_string_list_t) -> *mut Vec<*mut cef_string_t> {
lt as *mut Vec<*mut cef_string_t>
}
//cef_string_list //cef_string_list
#[no_mangle] #[no_mangle]
@ -19,11 +24,11 @@ pub extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn cef_string_list_size(lt: *const cef_string_list_t) -> c_int { pub extern "C" fn cef_string_list_size(lt: *mut cef_string_list_t) -> c_int {
unsafe { unsafe {
if fptr_is_null(mem::transmute(lt)) { return 0; } if fptr_is_null(mem::transmute(lt)) { return 0; }
let v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); let v = string_map_to_vec(lt);
v.len() as c_int (*v).len() as c_int
} }
} }
@ -31,10 +36,10 @@ pub extern "C" fn cef_string_list_size(lt: *const cef_string_list_t) -> c_int {
pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *const cef_string_t) { pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *const cef_string_t) {
unsafe { unsafe {
if fptr_is_null(mem::transmute(lt)) { return; } if fptr_is_null(mem::transmute(lt)) { return; }
let mut v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); let v = string_map_to_vec(lt);
let cs = cef_string_userfree_utf8_alloc(); let cs = cef_string_userfree_utf8_alloc();
cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1); cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1);
v.push(cs); (*v).push(cs);
} }
} }
@ -42,9 +47,9 @@ pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *con
pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int, value: *mut cef_string_t) -> c_int { pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int, value: *mut cef_string_t) -> c_int {
unsafe { unsafe {
if index < 0 || fptr_is_null(mem::transmute(lt)) { return 0; } if index < 0 || fptr_is_null(mem::transmute(lt)) { return 0; }
let v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); let v = string_map_to_vec(lt);
if index as uint > v.len() - 1 { return 0; } if index as uint > (*v).len() - 1 { return 0; }
let cs = v.get(index as uint); let cs = (*v).get(index as uint);
cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1) cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1)
} }
} }
@ -53,11 +58,11 @@ pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int
pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) { pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) {
unsafe { unsafe {
if fptr_is_null(mem::transmute(lt)) { return; } if fptr_is_null(mem::transmute(lt)) { return; }
let mut v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); let v = string_map_to_vec(lt);
if v.len() == 0 { return; } if (*v).len() == 0 { return; }
let mut cs; let mut cs;
while v.len() != 0 { while (*v).len() != 0 {
cs = v.pop(); cs = (*v).pop();
cef_string_userfree_utf8_free(cs.unwrap()); cef_string_userfree_utf8_free(cs.unwrap());
} }
} }
@ -67,7 +72,7 @@ pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) {
pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) { pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) {
unsafe { unsafe {
if fptr_is_null(mem::transmute(lt)) { return; } if fptr_is_null(mem::transmute(lt)) { return; }
let mut v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); let v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt);
cef_string_list_clear(lt); cef_string_list_clear(lt);
drop(v); drop(v);
} }
@ -77,9 +82,9 @@ pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) {
pub extern "C" fn cef_string_list_copy(lt: *mut cef_string_list_t) -> *mut cef_string_list_t { pub extern "C" fn cef_string_list_copy(lt: *mut cef_string_list_t) -> *mut cef_string_list_t {
unsafe { unsafe {
if fptr_is_null(mem::transmute(lt)) { return 0 as *mut cef_string_list_t; } if fptr_is_null(mem::transmute(lt)) { return 0 as *mut cef_string_list_t; }
let v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); let v = string_map_to_vec(lt);
let lt2 = cef_string_list_alloc(); let lt2 = cef_string_list_alloc();
for cs in v.iter() { for cs in (*v).iter() {
cef_string_list_append(lt2, mem::transmute((*cs))); cef_string_list_append(lt2, mem::transmute((*cs)));
} }
lt2 lt2