Skip to content

Commit 3e143ad

Browse files
committed
librustc: Make extern functions no longer of *u8 type.
Calling them LLVM asserts still, but that never worked anyway. This is the backwards compatible part.
1 parent 92b0324 commit 3e143ad

File tree

14 files changed

+437
-70
lines changed

14 files changed

+437
-70
lines changed

src/libcore/rt/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub impl Context {
4545
// The C-ABI function that is the task entry point
4646
extern fn task_start_wrapper(f: &~fn()) { (*f)() }
4747

48-
let fp: *c_void = task_start_wrapper as *c_void;
48+
let fp: *c_void = unsafe { transmute(task_start_wrapper) };
4949
let argp: *c_void = unsafe { transmute::<&~fn(), *c_void>(&*start) };
5050
let sp: *uint = stack.end();
5151
let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };

src/libcore/rt/local_services.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ impl Unwinder {
138138

139139
extern {
140140
#[rust_stack]
141+
#[cfg(stage0)]
141142
fn rust_try(f: *u8, code: *c_void, data: *c_void) -> uintptr_t;
143+
#[rust_stack]
144+
#[cfg(not(stage0))]
145+
fn rust_try(f: extern "C" fn(code: *c_void, env: *c_void),
146+
code: *c_void,
147+
data: *c_void)
148+
-> uintptr_t;
142149
}
143150
}
144151

src/libcore/rt/uv/net.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ pub type AllocCallback = ~fn(uint) -> Buf;
6262
impl Callback for AllocCallback { }
6363

6464
pub impl StreamWatcher {
65-
6665
fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
6766
// XXX: Borrowchk problems
6867
let data = get_watcher_data(unsafe { transmute_mut_region(self) });
6968
data.alloc_cb = Some(alloc);
7069
data.read_cb = Some(cb);
7170

7271
let handle = self.native_handle();
73-
unsafe { uvll::read_start(handle, alloc_cb, read_cb); }
72+
unsafe {
73+
uvll::read_start(handle, alloc_cb, read_cb);
74+
}
7475

7576
extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf {
7677
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(stream);
@@ -112,8 +113,9 @@ pub impl StreamWatcher {
112113
let bufs = [buf];
113114
unsafe {
114115
assert!(0 == uvll::write(req.native_handle(),
115-
self.native_handle(),
116-
bufs, write_cb));
116+
self.native_handle(),
117+
bufs,
118+
write_cb));
117119
}
118120

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

150-
unsafe { uvll::close(self.native_handle(), close_cb); }
152+
unsafe {
153+
uvll::close(self.native_handle(), close_cb);
154+
}
151155

152156
extern fn close_cb(handle: *uvll::uv_stream_t) {
153157
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(handle);
@@ -219,8 +223,9 @@ pub impl TcpWatcher {
219223
do ip4_as_uv_ip4(address) |addr| {
220224
rtdebug!("connect_t: %x", connect_handle as uint);
221225
assert!(0 == uvll::tcp_connect(connect_handle,
222-
self.native_handle(),
223-
addr, connect_cb));
226+
self.native_handle(),
227+
addr,
228+
connect_cb));
224229
}
225230
}
226231
_ => fail!()
@@ -251,7 +256,8 @@ pub impl TcpWatcher {
251256
static BACKLOG: c_int = 128; // XXX should be configurable
252257
// XXX: This can probably fail
253258
assert!(0 == uvll::listen(self.native_handle(),
254-
BACKLOG, connection_cb));
259+
BACKLOG,
260+
connection_cb));
255261
}
256262

