Skip to content

Commit 30c885e

Browse files
committed
uv: Remove lots of uv/C++ wrappers
1 parent 3851f90 commit 30c885e

File tree

14 files changed

+310
-955
lines changed

14 files changed

+310
-955
lines changed

src/librustuv/addrinfo.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ impl GetAddrInfoRequest {
110110
self.get_req_data().getaddrinfo_cb = Some(wrapper_cb);
111111

112112
unsafe {
113-
assert!(0 == uvll::getaddrinfo(loop_.native_handle(),
114-
self.native_handle(),
115-
getaddrinfo_cb,
116-
c_node_ptr,
117-
c_service_ptr,
118-
hint_ptr));
113+
assert!(0 == uvll::uv_getaddrinfo(loop_.native_handle(),
114+
self.native_handle(),
115+
getaddrinfo_cb,
116+
c_node_ptr,
117+
c_service_ptr,
118+
hint_ptr));
119119
}
120120

121121
extern "C" fn getaddrinfo_cb(req: *uvll::uv_getaddrinfo_t,
@@ -127,7 +127,7 @@ impl GetAddrInfoRequest {
127127
let data = req.get_req_data();
128128
(*data.getaddrinfo_cb.get_ref())(req, &addrinfo, err);
129129
unsafe {
130-
uvll::freeaddrinfo(res);
130+
uvll::uv_freeaddrinfo(res);
131131
}
132132
}
133133
}

src/librustuv/async.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl AsyncWatcher {
2626
watcher.install_watcher_data();
2727
let data = watcher.get_watcher_data();
2828
data.async_cb = Some(cb);
29-
assert_eq!(0, uvll::async_init(loop_.native_handle(), handle, async_cb));
29+
assert_eq!(0, uvll::uv_async_init(loop_.native_handle(), handle, async_cb));
3030
return watcher;
3131
}
3232

@@ -42,7 +42,7 @@ impl AsyncWatcher {
4242
pub fn send(&mut self) {
4343
unsafe {
4444
let handle = self.native_handle();
45-
uvll::async_send(handle);
45+
uvll::uv_async_send(handle);
4646
}
4747
}
4848
}

src/librustuv/file.rs

Lines changed: 81 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ impl FsRequest {
4242
me.req_boilerplate(Some(cb))
4343
};
4444
let ret = path.with_ref(|p| unsafe {
45-
uvll::fs_open(loop_.native_handle(),
46-
self.native_handle(), p, flags, mode, complete_cb_ptr)
45+
uvll::uv_fs_open(loop_.native_handle(),
46+
self.native_handle(), p, flags as c_int,
47+
mode as c_int, complete_cb_ptr)
4748
});
4849
assert_eq!(ret, 0);
4950
}
@@ -52,17 +53,18 @@ impl FsRequest {
5253
flags: int, mode: int) -> Result<c_int, UvError> {
5354
let complete_cb_ptr = self.req_boilerplate(None);
5455
let result = path.with_ref(|p| unsafe {
55-
uvll::fs_open(loop_.native_handle(),
56-
self.native_handle(), p, flags, mode, complete_cb_ptr)
56+
uvll::uv_fs_open(loop_.native_handle(),
57+
self.native_handle(), p, flags as c_int,
58+
mode as c_int, complete_cb_ptr)
5759
});
5860
self.sync_cleanup(result)
5961
}
6062

6163
pub fn unlink(mut self, loop_: &Loop, path: &CString, cb: FsCallback) {
6264
let complete_cb_ptr = self.req_boilerplate(Some(cb));
6365
let ret = path.with_ref(|p| unsafe {
64-
uvll::fs_unlink(loop_.native_handle(),
65-
self.native_handle(), p, complete_cb_ptr)
66+
uvll::uv_fs_unlink(loop_.native_handle(),
67+
self.native_handle(), p, complete_cb_ptr)
6668
});
6769
assert_eq!(ret, 0);
6870
}
@@ -71,8 +73,8 @@ impl FsRequest {
7173
-> Result<c_int, UvError> {
7274
let complete_cb_ptr = self.req_boilerplate(None);
7375
let result = path.with_ref(|p| unsafe {
74-
uvll::fs_unlink(loop_.native_handle(),
75-
self.native_handle(), p, complete_cb_ptr)
76+
uvll::uv_fs_unlink(loop_.native_handle(),
77+
self.native_handle(), p, complete_cb_ptr)
7678
});
7779
self.sync_cleanup(result)
7880
}
@@ -89,8 +91,8 @@ impl FsRequest {
8991
pub fn stat(mut self, loop_: &Loop, path: &CString, cb: FsCallback) {
9092
let complete_cb_ptr = self.req_boilerplate(Some(cb));
9193
let ret = path.with_ref(|p| unsafe {
92-
uvll::fs_stat(loop_.native_handle(),
93-
self.native_handle(), p, complete_cb_ptr)
94+
uvll::uv_fs_stat(loop_.native_handle(),
95+
self.native_handle(), p, complete_cb_ptr)
9496
});
9597
assert_eq!(ret, 0);
9698
}
@@ -101,9 +103,9 @@ impl FsRequest {
101103
let base_ptr = buf.base as *c_void;
102104
let len = buf.len as uint;
103105
let ret = unsafe {
104-
uvll::fs_write(loop_.native_handle(), self.native_handle(),
105-
fd, base_ptr,
106-
len, offset, complete_cb_ptr)
106+
uvll::uv_fs_write(loop_.native_handle(), self.native_handle(),
107+
fd, base_ptr,
108+
len as c_uint, offset, complete_cb_ptr)
107109
};
108110
assert_eq!(ret, 0);
109111
}
@@ -113,9 +115,9 @@ impl FsRequest {
113115
let base_ptr = buf.base as *c_void;
114116
let len = buf.len as uint;
115117
let result = unsafe {
116-
uvll::fs_write(loop_.native_handle(), self.native_handle(),
117-
fd, base_ptr,
118-
len, offset, complete_cb_ptr)
118+
uvll::uv_fs_write(loop_.native_handle(), self.native_handle(),
119+
fd, base_ptr,
120+
len as c_uint, offset, complete_cb_ptr)
119121
};
120122
self.sync_cleanup(result)
121123
}
@@ -126,9 +128,9 @@ impl FsRequest {
126128
let buf_ptr = buf.base as *c_void;
127129
let len = buf.len as uint;
128130
let ret = unsafe {
129-
uvll::fs_read(loop_.native_handle(), self.native_handle(),
130-
fd, buf_ptr,
131-
len, offset, complete_cb_ptr)
131+
uvll::uv_fs_read(loop_.native_handle(), self.native_handle(),
132+
fd, buf_ptr,
133+
len as c_uint, offset, complete_cb_ptr)
132134
};
133135
assert_eq!(ret, 0);
134136
}
@@ -138,30 +140,44 @@ impl FsRequest {
138140
let buf_ptr = buf.base as *c_void;
139141
let len = buf.len as uint;
140142
let result = unsafe {
141-
uvll::fs_read(loop_.native_handle(), self.native_handle(),
142-
fd, buf_ptr,
143-
len, offset, complete_cb_ptr)
143+
uvll::uv_fs_read(loop_.native_handle(), self.native_handle(),
144+
fd, buf_ptr,
145+
len as c_uint, offset, complete_cb_ptr)
144146
};
145147
self.sync_cleanup(result)
146148
}
147149

150+
<<<<<<< HEAD
148151
pub fn close(mut self, loop_: &Loop, fd: c_int, cb: FsCallback) {
149152
let complete_cb_ptr = self.req_boilerplate(Some(cb));
150153
assert_eq!(unsafe {
151154
uvll::fs_close(loop_.native_handle(), self.native_handle(),
152155
fd, complete_cb_ptr)
153156
}, 0);
157+
=======
158+
pub fn close(self, loop_: &Loop, fd: c_int, cb: FsCallback) {
159+
let complete_cb_ptr = {
160+
let mut me = self;
161+
me.req_boilerplate(Some(cb))
162+
};
163+
let ret = unsafe {
164+
uvll::uv_fs_close(loop_.native_handle(), self.native_handle(),
165+
fd, complete_cb_ptr)
166+
};
167+
assert_eq!(ret, 0);
168+
>>>>>>> 1850d26... Remove lots of uv/C++ wrappers
154169
}
155170
pub fn close_sync(mut self, loop_: &Loop,
156171
fd: c_int) -> Result<c_int, UvError> {
157172
let complete_cb_ptr = self.req_boilerplate(None);
158173
let result = unsafe {
159-
uvll::fs_close(loop_.native_handle(), self.native_handle(),
160-
fd, complete_cb_ptr)
174+
uvll::uv_fs_close(loop_.native_handle(), self.native_handle(),
175+
fd, complete_cb_ptr)
161176
};
162177
self.sync_cleanup(result)
163178
}
164179

180+
<<<<<<< HEAD
165181
pub fn mkdir(mut self, loop_: &Loop, path: &CString, mode: c_int,
166182
cb: FsCallback) {
167183
let complete_cb_ptr = self.req_boilerplate(Some(cb));
@@ -198,10 +214,36 @@ impl FsRequest {
198214
uvll::fs_chmod(loop_.native_handle(), self.native_handle(), p, mode,
199215
complete_cb_ptr)
200216
}), 0);
217+
=======
218+
pub fn mkdir(self, loop_: &Loop, path: &CString, mode: int, cb: FsCallback) {
219+
let complete_cb_ptr = {
220+
let mut me = self;
221+
me.req_boilerplate(Some(cb))
222+
};
223+
let ret = path.with_ref(|p| unsafe {
224+
uvll::uv_fs_mkdir(loop_.native_handle(),
225+
self.native_handle(), p,
226+
mode as c_int, complete_cb_ptr)
227+
});
228+
assert_eq!(ret, 0);
229+
}
230+
231+
pub fn rmdir(self, loop_: &Loop, path: &CString, cb: FsCallback) {
232+
let complete_cb_ptr = {
233+
let mut me = self;
234+
me.req_boilerplate(Some(cb))
235+
};
236+
let ret = path.with_ref(|p| unsafe {
237+
uvll::uv_fs_rmdir(loop_.native_handle(),
238+
self.native_handle(), p, complete_cb_ptr)
239+
});
240+
assert_eq!(ret, 0);
241+
>>>>>>> 1850d26... Remove lots of uv/C++ wrappers
201242
}
202243

203244
pub fn readdir(mut self, loop_: &Loop, path: &CString,
204245
flags: c_int, cb: FsCallback) {
246+
<<<<<<< HEAD
205247
let complete_cb_ptr = self.req_boilerplate(Some(cb));
206248
assert_eq!(path.with_ref(|p| unsafe {
207249
uvll::fs_readdir(loop_.native_handle(),
@@ -276,6 +318,17 @@ impl FsRequest {
276318
uvll::uv_fs_fdatasync(loop_.native_handle(), self.native_handle(), fd,
277319
complete_cb_ptr)
278320
}, 0);
321+
=======
322+
let complete_cb_ptr = {
323+
let mut me = self;
324+
me.req_boilerplate(Some(cb))
325+
};
326+
let ret = path.with_ref(|p| unsafe {
327+
uvll::uv_fs_readdir(loop_.native_handle(),
328+
self.native_handle(), p, flags, complete_cb_ptr)
329+
});
330+
assert_eq!(ret, 0);
331+
>>>>>>> 1850d26... Remove lots of uv/C++ wrappers
279332
}
280333

281334
// accessors/utility funcs
@@ -287,12 +340,10 @@ impl FsRequest {
287340
None => Ok(result)
288341
}
289342
}
290-
fn req_boilerplate(&mut self, cb: Option<FsCallback>) -> *u8 {
343+
fn req_boilerplate(&mut self, cb: Option<FsCallback>) -> uvll::uv_fs_cb {
291344
let result = match cb {
292-
Some(_) => {
293-
compl_cb as *u8
294-
},
295-
None => 0 as *u8
345+
Some(_) => compl_cb,
346+
None => 0 as uvll::uv_fs_cb
296347
};
297348
self.install_req_data(cb);
298349
result
@@ -365,7 +416,7 @@ impl FsRequest {
365416
let data = uvll::get_data_for_req(self.native_handle());
366417
let _data = transmute::<*c_void, ~RequestData>(data);
367418
uvll::set_data_for_req(self.native_handle(), null::<()>());
368-
uvll::fs_req_cleanup(self.native_handle());
419+
uvll::uv_fs_req_cleanup(self.native_handle());
369420
free_req(self.native_handle() as *c_void)
370421
}
371422
}

src/librustuv/idle.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl IdleWatcher {
2121
unsafe {
2222
let handle = uvll::malloc_handle(uvll::UV_IDLE);
2323
assert!(handle.is_not_null());
24-
assert_eq!(uvll::idle_init(loop_.native_handle(), handle), 0);
24+
assert_eq!(uvll::uv_idle_init(loop_.native_handle(), handle), 0);
2525
let mut watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
2626
watcher.install_watcher_data();
2727
return watcher
@@ -35,14 +35,14 @@ impl IdleWatcher {
3535
}
3636

3737
unsafe {
38-
assert_eq!(uvll::idle_start(self.native_handle(), idle_cb), 0)
38+
assert_eq!(uvll::uv_idle_start(self.native_handle(), idle_cb), 0)
3939
}
4040
}
4141

4242
pub fn restart(&mut self) {
4343
unsafe {
4444
assert!(self.get_watcher_data().idle_cb.is_some());
45-
assert_eq!(uvll::idle_start(self.native_handle(), idle_cb), 0)
45+
assert_eq!(uvll::uv_idle_start(self.native_handle(), idle_cb), 0)
4646
}
4747
}
4848

@@ -52,7 +52,7 @@ impl IdleWatcher {
5252
// free
5353

5454
unsafe {
55-
assert_eq!(uvll::idle_stop(self.native_handle()), 0);
55+
assert_eq!(uvll::uv_idle_stop(self.native_handle()), 0);
5656
}
5757
}
5858
}

src/librustuv/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use std::str::raw::from_c_str;
4949
use std::vec;
5050
use std::ptr;
5151
use std::str;
52-
use std::libc::{c_void, c_int, size_t, malloc, free};
52+
use std::libc::{c_void, c_int, size_t, malloc, free, c_char, c_uint};
5353
use std::cast::transmute;
5454
use std::ptr::null;
5555
use std::unstable::finally::Finally;
@@ -127,11 +127,11 @@ impl Loop {
127127
}
128128

129129
pub fn run(&mut self) {
130-
unsafe { uvll::run(self.native_handle()) };
130+
unsafe { uvll::uv_run(self.native_handle(), uvll::RUN_DEFAULT) };
131131
}
132132

133133
pub fn close(&mut self) {
134-
unsafe { uvll::loop_delete(self.native_handle()) };
134+
unsafe { uvll::uv_loop_delete(self.native_handle()) };
135135
}
136136
}
137137

@@ -240,7 +240,9 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
240240
data.close_cb = Some(cb);
241241
}
242242

243-
unsafe { uvll::close(self.native_handle(), close_cb); }
243+
unsafe {
244+
uvll::uv_close(self.native_handle() as *uvll::uv_handle_t, close_cb);
245+
}
244246

245247
extern fn close_cb(handle: *uvll::uv_handle_t) {
246248
let mut h: Handle = NativeHandle::from_native_handle(handle);
@@ -251,7 +253,9 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
251253
}
252254

253255
fn close_async(self) {
254-
unsafe { uvll::close(self.native_handle(), close_cb); }
256+
unsafe {
257+
uvll::uv_close(self.native_handle() as *uvll::uv_handle_t, close_cb);
258+
}
255259

256260
extern fn close_cb(handle: *uvll::uv_handle_t) {
257261
let mut h: Handle = NativeHandle::from_native_handle(handle);
@@ -270,7 +274,7 @@ impl UvError {
270274
pub fn name(&self) -> ~str {
271275
unsafe {
272276
let inner = match self { &UvError(a) => a };
273-
let name_str = uvll::err_name(inner);
277+
let name_str = uvll::uv_err_name(inner);
274278
assert!(name_str.is_not_null());
275279
from_c_str(name_str)
276280
}
@@ -279,7 +283,7 @@ impl UvError {
279283
pub fn desc(&self) -> ~str {
280284
unsafe {
281285
let inner = match self { &UvError(a) => a };
282-
let desc_str = uvll::strerror(inner);
286+
let desc_str = uvll::uv_strerror(inner);
283287
assert!(desc_str.is_not_null());
284288
from_c_str(desc_str)
285289
}
@@ -309,7 +313,7 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
309313
use std::rt::io::*;
310314
311315
// uv error descriptions are static
312-
let c_desc = uvll::strerror(*uverr);
316+
let c_desc = uvll::uv_strerror(*uverr);
313317
let desc = str::raw::c_str_to_static_slice(c_desc);
314318
315319
let kind = match *uverr {
@@ -360,7 +364,7 @@ pub fn empty_buf() -> Buf {
360364
/// Borrow a slice to a Buf
361365
pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
362366
let data = vec::raw::to_ptr(v);
363-
unsafe { uvll::buf_init(data, v.len()) }
367+
unsafe { uvll::uv_buf_init(data as *c_char, v.len() as c_uint) }
364368
}
365369
366370
// XXX: Do these conversions without copying
@@ -376,7 +380,7 @@ pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
376380
let data = data as *mut u8;
377381
ptr::copy_memory(data, b, l)
378382
}
379-
uvll::buf_init(data, v.len())
383+
uvll::uv_buf_init(data as *c_char, v.len() as c_uint)
380384
}
381385
}
382386

0 commit comments

Comments
 (0)