Skip to content

librustc: Make extern functions no longer of *u8 type. #6491

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcore/rt/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub impl Context {
// The C-ABI function that is the task entry point
extern fn task_start_wrapper(f: &~fn()) { (*f)() }

let fp: *c_void = task_start_wrapper as *c_void;
let fp: *c_void = unsafe { transmute(task_start_wrapper) };
let argp: *c_void = unsafe { transmute::<&~fn(), *c_void>(&*start) };
let sp: *uint = stack.end();
let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };
Expand Down
7 changes: 7 additions & 0 deletions src/libcore/rt/local_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ impl Unwinder {

extern {
#[rust_stack]
#[cfg(stage0)]
fn rust_try(f: *u8, code: *c_void, data: *c_void) -> uintptr_t;
#[rust_stack]
#[cfg(not(stage0))]
fn rust_try(f: extern "C" fn(code: *c_void, env: *c_void),
code: *c_void,
data: *c_void)
-> uintptr_t;
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/libcore/rt/uv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ pub type AllocCallback = ~fn(uint) -> Buf;
impl Callback for AllocCallback { }

pub impl StreamWatcher {

fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
// XXX: Borrowchk problems
let data = get_watcher_data(unsafe { transmute_mut_region(self) });
data.alloc_cb = Some(alloc);
data.read_cb = Some(cb);

let handle = self.native_handle();
unsafe { uvll::read_start(handle, alloc_cb, read_cb); }
unsafe {
uvll::read_start(handle, alloc_cb, read_cb);
}

extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf {
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(stream);
Expand Down Expand Up @@ -112,8 +113,9 @@ pub impl StreamWatcher {
let bufs = [buf];
unsafe {
assert!(0 == uvll::write(req.native_handle(),
self.native_handle(),
bufs, write_cb));
self.native_handle(),
bufs,
write_cb));
}

extern fn write_cb(req: *uvll::uv_write_t, status: c_int) {
Expand Down Expand Up @@ -147,7 +149,9 @@ pub impl StreamWatcher {
data.close_cb = Some(cb);
}

unsafe { uvll::close(self.native_handle(), close_cb); }
unsafe {
uvll::close(self.native_handle(), close_cb);
}

extern fn close_cb(handle: *uvll::uv_stream_t) {
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(handle);
Expand Down Expand Up @@ -219,8 +223,9 @@ pub impl TcpWatcher {
do ip4_as_uv_ip4(address) |addr| {
rtdebug!("connect_t: %x", connect_handle as uint);
assert!(0 == uvll::tcp_connect(connect_handle,
self.native_handle(),
addr, connect_cb));
self.native_handle(),
addr,
connect_cb));
}
}
_ => fail!()
Expand Down Expand Up @@ -251,7 +256,8 @@ pub impl TcpWatcher {
static BACKLOG: c_int = 128; // XXX should be configurable
// XXX: This can probably fail
assert!(0 == uvll::listen(self.native_handle(),
BACKLOG, connection_cb));
BACKLOG,
connection_cb));
}

extern fn connection_cb(handle: *uvll::uv_stream_t, status: c_int) {
Expand Down
124 changes: 116 additions & 8 deletions src/libcore/rt/uvll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ pub type uv_timer_t = c_void;
pub type uv_stream_t = c_void;
pub type uv_fs_t = c_void;

#[cfg(stage0)]
pub type uv_idle_cb = *u8;
#[cfg(not(stage0))]
pub type uv_idle_cb = extern "C" fn(*c_void, i32);

pub type sockaddr_in = c_void;
pub type sockaddr_in6 = c_void;
Expand Down Expand Up @@ -146,10 +149,17 @@ pub unsafe fn run(loop_handle: *c_void) {
rust_uv_run(loop_handle);
}

#[cfg(stage0)]
pub unsafe fn close<T>(handle: *T, cb: *u8) {
rust_uv_close(handle as *c_void, cb);
}

#[cfg(not(stage0))]
pub unsafe fn close<T>(handle: *T,
callback: extern "C" fn(handle: *uv_stream_t)) {
rust_uv_close(handle as *c_void, callback);
}

pub unsafe fn walk(loop_handle: *c_void, cb: *u8, arg: *c_void) {
rust_uv_walk(loop_handle, cb, arg);
}
Expand Down Expand Up @@ -179,12 +189,29 @@ pub unsafe fn tcp_init(loop_handle: *c_void, handle: *uv_tcp_t) -> c_int {
}

// FIXME ref #2064
#[cfg(stage0)]
pub unsafe fn tcp_connect(connect_ptr: *uv_connect_t,
tcp_handle_ptr: *uv_tcp_t,
addr_ptr: *sockaddr_in,
after_connect_cb: *u8)
-> c_int {
return rust_uv_tcp_connect(connect_ptr,
tcp_handle_ptr,
after_connect_cb,
addr_ptr);
}

// FIXME ref #2064
#[cfg(not(stage0))]
pub unsafe fn tcp_connect(connect_ptr: *uv_connect_t,
tcp_handle_ptr: *uv_tcp_t,
addr_ptr: *sockaddr_in,
after_connect_cb: *u8) -> c_int {
return rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr,
after_connect_cb, addr_ptr);
after_connect_cb: extern "C" fn(*c_void, i32))
-> c_int {
return rust_uv_tcp_connect(connect_ptr,
tcp_handle_ptr,
after_connect_cb,
addr_ptr);
}
// FIXME ref #2064
pub unsafe fn tcp_connect6(connect_ptr: *uv_connect_t,
Expand All @@ -211,20 +238,64 @@ pub unsafe fn tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t, name: *sockaddr_in6) -
return rust_uv_tcp_getpeername6(tcp_handle_ptr, name);
}