257263
extern fn connection_cb(handle: *uvll::uv_stream_t, status: c_int) {

src/libcore/rt/uvll.rs

Lines changed: 116 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ pub type uv_timer_t = c_void;
5454
pub type uv_stream_t = c_void;
5555
pub type uv_fs_t = c_void;
5656

57+
#[cfg(stage0)]
5758
pub type uv_idle_cb = *u8;
59+
#[cfg(not(stage0))]
60+
pub type uv_idle_cb = extern "C" fn(*c_void, i32);
5861

5962
pub type sockaddr_in = c_void;
6063
pub type sockaddr_in6 = c_void;
@@ -146,10 +149,17 @@ pub unsafe fn run(loop_handle: *c_void) {
146149
rust_uv_run(loop_handle);
147150
}
148151

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

157+
#[cfg(not(stage0))]
158+
pub unsafe fn close<T>(handle: *T,
159+
callback: extern "C" fn(handle: *uv_stream_t)) {
160+
rust_uv_close(handle as *c_void, callback);
161+
}
162+
153163
pub unsafe fn walk(loop_handle: *c_void, cb: *u8, arg: *c_void) {
154164
rust_uv_walk(loop_handle, cb, arg);
155165
}
@@ -179,12 +189,29 @@ pub unsafe fn tcp_init(loop_handle: *c_void, handle: *uv_tcp_t) -> c_int {
179189
}
180190

181191
// FIXME ref #2064
192+
#[cfg(stage0)]
193+
pub unsafe fn tcp_connect(connect_ptr: *uv_connect_t,
194+
tcp_handle_ptr: *uv_tcp_t,
195+
addr_ptr: *sockaddr_in,
196+
after_connect_cb: *u8)
197+
-> c_int {
198+
return rust_uv_tcp_connect(connect_ptr,
199+
tcp_handle_ptr,
200+
after_connect_cb,
201+
addr_ptr);
202+
}
203+
204+
// FIXME ref #2064
205+
#[cfg(not(stage0))]
182206
pub unsafe fn tcp_connect(connect_ptr: *uv_connect_t,
183207
tcp_handle_ptr: *uv_tcp_t,
184208
addr_ptr: *sockaddr_in,
185-
after_connect_cb: *u8) -> c_int {
186-
return rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr,
187-
after_connect_cb, addr_ptr);
209+
after_connect_cb: extern "C" fn(*c_void, i32))
210+
-> c_int {
211+
return rust_uv_tcp_connect(connect_ptr,
212+
tcp_handle_ptr,
213+
after_connect_cb,
214+
addr_ptr);
188215
}
189216
// FIXME ref #2064
190217
pub unsafe fn tcp_connect6(connect_ptr: *uv_connect_t,
@@ -211,20 +238,64 @@ pub unsafe fn tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t, name: *sockaddr_in6) -
211238
return rust_uv_tcp_getpeername6(tcp_handle_ptr, name);
212239
}
213240

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

246+
#[cfg(not(stage0))]
247+
pub unsafe fn listen<T>(stream: *T,
248+
backlog: c_int,
249+
callback: extern "C" fn(a: *c_void, b: i32))
250+
-> c_int {
251+
return rust_uv_listen(stream as *c_void, backlog, callback);
252+
}
253+
218254
pub unsafe fn accept(server: *c_void, client: *c_void) -> c_int {
219255
return rust_uv_accept(server as *c_void, client as *c_void);
220256
}
221257

