mirror of
https://github.com/servo/servo.git
synced 2025-07-19 13:23:46 +01:00
embedding: remove eutil::fptr_is_null, fix #3967, add Option<> to fptrs
This commit is contained in:
parent
85a2f0b66a
commit
d33f74f499
7 changed files with 213 additions and 222 deletions
|
@ -35,7 +35,7 @@ pub fn command_line_init(argc: c_int, argv: *const *const u8) {
|
|||
let cl = command_line_new();
|
||||
(*cl).argc = argc;
|
||||
(*cl).argv = a;
|
||||
(*cl).cl.get_switch_value = command_line_get_switch_value;
|
||||
(*cl).cl.get_switch_value = Some(command_line_get_switch_value);
|
||||
GLOBAL_CMDLINE = Some(cl);
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ pub extern "C" fn command_line_get_switch_value(cmd: *mut cef_command_line_t, na
|
|||
pub extern "C" fn cef_command_line_create() -> *mut cef_command_line_t {
|
||||
unsafe {
|
||||
let cl = command_line_new();
|
||||
(*cl).cl.get_switch_value = command_line_get_switch_value;
|
||||
(*cl).cl.get_switch_value = Some(command_line_get_switch_value);
|
||||
mem::transmute(cl)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,12 @@
|
|||
|
||||
|
||||
use command_line::command_line_init;
|
||||
use eutil::fptr_is_null;
|
||||
use geom::size::TypedSize2D;
|
||||
use glfw_app;
|
||||
use libc::{c_int, c_void};
|
||||
use native;
|
||||
use servo::Browser;
|
||||
use servo_util::opts;
|
||||
use std::mem;
|
||||
use types::{cef_app_t, cef_main_args_t, cef_settings_t};
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -25,15 +23,13 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t,
|
|||
}
|
||||
unsafe {
|
||||
command_line_init((*args).argc, (*args).argv);
|
||||
let cb = (*application).get_browser_process_handler;
|
||||
if !fptr_is_null(mem::transmute(cb)) {
|
||||
let handler = cb(application);
|
||||
if handler.is_not_null() {
|
||||
let hcb = (*handler).on_context_initialized;
|
||||
if !fptr_is_null(mem::transmute(hcb)) {
|
||||
hcb(handler);
|
||||
}
|
||||
}
|
||||
if !(*application).get_browser_process_handler.is_some() { return 1; }
|
||||
let cb = (*application).get_browser_process_handler.unwrap();
|
||||
let handler = cb(application);
|
||||
if handler.is_not_null() {
|
||||
if !(*handler).on_context_initialized.is_some() { return 1; }
|
||||
let hcb = (*handler).on_context_initialized.unwrap();
|
||||
hcb(handler);
|
||||
}
|
||||
}
|
||||
return 1
|
||||
|
|
|
@ -6,10 +6,6 @@ use libc::c_int;
|
|||
use std::slice;
|
||||
use std::str;
|
||||
|
||||
pub fn fptr_is_null(fptr: *const u8) -> bool {
|
||||
fptr.is_null()
|
||||
}
|
||||
|
||||
pub fn slice_to_str(s: *const u8, l: uint, f: |&str| -> c_int) -> c_int {
|
||||
unsafe {
|
||||
slice::raw::buf_as_slice(s, l, |result| {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
use eutil::{fptr_is_null, slice_to_str};
|
||||
use eutil::slice_to_str;
|
||||
use libc::{size_t, c_int, c_ushort,c_void};
|
||||
use libc::types::os::arch::c95::wchar_t;
|
||||
use mem::{new0,newarray0,delete,deletearray};
|
||||
|
@ -52,8 +52,8 @@ pub extern "C" fn cef_string_userfree_utf16_free(cs: *mut cef_string_userfree_ut
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_utf8_clear(cs: *mut cef_string_utf8_t) {
|
||||
unsafe {
|
||||
if !fptr_is_null(mem::transmute((*cs).dtor)) {
|
||||
let dtor = (*cs).dtor;
|
||||
if (*cs).dtor.is_some() {
|
||||
let dtor = (*cs).dtor.unwrap();
|
||||
dtor((*cs).str);
|
||||
}
|
||||
(*cs).length = 0;
|
||||
|
@ -81,7 +81,7 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: *
|
|||
|
||||
ptr::copy_memory((*output).str, src, src_len as uint);
|
||||
(*output).length = src_len;
|
||||
(*output).dtor = string_utf8_dtor;
|
||||
(*output).dtor = Some(string_utf8_dtor);
|
||||
}
|
||||
} else {
|
||||
(*output).str = mem::transmute(src);
|
||||
|
@ -134,8 +134,8 @@ pub extern "C" fn cef_string_utf16_to_utf8(src: *const u16, src_len: size_t, out
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) {
|
||||
unsafe {
|
||||
if !fptr_is_null(mem::transmute((*cs).dtor)) {
|
||||
let dtor = (*cs).dtor;
|
||||
if (*cs).dtor.is_some() {
|
||||
let dtor = (*cs).dtor.unwrap();
|
||||
dtor((*cs).str);
|
||||
}
|
||||
(*cs).length = 0;
|
||||
|
@ -163,7 +163,7 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou
|
|||
|
||||
ptr::copy_memory((*output).str, src, src_len as uint);
|
||||
(*output).length = src_len;
|
||||
(*output).dtor = string_utf16_dtor;
|
||||
(*output).dtor = Some(string_utf16_dtor);
|
||||
}
|
||||
} else {
|
||||
(*output).str = mem::transmute(src);
|
||||
|
@ -192,8 +192,8 @@ pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const c
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) {
|
||||
unsafe {
|
||||
if !fptr_is_null(mem::transmute((*cs).dtor)) {
|
||||
let dtor = (*cs).dtor;
|
||||
if (*cs).dtor.is_some() {
|
||||
let dtor = (*cs).dtor.unwrap();
|
||||
dtor((*cs).str);
|
||||
}
|
||||
(*cs).length = 0;
|
||||
|
@ -221,7 +221,7 @@ pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, outp
|
|||
|
||||
ptr::copy_memory((*output).str, src, src_len as uint);
|
||||
(*output).length = src_len;
|
||||
(*output).dtor = string_wide_dtor;
|
||||
(*output).dtor = Some(string_wide_dtor);
|
||||
}
|
||||
} else {
|
||||
(*output).str = mem::transmute(src);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use eutil::fptr_is_null;
|
||||
use libc::{c_int};
|
||||
use std::mem;
|
||||
use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set};
|
||||
|
@ -26,7 +25,7 @@ pub extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t {
|
|||
#[no_mangle]
|
||||
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; }
|
||||
if lt.is_null() { return 0; }
|
||||
let v = string_list_to_vec(lt);
|
||||
(*v).len() as c_int
|
||||
}
|
||||
|
@ -35,7 +34,7 @@ pub extern "C" fn cef_string_list_size(lt: *mut cef_string_list_t) -> c_int {
|
|||
#[no_mangle]
|
||||
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; }
|
||||
if lt.is_null() { return; }
|
||||
let v = string_list_to_vec(lt);
|
||||
let cs = cef_string_userfree_utf8_alloc();
|
||||
cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1);
|
||||
|
@ -46,7 +45,7 @@ pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *con
|
|||
#[no_mangle]
|
||||
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; }
|
||||
if index < 0 || lt.is_null() { return 0; }
|
||||
let v = string_list_to_vec(lt);
|
||||
if index as uint > (*v).len() - 1 { return 0; }
|
||||
let cs = (*v)[index as uint];
|
||||
|
@ -57,7 +56,7 @@ pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(lt)) { return; }
|
||||
if lt.is_null() { return; }
|
||||
let v = string_list_to_vec(lt);
|
||||
if (*v).len() == 0 { return; }
|
||||
let mut cs;
|
||||
|
@ -71,7 +70,7 @@ pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(lt)) { return; }
|
||||
if lt.is_null() { return; }
|
||||
let v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt);
|
||||
cef_string_list_clear(lt);
|
||||
drop(v);
|
||||
|
@ -81,7 +80,7 @@ pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) {
|
|||
#[no_mangle]
|
||||
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; }
|
||||
if lt.is_null() { return 0 as *mut cef_string_list_t; }
|
||||
let v = string_list_to_vec(lt);
|
||||
let lt2 = cef_string_list_alloc();
|
||||
for cs in (*v).iter() {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use eutil::{fptr_is_null, slice_to_str};
|
||||
use eutil::slice_to_str;
|
||||
use libc::{c_int};
|
||||
use std::collections::TreeMap;
|
||||
use std::mem;
|
||||
|
@ -27,7 +27,7 @@ pub extern "C" fn cef_string_map_alloc() -> *mut cef_string_map_t {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_map_size(sm: *mut cef_string_map_t) -> c_int {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(sm)) { return 0; }
|
||||
if sm.is_null() { return 0; }
|
||||
let v = string_map_to_treemap(sm);
|
||||
(*v).len() as c_int
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ pub extern "C" fn cef_string_map_size(sm: *mut cef_string_map_t) -> c_int {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_map_append(sm: *mut cef_string_map_t, key: *const cef_string_t, value: *const cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(sm)) { return 0; }
|
||||
if sm.is_null() { return 0; }
|
||||
let v = string_map_to_treemap(sm);
|
||||
slice_to_str((*key).str as *const u8, (*key).length as uint, |result| {
|
||||
let s = String::from_str(result);
|
||||
|
@ -51,7 +51,7 @@ pub extern "C" fn cef_string_map_append(sm: *mut cef_string_map_t, key: *const c
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_map_find(sm: *mut cef_string_map_t, key: *const cef_string_t, value: *mut cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(sm)) { return 0; }
|
||||
if sm.is_null() { return 0; }
|
||||
let v = string_map_to_treemap(sm);
|
||||
slice_to_str((*key).str as *const u8, (*key).length as uint, |result| {
|
||||
match (*v).find(&String::from_str(result)) {
|
||||
|
@ -68,7 +68,7 @@ pub extern "C" fn cef_string_map_find(sm: *mut cef_string_map_t, key: *const cef
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_map_key(sm: *mut cef_string_map_t, index: c_int, value: *mut cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if index < 0 || fptr_is_null(mem::transmute(sm)) { return 0; }
|
||||
if index < 0 || sm.is_null() { return 0; }
|
||||
let v = string_map_to_treemap(sm);
|
||||
if index as uint > (*v).len() - 1 { return 0; }
|
||||
|
||||
|
@ -85,7 +85,7 @@ pub extern "C" fn cef_string_map_key(sm: *mut cef_string_map_t, index: c_int, va
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_map_value(sm: *mut cef_string_map_t, index: c_int, value: *mut cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if index < 0 || fptr_is_null(mem::transmute(sm)) { return 0; }
|
||||
if index < 0 || sm.is_null() { return 0; }
|
||||
let v = string_map_to_treemap(sm);
|
||||
if index as uint > (*v).len() - 1 { return 0; }
|
||||
|
||||
|
@ -102,7 +102,7 @@ pub extern "C" fn cef_string_map_value(sm: *mut cef_string_map_t, index: c_int,
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_map_clear(sm: *mut cef_string_map_t) {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(sm)) { return; }
|
||||
if sm.is_null() { return; }
|
||||
let v = string_map_to_treemap(sm);
|
||||
for val in (*v).values() {
|
||||
cef_string_userfree_utf8_free(*val);
|
||||
|
@ -114,7 +114,7 @@ pub extern "C" fn cef_string_map_clear(sm: *mut cef_string_map_t) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_map_free(sm: *mut cef_string_map_t) {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(sm)) { return; }
|
||||
if sm.is_null() { return; }
|
||||
let _v: Box<TreeMap<String, *mut cef_string_t>> = mem::transmute(sm);
|
||||
cef_string_map_clear(sm);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue