Skip to content

Commit 95f5365

Browse files
olsonjefferybrson
authored andcommitted
---
yaml --- r: 12559 b: refs/heads/master c: bf99a3a h: refs/heads/master i: 12557: 5400937 12555: 181b7fd 12551: 2d6d4ba 12543: 9ffd073 v: v3
1 parent 89efcd6 commit 95f5365

File tree

5 files changed

+181
-44
lines changed

5 files changed

+181
-44
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3d004c6df8f25e1f120279c1e9e9b1b6e38810e0
2+
refs/heads/master: bf99a3aa932d32a1390ca58df403c68defc51a07
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libstd/uv.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ native mod rustrt {
5353
loop_handle: *libc::c_void,
5454
cb: *u8,
5555
id: *u8) -> *libc::c_void;
56-
fn rust_uv_timer_init(
56+
fn rust_uv_hilvl_timer_init(
5757
loop_handle: *libc::c_void,
5858
cb: *u8,
5959
id: *u8) -> *libc::c_void;
60-
fn rust_uv_timer_start(
60+
fn rust_uv_hilvl_timer_start(
6161
timer_handle: *libc::c_void,
6262
timeout: libc::c_uint,
6363
repeat: libc::c_uint);
64-
fn rust_uv_timer_stop(handle: *libc::c_void);
64+
fn rust_uv_timer_stop(handle: *ll::uv_timer_t) -> libc::c_int;
6565
fn rust_uv_free(ptr: *libc::c_void);
6666
// sizeof testing helpers
6767
fn rust_uv_helper_uv_tcp_t_size() -> libc::c_uint;
@@ -71,6 +71,7 @@ native mod rustrt {
7171
fn rust_uv_helper_uv_err_t_size() -> libc::c_uint;
7272
fn rust_uv_helper_sockaddr_in_size() -> libc::c_uint;
7373
fn rust_uv_helper_uv_async_t_size() -> libc::c_uint;
74+
fn rust_uv_helper_uv_timer_t_size() -> libc::c_uint;
7475
}
7576

7677

@@ -525,7 +526,7 @@ crust fn process_operation(
525526
}
526527
op_timer_init(id) {
527528
let id_ptr = vec::unsafe::to_ptr(id);
528-
let timer_handle = rustrt::rust_uv_timer_init(
529+
let timer_handle = rustrt::rust_uv_hilvl_timer_init(
529530
lp,
530531
process_timer_call,
531532
id_ptr);
@@ -534,11 +535,11 @@ crust fn process_operation(
534535
timer_handle));
535536
}
536537
op_timer_start(id, handle, timeout, repeat) {
537-
rustrt::rust_uv_timer_start(handle, timeout,
538+
rustrt::rust_uv_hilvl_timer_start(handle, timeout,
538539
repeat);
539540
}
540541
op_timer_stop(id, handle, after_cb) {
541-
rustrt::rust_uv_timer_stop(handle);
542+
rustrt::rust_uv_timer_stop(handle as *ll::uv_timer_t);
542543
comm::send(loop_chan, uv_timer_stop(id, after_cb));
543544
}
544545
op_teardown(op_handle) {
@@ -1251,5 +1252,17 @@ mod test {
12511252
log(debug, output);
12521253
assert native_handle_size as uint == rust_handle_size;
12531254
}
1255+
1256+
#[test]
1257+
#[ignore(cfg(target_os = "freebsd"))]
1258+
fn test_uv_struct_size_uv_timer_t() {
1259+
let native_handle_size =
1260+
rustrt::rust_uv_helper_uv_timer_t_size();
1261+
let rust_handle_size = sys::size_of::<ll::uv_timer_t>();
1262+
let output = #fmt("uv_timer_t -- native: %u rust: %u",
1263+
native_handle_size as uint, rust_handle_size);
1264+
log(debug, output);
1265+
assert native_handle_size as uint == rust_handle_size;
1266+
}
12541267

12551268
}

trunk/src/libstd/uv_ll.rs

Lines changed: 140 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,36 @@ type uv_async_t = {
201201
a12: *u8
202202
};
203203

204+
// 64bit unix size: 128
205+
// 32bit unix size: ?
206+
#[cfg(target_os = "linux")]
207+
#[cfg(target_os = "macos")]
208+
#[cfg(target_os = "freebsd")]
209+
type uv_timer_t = {
210+
fields: uv_handle_fields,
211+
a00: *u8, a01: *u8, a02: *u8, a03: *u8,
212+
a04: *u8, a05: *u8, a06: *u8, a07: *u8,
213+
a08: *u8, a09: *u8,
214+
a11: uv_timer_t_32bit_unix_riders
215+
};
216+
#[cfg(target_arch="x86_64")]
217+
type uv_timer_t_32bit_unix_riders = {
218+
a10: *u8, a11: *u8
219+
};
220+
#[cfg(target_arch="x86")]
221+
type uv_timer_t_32bit_unix_riders = {
222+
a10: *u8, a11: *u8, a12: *u8, a13: *u8
223+
};
224+
// win32 size: ?
225+
#[cfg(target_os = "win32")]
226+
type uv_timer_t = {
227+
fields: uv_handle_fields,
228+
a00: *u8, a01: *u8, a02: *u8, a03: *u8,
229+
a04: *u8, a05: *u8, a06: *u8, a07: *u8,
230+
a08: *u8, a09: *u8, a10: *u8, a11: *u8,
231+
a12: *u8
232+
};
233+
204234
// unix size: 16
205235
#[cfg(target_os = "linux")]
206236
#[cfg(target_os = "macos")]
@@ -379,6 +409,57 @@ mod uv_ll_struct_stubgen {
379409
#[cfg(target_os = "linux")]
380410
#[cfg(target_os = "macos")]
381411
#[cfg(target_os = "freebsd")]
412+
fn gen_stub_uv_timer_t() -> uv_timer_t {
413+
ret gen_stub_arch();
414+
#[cfg(target_arch = "x86_64")]
415+
fn gen_stub_arch() -> uv_timer_t {
416+
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
417+
close_cb: ptr::null(),
418+
mut data: ptr::null() },
419+
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
420+
a03: 0 as *u8,
421+
a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
422+
a07: 0 as *u8,
423+
a08: 0 as *u8, a09: 0 as *u8,
424+
a11: {
425+
a10: 0 as *u8, a11: 0 as *u8
426+
}
427+
};
428+
}
429+
#[cfg(target_arch = "x86")]
430+
fn gen_stub_arch() -> uv_timer_t {
431+
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
432+
close_cb: ptr::null(),
433+
mut data: ptr::null() },
434+
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
435+
a03: 0 as *u8,
436+
a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
437+
a07: 0 as *u8,
438+
a08: 0 as *u8, a09: 0 as *u8,
439+
a11: {
440+
a10: 0 as *u8, a11: 0 as *u8,
441+
a12: 0 as *u8, a13: 0 as *u8
442+
}
443+
};
444+
}
445+
}
446+
#[cfg(target_os = "win32")]
447+
fn gen_stub_uv_timer_t() -> uv_timer_t {
448+
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
449+
close_cb: ptr::null(),
450+
mut data: ptr::null() },
451+
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
452+
a03: 0 as *u8,
453+
a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
454+
a07: 0 as *u8,
455+
a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
456+
a11: 0 as *u8,
457+
a12: 0 as *u8
458+
};
459+
}
460+
#[cfg(target_os = "linux")]
461+
#[cfg(target_os = "macos")]
462+
#[cfg(target_os = "freebsd")]
382463
fn gen_stub_uv_write_t() -> uv_write_t {
383464
ret gen_stub_arch();
384465
#[cfg(target_arch="x86_64")]
@@ -467,10 +548,18 @@ native mod rustrt {
467548
fn rust_uv_read_start(stream: *libc::c_void, on_alloc: *u8,
468549
on_read: *u8) -> libc::c_int;
469550
fn rust_uv_read_stop(stream: *libc::c_void) -> libc::c_int;
551+
fn rust_uv_timer_init(loop_handle: *libc::c_void,
552+
timer_handle: *uv_timer_t) -> libc::c_int;
553+
fn rust_uv_timer_start(
554+
timer_handle: *uv_timer_t,
555+
cb: *u8,
556+
timeout: libc::c_uint,
557+
repeat: libc::c_uint) -> libc::c_int;
558+
fn rust_uv_timer_stop(handle: *uv_timer_t) -> libc::c_int;
559+
560+
// data accessors/helpers for rust-mapped uv structs
470561
fn rust_uv_malloc_buf_base_of(sug_size: libc::size_t) -> *u8;
471562
fn rust_uv_free_base_of_buf(++buf: uv_buf_t);
472-
473-
// data accessors for rust-mapped uv structs
474563
fn rust_uv_get_stream_handle_from_connect_req(
475564
connect_req: *uv_connect_t)
476565
-> *uv_stream_t;
@@ -577,6 +666,50 @@ unsafe fn async_init(loop_handle: *libc::c_void,
577666
unsafe fn async_send(async_handle: *uv_async_t) {
578667
ret rustrt::rust_uv_async_send(async_handle);
579668
}
669+
unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
670+
let out_buf = { base: ptr::null(), len: 0 as libc::size_t };
671+
let out_buf_ptr = ptr::addr_of(out_buf);
672+
log(debug, #fmt("ll::buf_init - input %u len %u out_buf: %u",
673+
input as uint,
674+
len as uint,
675+
out_buf_ptr as uint));
676+
// yuck :/
677+
rustrt::rust_uv_buf_init(out_buf_ptr, input, len);
678+
//let result = rustrt::rust_uv_buf_init_2(input, len);
679+
log(debug, "after rust_uv_buf_init");
680+
let res_base = get_base_from_buf(out_buf);
681+
let res_len = get_len_from_buf(out_buf);
682+
//let res_base = get_base_from_buf(result);
683+
log(debug, #fmt("ll::buf_init - result %u len %u",
684+
res_base as uint,
685+
res_len as uint));
686+
ret out_buf;
687+
//ret result;
688+
}
689+
unsafe fn ip4_addr(ip: str, port: int)
690+
-> sockaddr_in {
691+
let mut addr_vec = str::bytes(ip);
692+
addr_vec += [0u8]; // add null terminator
693+
let addr_vec_ptr = vec::unsafe::to_ptr(addr_vec);
694+
let ip_back = str::from_bytes(addr_vec);
695+
log(debug, #fmt("vec val: '%s' length: %u",
696+
ip_back, vec::len(addr_vec)));
697+
ret rustrt::rust_uv_ip4_addr(addr_vec_ptr,
698+
port as libc::c_int);
699+
}
700+
701+
unsafe fn timer_init(loop_ptr: *libc::c_void,
702+
timer_ptr: *uv_timer_t) -> libc::c_int {
703+
ret rustrt::rust_uv_timer_init(loop_ptr, timer_ptr);
704+
}
705+
unsafe fn timer_start(timer_ptr: *uv_timer_t, cb: *u8, timeout: uint,
706+
repeat: uint) -> libc::c_int {
707+
ret rustrt::rust_uv_timer_start(timer_ptr, cb, timeout as libc::c_uint,
708+
repeat as libc::c_uint);
709+
}
710+
unsafe fn timer_stop(timer_ptr: *uv_timer_t) -> libc::c_int {
711+
ret rustrt::rust_uv_timer_stop(timer_ptr);
712+
}
580713

