From 021937bca010027c9a7e1e7257615b23339ef57b Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 16 Oct 2014 05:03:24 -0400 Subject: [PATCH 1/3] embedding: fix string_list deallocation where I accidentally the whole string_list --- ports/cef/string_list.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index 8f2fec1d0c7..af7aa3207dd 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -22,8 +22,8 @@ pub extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t { pub extern "C" fn cef_string_list_size(lt: *const cef_string_list_t) -> c_int { unsafe { if fptr_is_null(mem::transmute(lt)) { return 0; } - let v: Box> = mem::transmute(lt); - v.len() as c_int + let v: *const Vec<*mut cef_string_t> = mem::transmute(lt); + (*v).len() as c_int } } @@ -31,10 +31,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) { unsafe { if fptr_is_null(mem::transmute(lt)) { return; } - let mut v: Box> = mem::transmute(lt); + let v: *const Vec<*mut cef_string_t> = mem::transmute(lt); let cs = cef_string_userfree_utf8_alloc(); cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1); - v.push(cs); + (*v).push(cs); } } @@ -43,8 +43,8 @@ pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int unsafe { if index < 0 || fptr_is_null(mem::transmute(lt)) { return 0; } let v: Box> = mem::transmute(lt); - if index as uint > v.len() - 1 { return 0; } - let cs = v.get(index as uint); + if index as uint > (*v).len() - 1 { return 0; } + let cs = (*v).get(index as uint); cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1) } } @@ -53,11 +53,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) { unsafe { if fptr_is_null(mem::transmute(lt)) { return; } - let mut v: Box> = mem::transmute(lt); - if v.len() == 0 { return; } + let v: *const Vec<*mut cef_string_t> = mem::transmute(lt); + if (*v).len() == 0 { return; } let mut cs; - while v.len() != 0 { - cs = v.pop(); + while (*v).len() != 0 { + cs = (*v).pop(); cef_string_userfree_utf8_free(cs.unwrap()); } } @@ -67,9 +67,9 @@ 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) { unsafe { if fptr_is_null(mem::transmute(lt)) { return; } - let mut v: Box> = mem::transmute(lt); + let v: *const Vec<*mut cef_string_t> = mem::transmute(lt); cef_string_list_clear(lt); - drop(v); + drop((*v)); } } @@ -79,7 +79,7 @@ pub extern "C" fn cef_string_list_copy(lt: *mut cef_string_list_t) -> *mut cef_s if fptr_is_null(mem::transmute(lt)) { return 0 as *mut cef_string_list_t; } let v: Box> = mem::transmute(lt); let lt2 = cef_string_list_alloc(); - for cs in v.iter() { + for cs in (*v).iter() { cef_string_list_append(lt2, mem::transmute((*cs))); } lt2 From 43cc865629fe086eb694bae94f49cb4c9c391a9f Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 23 Oct 2014 12:22:26 -0400 Subject: [PATCH 2/3] embedding: fix string_list compile errors? --- ports/cef/string_list.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index af7aa3207dd..a32cbdbcffd 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -19,10 +19,10 @@ pub extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t { } #[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 { if fptr_is_null(mem::transmute(lt)) { return 0; } - let v: *const Vec<*mut cef_string_t> = mem::transmute(lt); + let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); (*v).len() as c_int } } @@ -31,7 +31,7 @@ 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) { unsafe { if fptr_is_null(mem::transmute(lt)) { return; } - let v: *const Vec<*mut cef_string_t> = mem::transmute(lt); + let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); let cs = cef_string_userfree_utf8_alloc(); cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1); (*v).push(cs); @@ -42,7 +42,7 @@ 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 { unsafe { if index < 0 || fptr_is_null(mem::transmute(lt)) { return 0; } - let v: Box> = mem::transmute(lt); + let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); if index as uint > (*v).len() - 1 { return 0; } let cs = (*v).get(index as uint); cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1) @@ -53,7 +53,7 @@ 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) { unsafe { if fptr_is_null(mem::transmute(lt)) { return; } - let v: *const Vec<*mut cef_string_t> = mem::transmute(lt); + let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); if (*v).len() == 0 { return; } let mut cs; while (*v).len() != 0 { @@ -67,9 +67,9 @@ 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) { unsafe { if fptr_is_null(mem::transmute(lt)) { return; } - let v: *const Vec<*mut cef_string_t> = mem::transmute(lt); + let v: Box> = mem::transmute(lt); cef_string_list_clear(lt); - drop((*v)); + drop(v); } } @@ -77,7 +77,7 @@ 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 { unsafe { if fptr_is_null(mem::transmute(lt)) { return 0 as *mut cef_string_list_t; } - let v: Box> = mem::transmute(lt); + let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); let lt2 = cef_string_list_alloc(); for cs in (*v).iter() { cef_string_list_append(lt2, mem::transmute((*cs))); From 69e8de33e828679844a7ee43088a30f95fee2909 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 23 Oct 2014 12:24:48 -0400 Subject: [PATCH 3/3] embedding: add string_map_to_vec() to reduce transmute calls --- ports/cef/string_list.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index a32cbdbcffd..9c9994d4c16 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -8,6 +8,11 @@ use std::mem; 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}; + +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 #[no_mangle] @@ -22,7 +27,7 @@ pub extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t { pub extern "C" fn cef_string_list_size(lt: *mut cef_string_list_t) -> c_int { unsafe { if fptr_is_null(mem::transmute(lt)) { return 0; } - let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); + let v = string_map_to_vec(lt); (*v).len() as c_int } } @@ -31,7 +36,7 @@ pub extern "C" fn cef_string_list_size(lt: *mut 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) { unsafe { if fptr_is_null(mem::transmute(lt)) { return; } - let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); + let v = string_map_to_vec(lt); let cs = cef_string_userfree_utf8_alloc(); cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1); (*v).push(cs); @@ -42,7 +47,7 @@ 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 { unsafe { if index < 0 || fptr_is_null(mem::transmute(lt)) { return 0; } - let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); + let v = string_map_to_vec(lt); if index as uint > (*v).len() - 1 { return 0; } let cs = (*v).get(index as uint); cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1) @@ -53,7 +58,7 @@ 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) { unsafe { if fptr_is_null(mem::transmute(lt)) { return; } - let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); + let v = string_map_to_vec(lt); if (*v).len() == 0 { return; } let mut cs; while (*v).len() != 0 { @@ -77,7 +82,7 @@ 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 { unsafe { if fptr_is_null(mem::transmute(lt)) { return 0 as *mut cef_string_list_t; } - let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt); + let v = string_map_to_vec(lt); let lt2 = cef_string_list_alloc(); for cs in (*v).iter() { cef_string_list_append(lt2, mem::transmute((*cs)));