#[cfg(stage0)]
pub unsafe fn listen<T>(stream: *T, backlog: c_int, cb: *u8) -> c_int {
return rust_uv_listen(stream as *c_void, backlog, cb);
}

#[cfg(not(stage0))]
pub unsafe fn listen<T>(stream: *T,
backlog: c_int,
callback: extern "C" fn(a: *c_void, b: i32))
-> c_int {
return rust_uv_listen(stream as *c_void, backlog, callback);
}

pub unsafe fn accept(server: *c_void, client: *c_void) -> c_int {
return rust_uv_accept(server as *c_void, client as *c_void);
}

pub unsafe fn write<T>(req: *uv_write_t, stream: *T, buf_in: &[uv_buf_t], cb: *u8) -> c_int {
#[cfg(stage0)]
pub unsafe fn write<T>(req: *uv_write_t,
stream: *T,
buf_in: &[uv_buf_t],
callback: *u8)
-> c_int {
let buf_ptr = vec::raw::to_ptr(buf_in);
let buf_cnt = vec::len(buf_in) as i32;
return rust_uv_write(req as *c_void,
stream as *c_void,
buf_ptr,
buf_cnt,
callback);
}

#[cfg(not(stage0))]
pub unsafe fn write<T>(req: *uv_write_t,
stream: *T,
buf_in: &[uv_buf_t],
callback: extern "C" fn(*c_void, i32))
-> c_int {
let buf_ptr = vec::raw::to_ptr(buf_in);
let buf_cnt = vec::len(buf_in) as i32;
return rust_uv_write(req as *c_void, stream as *c_void, buf_ptr, buf_cnt, cb);
return rust_uv_write(req as *c_void,
stream as *c_void,
buf_ptr,
buf_cnt,
callback);
}
pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8) -> c_int {

#[cfg(stage0)]
pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8)
-> c_int {
return rust_uv_read_start(stream as *c_void, on_alloc, on_read);
}

#[cfg(not(stage0))]
pub unsafe fn read_start(stream: *uv_stream_t,
on_alloc: extern "C" fn(*c_void, u64) -> uv_buf_t,
on_read: extern "C" fn(*c_void, i64, uv_buf_t))
-> c_int {
return rust_uv_read_start(stream as *c_void, on_alloc, on_read);
}