222-
pub unsafe fn write<T>(req: *uv_write_t, stream: *T, buf_in: &[uv_buf_t], cb: *u8) -> c_int {
258+
#[cfg(stage0)]
259+
pub unsafe fn write<T>(req: *uv_write_t,
260+
stream: *T,
261+
buf_in: &[uv_buf_t],
262+
callback: *u8)
263+
-> c_int {
264+
let buf_ptr = vec::raw::to_ptr(buf_in);
265+
let buf_cnt = vec::len(buf_in) as i32;
266+
return rust_uv_write(req as *c_void,
267+
stream as *c_void,
268+
buf_ptr,
269+
buf_cnt,
270+
callback);
271+
}
272+
273+
#[cfg(not(stage0))]
274+
pub unsafe fn write<T>(req: *uv_write_t,
275+
stream: *T,
276+
buf_in: &[uv_buf_t],
277+
callback: extern "C" fn(*c_void, i32))
278+
-> c_int {
223279
let buf_ptr = vec::raw::to_ptr(buf_in);
224280
let buf_cnt = vec::len(buf_in) as i32;
225-
return rust_uv_write(req as *c_void, stream as *c_void, buf_ptr, buf_cnt, cb);
281+
return rust_uv_write(req as *c_void,
282+
stream as *c_void,
283+
buf_ptr,
284+
buf_cnt,
285+
callback);
226286
}
227-
pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8) -> c_int {
287+
288+
#[cfg(stage0)]
289+
pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8)
290+
-> c_int {
291+
return rust_uv_read_start(stream as *c_void, on_alloc, on_read);
292+
}
293+
294+
#[cfg(not(stage0))]
295+
pub unsafe fn read_start(stream: *uv_stream_t,
296+
on_alloc: extern "C" fn(*c_void, u64) -> uv_buf_t,
297+
on_read: extern "C" fn(*c_void, i64, uv_buf_t))
298+
-> c_int {
228299
return rust_uv_read_start(stream as *c_void, on_alloc, on_read);
229300
}
230301

@@ -361,7 +432,13 @@ extern {
361432
fn rust_uv_loop_new() -> *c_void;
362433
fn rust_uv_loop_delete(lp: *c_void);
363434
fn rust_uv_run(loop_handle: *c_void);
435+
436+
#[cfg(stage0)]
364437
fn rust_uv_close(handle: *c_void, cb: *u8);
438+
#[cfg(not(stage0))]
439+
fn rust_uv_close(handle: *c_void,
440+
callback: extern "C" fn(handle: *uv_stream_t));
441+
365442
fn rust_uv_walk(loop_handle: *c_void, cb: *u8, arg: *c_void);
366443

367444
fn rust_uv_idle_new() -> *uv_idle_t;
@@ -390,11 +467,19 @@ extern {
390467
fn rust_uv_ip6_name(src: *sockaddr_in6, dst: *u8, size: size_t) -> c_int;
391468
fn rust_uv_ip4_port(src: *sockaddr_in) -> c_uint;
392469
fn rust_uv_ip6_port(src: *sockaddr_in6) -> c_uint;
470+
393471
// FIXME ref #2064
472+
#[cfg(stage0)]
394473
fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t,
395474
tcp_handle_ptr: *uv_tcp_t,
396475
after_cb: *u8,
397476
addr: *sockaddr_in) -> c_int;
477+
#[cfg(not(stage0))]
478+
fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t,
479+
tcp_handle_ptr: *uv_tcp_t,
480+
after_cb: extern "C" fn(*libc::c_void, i32),
481+
addr: *sockaddr_in) -> c_int;
482+
398483
// FIXME ref #2064
399484
fn rust_uv_tcp_bind(tcp_server: *uv_tcp_t, addr: *sockaddr_in) -> c_int;
400485
// FIXME ref #2064
@@ -408,16 +493,39 @@ extern {
408493
name: *sockaddr_in) -> c_int;
409494
fn rust_uv_tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t,
410495
name: *sockaddr_in6) ->c_int;
496+
497+
#[cfg(stage0)]
411498
fn rust_uv_listen(stream: *c_void, backlog: c_int, cb: *u8) -> c_int;
499+
#[cfg(not(stage0))]
500+
fn rust_uv_listen(stream: *c_void,
501+
backlog: c_int,
502+
callback: extern "C" fn(a: *c_void, b: i32))
503+
-> c_int;
504+
412505
fn rust_uv_accept(server: *c_void, client: *c_void) -> c_int;
506+
507+
#[cfg(stage0)]
413508
fn rust_uv_write(req: *c_void,
414509
stream: *c_void,
415510
buf_in: *uv_buf_t,
416511
buf_cnt: c_int,
417512
cb: *u8) -> c_int;
513+
514+
#[cfg(not(stage0))]
515+
fn rust_uv_write(req: *c_void,
516+
stream: *c_void,
517+
buf_in: *uv_buf_t,
518+
buf_cnt: c_int,
519+
callback: extern "C" fn(*c_void, i32))
520+
-> c_int;
521+
#[cfg(stage0)]
522+
fn rust_uv_read_start(stream: *c_void, on_alloc: *u8, on_read: *u8)
523+
-> c_int;
524+
#[cfg(not(stage0))]
418525
fn rust_uv_read_start(stream: *c_void,
419-
on_alloc: *u8,
420-
on_read: *u8) -> c_int;
526+
on_alloc: extern "C" fn(*c_void, u64) -> uv_buf_t,
527+
on_read: extern "C" fn(*c_void, i64, uv_buf_t))
528+
-> c_int;
421529
fn rust_uv_read_stop(stream: *c_void) -> c_int;
422530
fn rust_uv_timer_init(loop_handle: *c_void,
423531
timer_handle: *uv_timer_t) -> c_int;