581714
// libuv struct initializers
582715
unsafe fn tcp_t() -> uv_tcp_t {
@@ -591,6 +724,11 @@ unsafe fn write_t() -> uv_write_t {
591724
unsafe fn async_t() -> uv_async_t {
592725
ret uv_ll_struct_stubgen::gen_stub_uv_async_t();
593726
}
727+
unsafe fn timer_t() -> uv_timer_t {
728+
ret uv_ll_struct_stubgen::gen_stub_uv_timer_t();
729+
}
730+
731+
// data access helpers
594732
unsafe fn get_loop_for_uv_handle(handle: *libc::c_void)
595733
-> *libc::c_void {
596734
ret rustrt::rust_uv_get_loop_for_uv_handle(handle);
@@ -627,37 +765,6 @@ unsafe fn get_base_from_buf(buf: uv_buf_t) -> *u8 {
627765
unsafe fn get_len_from_buf(buf: uv_buf_t) -> libc::size_t {
628766
ret rustrt::rust_uv_get_len_from_buf(buf);
629767
}
630-
unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
631-
let out_buf = { base: ptr::null(), len: 0 as libc::size_t };
632-
let out_buf_ptr = ptr::addr_of(out_buf);
633-
log(debug, #fmt("ll::buf_init - input %u len %u out_buf: %u",
634-
input as uint,
635-
len as uint,
636-
out_buf_ptr as uint));
637-
// yuck :/
638-
rustrt::rust_uv_buf_init(out_buf_ptr, input, len);
639-
//let result = rustrt::rust_uv_buf_init_2(input, len);
640-
log(debug, "after rust_uv_buf_init");
641-
let res_base = get_base_from_buf(out_buf);
642-
let res_len = get_len_from_buf(out_buf);
643-
//let res_base = get_base_from_buf(result);
644-
log(debug, #fmt("ll::buf_init - result %u len %u",
645-
res_base as uint,
646-
res_len as uint));
647-
ret out_buf;
648-
//ret result;
649-
}
650-
unsafe fn ip4_addr(ip: str, port: int)
651-
-> sockaddr_in {
652-
let mut addr_vec = str::bytes(ip);
653-
addr_vec += [0u8]; // add null terminator
654-
let addr_vec_ptr = vec::unsafe::to_ptr(addr_vec);
655-
let ip_back = str::from_bytes(addr_vec);
656-
log(debug, #fmt("vec val: '%s' length: %u",
657-
ip_back, vec::len(addr_vec)));
658-
ret rustrt::rust_uv_ip4_addr(addr_vec_ptr,
659-
port as libc::c_int);
660-
}
661768
unsafe fn malloc_buf_base_of(suggested_size: libc::size_t)
662769
-> *u8 {
663770
ret rustrt::rust_uv_malloc_buf_base_of(suggested_size);

trunk/src/rt/rust_uv.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ rust_uv_hilvl_async_init(uv_loop_t* loop, crust_simple_cb cb,
189189
}
190190

191191
extern "C" void*
192-
rust_uv_timer_init(uv_loop_t* loop, crust_simple_cb cb,
192+
rust_uv_hilvl_timer_init(uv_loop_t* loop, crust_simple_cb cb,
193193
uint8_t* buf) {
194194
uv_timer_t* new_timer = (uv_timer_t*)current_kernel_malloc(
195195
sizeof(uv_timer_t),
@@ -202,14 +202,25 @@ rust_uv_timer_init(uv_loop_t* loop, crust_simple_cb cb,
202202
}
203203

204204
extern "C" void
205-
rust_uv_timer_start(uv_timer_t* the_timer, uint32_t timeout,
205+
rust_uv_hilvl_timer_start(uv_timer_t* the_timer, uint32_t timeout,
206206
uint32_t repeat) {
207207
uv_timer_start(the_timer, native_timer_cb, timeout, repeat);
208208
}
209209

210-
extern "C" void
210+
extern "C" int
211+
rust_uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) {
212+
return uv_timer_init(loop, timer);
213+
}
214+
215+
extern "C" int
216+
rust_uv_timer_start(uv_timer_t* the_timer, uv_timer_cb cb,
217+
uint32_t timeout, uint32_t repeat) {
218+
return uv_timer_start(the_timer, cb, timeout, repeat);
219+
}
220+
221+
extern "C" int
211222
rust_uv_timer_stop(uv_timer_t* the_timer) {
212-
uv_timer_stop(the_timer);
223+
return uv_timer_stop(the_timer);
213224
}
214225

215226
extern "C" int
@@ -288,6 +299,10 @@ extern "C" size_t
288299
rust_uv_helper_uv_async_t_size() {
289300
return sizeof(uv_async_t);
290301
}
302+
extern "C" size_t
303+
rust_uv_helper_uv_timer_t_size() {
304+
return sizeof(uv_timer_t);
305+
}
291306

292307
extern "C" uv_stream_t*
293308
rust_uv_get_stream_handle_from_connect_req(uv_connect_t* connect) {

trunk/src/rt/rustrt.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ rust_uv_hilvl_close_timer
9797
rust_uv_async_send
9898
rust_uv_async_init
9999
rust_uv_hilvl_async_init
100+
rust_uv_hilvl_timer_init
101+
rust_uv_hilvl_timer_start
100102
rust_uv_timer_init
101103
rust_uv_timer_start
102104
rust_uv_timer_stop

0 commit comments

Comments
 (0)