Expand Down Expand Up @@ -361,7 +432,13 @@ extern {
fn rust_uv_loop_new() -> *c_void;
fn rust_uv_loop_delete(lp: *c_void);
fn rust_uv_run(loop_handle: *c_void);

#[cfg(stage0)]
fn rust_uv_close(handle: *c_void, cb: *u8);
#[cfg(not(stage0))]
fn rust_uv_close(handle: *c_void,
callback: extern "C" fn(handle: *uv_stream_t));

fn rust_uv_walk(loop_handle: *c_void, cb: *u8, arg: *c_void);

fn rust_uv_idle_new() -> *uv_idle_t;
Expand Down Expand Up @@ -390,11 +467,19 @@ extern {
fn rust_uv_ip6_name(src: *sockaddr_in6, dst: *u8, size: size_t) -> c_int;
fn rust_uv_ip4_port(src: *sockaddr_in) -> c_uint;
fn rust_uv_ip6_port(src: *sockaddr_in6) -> c_uint;

// FIXME ref #2064
#[cfg(stage0)]
fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t,
tcp_handle_ptr: *uv_tcp_t,
after_cb: *u8,
addr: *sockaddr_in) -> c_int;
#[cfg(not(stage0))]
fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t,
tcp_handle_ptr: *uv_tcp_t,
after_cb: extern "C" fn(*libc::c_void, i32),
addr: *sockaddr_in) -> c_int;

// FIXME ref #2064
fn rust_uv_tcp_bind(tcp_server: *uv_tcp_t, addr: *sockaddr_in) -> c_int;
// FIXME ref #2064
Expand All @@ -408,16 +493,39 @@ extern {
name: *sockaddr_in) -> c_int;
fn rust_uv_tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t,
name: *sockaddr_in6) ->c_int;

#[cfg(stage0)]
fn rust_uv_listen(stream: *c_void, backlog: c_int, cb: *u8) -> c_int;
#[cfg(not(stage0))]
fn rust_uv_listen(stream: *c_void,
backlog: c_int,
callback: extern "C" fn(a: *c_void, b: i32))
-> c_int;

fn rust_uv_accept(server: *c_void, client: *c_void) -> c_int;

#[cfg(stage0)]
fn rust_uv_write(req: *c_void,
stream: *c_void,
buf_in: *uv_buf_t,
buf_cnt: c_int,
cb: *u8) -> c_int;

#[cfg(not(stage0))]
fn rust_uv_write(req: *c_void,
stream: *c_void,
buf_in: *uv_buf_t,
buf_cnt: c_int,
callback: extern "C" fn(*c_void, i32))
-> c_int;
#[cfg(stage0)]
fn rust_uv_read_start(stream: *c_void, on_alloc: *u8, on_read: *u8)
-> c_int;
#[cfg(not(stage0))]
fn rust_uv_read_start(stream: *c_void,
on_alloc: *u8,
on_read: *u8) -> c_int;
on_alloc: extern "C" fn(*c_void, u64) -> uv_buf_t,
on_read: extern "C" fn(*c_void, i64, uv_buf_t))
-> c_int;
fn rust_uv_read_stop(stream: *c_void) -> c_int;
fn rust_uv_timer_init(loop_handle: *c_void,
timer_handle: *uv_timer_t) -> c_int;
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/task/local_data_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Eq for @LocalData {
// proper map.
type TaskLocalElement = (*libc::c_void, *libc::c_void, @LocalData);
// Has to be a pointer at outermost layer; the foreign call returns void *.
type TaskLocalMap = @mut ~[Option<TaskLocalElement>];
pub type TaskLocalMap = @mut ~[Option<TaskLocalElement>];

fn cleanup_task_local_map(map_ptr: *libc::c_void) {
unsafe {
Expand All @@ -82,7 +82,6 @@ unsafe fn get_local_map(handle: Handle) -> TaskLocalMap {
}

unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {

extern fn cleanup_task_local_map_extern_cb(map_ptr: *libc::c_void) {
cleanup_task_local_map(map_ptr);
}
Expand Down
7 changes: 7 additions & 0 deletions src/libcore/task/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The task interface to the runtime
#[doc(hidden)]; // FIXME #3538

use libc;
use task::local_data_priv::TaskLocalMap;

#[allow(non_camel_case_types)] // runtime type
pub type sched_id = int;
Expand Down Expand Up @@ -67,5 +68,11 @@ pub extern {
#[rust_stack]
fn rust_set_task_local_data(task: *rust_task, map: *libc::c_void);
#[rust_stack]
#[cfg(stage0)]
fn rust_task_local_data_atexit(task: *rust_task, cleanup_fn: *u8);
#[rust_stack]
#[cfg(not(stage0))]
fn rust_task_local_data_atexit(
task: *rust_task,
cleanup_fn: extern "C" fn(a: *libc::c_void));
}
Loading