src/libcore/task/local_data_priv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Eq for @LocalData {
6161
// proper map.
6262
type TaskLocalElement = (*libc::c_void, *libc::c_void, @LocalData);
6363
// Has to be a pointer at outermost layer; the foreign call returns void *.
64-
type TaskLocalMap = @mut ~[Option<TaskLocalElement>];
64+
pub type TaskLocalMap = @mut ~[Option<TaskLocalElement>];
6565

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

8484
unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
85-
8685
extern fn cleanup_task_local_map_extern_cb(map_ptr: *libc::c_void) {
8786
cleanup_task_local_map(map_ptr);
8887
}

src/libcore/task/rt.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The task interface to the runtime
1717
#[doc(hidden)]; // FIXME #3538
1818

1919
use libc;
20+
use task::local_data_priv::TaskLocalMap;
2021

2122
#[allow(non_camel_case_types)] // runtime type
2223
pub type sched_id = int;
@@ -67,5 +68,11 @@ pub extern {
6768
#[rust_stack]
6869
fn rust_set_task_local_data(task: *rust_task, map: *libc::c_void);
6970
#[rust_stack]
71+
#[cfg(stage0)]
7072
fn rust_task_local_data_atexit(task: *rust_task, cleanup_fn: *u8);
73+
#[rust_stack]
74+
#[cfg(not(stage0))]
75+
fn rust_task_local_data_atexit(
76+
task: *rust_task,
77+
cleanup_fn: extern "C" fn(a: *libc::c_void));
7178
}

src/librustc/middle/trans/expr.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,10 +1644,16 @@ fn trans_imm_cast(bcx: block, expr: @ast::expr,
16441644
val_ty(lldiscrim_a),
16451645
lldiscrim_a, true),
16461646
cast_float => SIToFP(bcx, lldiscrim_a, ll_t_out),
1647-
_ => ccx.sess.bug(~"translating unsupported cast.")
1647+
_ => {
1648+
ccx.sess.span_bug(expr.span,
1649+
~"translating unsupported cast.")
1650+
}
16481651
}
16491652
}
1650-
_ => ccx.sess.bug(~"translating unsupported cast.")
1653+
_ => {
1654+
ccx.sess.span_bug(expr.span,
1655+
~"translating unsupported cast.")
1656+
}
16511657
};
16521658
return immediate_rvalue_bcx(bcx, newval, t_out);
16531659
}

src/librustc/middle/ty.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,15 @@ pub fn type_is_unique(ty: t) -> bool {
17691769
}
17701770
}
17711771
1772+
pub fn type_is_castable(ty: t) -> bool {
1773+
match get(ty).sty {
1774+
ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
1775+
ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) | ty_type |
1776+
ty_ptr(_) => true,
1777+
_ => false
1778+
}
1779+
}
1780+
17721781
/*
17731782
A scalar type is one that denotes an atomic datum, with no sub-components.
17741783
(A ty_ptr is scalar because it represents a non-managed pointer, so its

0 commit comments

Comments
 (0)