Skip to content

migrate to native types #7669

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
4 changes: 2 additions & 2 deletions doc/po/tutorial-ffi.md.pot
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial-ffi.md:156
msgid ""
"~~~~ use std::cast; use std::libc::{c_void, size_t, malloc, free}; use std::"
"~~~~ use std::cast; use std::libc::{size_t, malloc, free}; use std::"
"ptr; use std::unstable::intrinsics;"
msgstr ""

Expand Down Expand Up @@ -368,7 +368,7 @@ msgid ""
" let x = intrinsics::init(); // dummy value to swap in\n"
" // moving the object out is needed to call the destructor\n"
" ptr::replace_ptr(self.ptr, x);\n"
" free(self.ptr as *c_void)\n"
" free(self.ptr as *Void)\n"
" }\n"
" }\n"
"}\n"
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ wrapping `malloc` and `free`:

~~~~
use std::cast;
use std::libc::{c_void, size_t, malloc, free};
use std::libc::{size_t, malloc, free};
use std::ptr;
use std::unstable::intrinsics;

Expand Down Expand Up @@ -188,7 +188,7 @@ impl<T: Send> Drop for Unique<T> {
let x = intrinsics::init(); // dummy value to swap in
// moving the object out is needed to call the destructor
ptr::replace_ptr(self.ptr, x);
free(self.ptr as *c_void)
free(self.ptr as *Void)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<context id="ctypes" style-ref="type">
<keyword>c_float</keyword>
<keyword>c_double</keyword>
<keyword>c_void</keyword>
<keyword>FILE</keyword>
<keyword>fpos_t</keyword>
<keyword>DIR</keyword>
Expand Down
1 change: 0 additions & 1 deletion src/etc/kate/rust.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<list name="ctypes">
<item> c_float </item>
<item> c_double </item>
<item> c_void </item>
<item> FILE </item>
<item> fpos_t </item>
<item> DIR </item>
Expand Down
4 changes: 2 additions & 2 deletions src/etc/vim/syntax/rust.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ syn keyword rustKeyword be

syn keyword rustType int uint float char bool u8 u16 u32 u64 f32
syn keyword rustType f64 i8 i16 i32 i64 str Self
syn keyword rustType Option Either
syn keyword rustType Option Either Void

" Types from libc
syn keyword rustType c_float c_double c_void FILE fpos_t
syn keyword rustType c_float c_double FILE fpos_t
syn keyword rustType DIR dirent
syn keyword rustType c_char c_schar c_uchar
syn keyword rustType c_short c_ushort c_int c_uint c_long c_ulong
Expand Down
16 changes: 8 additions & 8 deletions src/libextra/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ Simple compression

#[allow(missing_doc)];

use std::libc::{c_void, size_t, c_int};
use std::libc::{size_t, c_int};
use std::libc;
use std::vec;

pub mod rustrt {
use std::libc::{c_int, c_void, size_t};
use std::libc::{c_int, size_t};

#[link_name = "rustrt"]
pub extern {
unsafe fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
unsafe fn tdefl_compress_mem_to_heap(psrc_buf: *const Void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
-> *c_void;
-> *Void;

unsafe fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
unsafe fn tinfl_decompress_mem_to_heap(psrc_buf: *const Void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
-> *c_void;
-> *Void;
}
}

Expand All @@ -49,7 +49,7 @@ pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
unsafe {
let mut outsz : size_t = 0;
let res =
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
rustrt::tdefl_compress_mem_to_heap(b as *Void,
len as size_t,
&mut outsz,
LZ_NORM);
Expand All @@ -67,7 +67,7 @@ pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] {
unsafe {
let mut outsz : size_t = 0;
let res =
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
rustrt::tinfl_decompress_mem_to_heap(b as *Void,
len as size_t,
&mut outsz,
0);
Expand Down
18 changes: 9 additions & 9 deletions src/libextra/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub mod rustrt {
#[nolink]
pub extern {
unsafe fn rust_uv_current_kernel_malloc(size: libc::c_uint)
-> *libc::c_void;
unsafe fn rust_uv_current_kernel_free(mem: *libc::c_void);
-> *Void;
unsafe fn rust_uv_current_kernel_free(mem: *Void);
unsafe fn rust_uv_helper_uv_tcp_t_size() -> libc::c_uint;
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
uv::ll::set_data_for_uv_handle(
stream_handle_ptr,
socket_data_ptr as
*libc::c_void);
*Void);
// just so the connect_cb can send the
// outcome..
uv::ll::set_data_for_req(connect_req_ptr,
Expand Down Expand Up @@ -275,7 +275,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
debug!("tcp::connect - received failure on result_po");
// still have to free the malloc'd stream handle..
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
as *libc::c_void);
as *Void);
let tcp_conn_err = match err_data.err_name {
~"ECONNREFUSED" => ConnectionRefused,
_ => GenericConnectErr(copy err_data.err_name,
Expand Down Expand Up @@ -555,8 +555,8 @@ pub fn accept(new_conn: TcpNewConnection)
debug!("uv_tcp_init successful for \
client stream");
match uv::ll::accept(
server_handle_ptr as *libc::c_void,
client_stream_handle_ptr as *libc::c_void) {
server_handle_ptr as *Void,
client_stream_handle_ptr as *Void) {
0i32 => {
debug!("successfully accepted client \
connection: \
Expand All @@ -567,7 +567,7 @@ pub fn accept(new_conn: TcpNewConnection)
uv::ll::set_data_for_uv_handle(
client_stream_handle_ptr,
client_socket_data_ptr
as *libc::c_void);
as *Void);
let ptr = uv::ll::get_data_for_uv_handle(
client_stream_handle_ptr);
debug!("ptrs: %x %x",
Expand Down Expand Up @@ -1021,7 +1021,7 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) {
//the line below will most likely crash
//log(debug, fmt!("about to free socket_data at %?", socket_data));
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
as *libc::c_void);
as *Void);
debug!("exiting dtor for tcp_socket");
}
}
Expand Down Expand Up @@ -1303,7 +1303,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t,
}
}

extern fn on_alloc_cb(handle: *libc::c_void,
extern fn on_alloc_cb(handle: *Void,
suggested_size: size_t)
-> uv::ll::uv_buf_t {
unsafe {
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cycle cannot be created with `Rc<T>` because there is no way to modify it after


use std::cast;
use std::libc::{c_void, size_t, malloc, free};
use std::libc::{size_t, malloc, free};
use std::ptr;
use std::sys;
use std::unstable::intrinsics;
Expand Down Expand Up @@ -74,7 +74,7 @@ impl<T> Drop for Rc<T> {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::read_ptr(self.ptr);
free(self.ptr as *c_void)
free(self.ptr as *Void)
}
}
}
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<T> Drop for RcMut<T> {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, uninit());
free(self.ptr as *c_void)
free(self.ptr as *Void)
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/libextra/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::cast::transmute;
use std::cast;
use std::comm::{stream, Chan, SharedChan, Port, select2i};
use std::either;
use std::libc::c_void;
use std::libc;

/**
Expand Down Expand Up @@ -54,10 +53,10 @@ pub fn delayed_send<T:Send>(iotask: &IoTask,
timer_ptr, delayed_send_cb, msecs, 0u);
if (start_result == 0i32) {
// Note: putting the channel into a ~
// to cast to *c_void
// to cast to *Void
let timer_done_ch_clone = ~timer_done_ch.clone();
let timer_done_ch_ptr = transmute::<
~SharedChan<()>, *c_void>(
~SharedChan<()>, *Void>(
timer_done_ch_clone);
uv::ll::set_data_for_uv_handle(
timer_ptr,
Expand Down Expand Up @@ -147,9 +146,9 @@ extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t, status: libc::c_int) {
debug!(
"delayed_send_cb handle %? status %?", handle, status);
// Faking a borrowed pointer to our ~SharedChan
let timer_done_ch_ptr: &*c_void = &uv::ll::get_data_for_uv_handle(
let timer_done_ch_ptr: &*Void = &uv::ll::get_data_for_uv_handle(
handle);
let timer_done_ch_ptr = transmute::<&*c_void, &~SharedChan<()>>(
let timer_done_ch_ptr = transmute::<&*Void, &~SharedChan<()>>(
timer_done_ch_ptr);
let stop_result = uv::ll::timer_stop(handle);
if (stop_result == 0i32) {
Expand All @@ -167,7 +166,7 @@ extern fn delayed_send_close_cb(handle: *uv::ll::uv_timer_t) {
unsafe {
debug!("delayed_send_close_cb handle %?", handle);
let timer_done_ch_ptr = uv::ll::get_data_for_uv_handle(handle);
let timer_done_ch = transmute::<*c_void, ~SharedChan<()>>(
let timer_done_ch = transmute::<*Void, ~SharedChan<()>>(
timer_done_ch_ptr);
timer_done_ch.send(());
}
Expand Down
9 changes: 4 additions & 5 deletions src/libextra/uv_global_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,13 @@ mod test {
use std::libc;
use std::task;
use std::cast::transmute;
use std::libc::c_void;
use std::comm::{stream, SharedChan, Chan};

extern fn simple_timer_close_cb(timer_ptr: *ll::uv_timer_t) {
unsafe {
let exit_ch_ptr = ll::get_data_for_uv_handle(
timer_ptr as *libc::c_void);
let exit_ch = transmute::<*c_void, ~Chan<bool>>(exit_ch_ptr);
timer_ptr as *Void);
let exit_ch = transmute::<*Void, ~Chan<bool>>(exit_ch_ptr);
exit_ch.send(true);
debug!("EXIT_CH_PTR simple_timer_close_cb exit_ch_ptr: %?",
exit_ch_ptr);
Expand All @@ -160,7 +159,7 @@ mod test {
fn impl_uv_hl_simple_timer(iotask: &IoTask) {
unsafe {
let (exit_po, exit_ch) = stream::<bool>();
let exit_ch_ptr: *libc::c_void = transmute(~exit_ch);
let exit_ch_ptr: *Void = transmute(~exit_ch);
debug!("EXIT_CH_PTR newly created exit_ch_ptr: %?",
exit_ch_ptr);
let timer_handle = ll::timer_t();
Expand All @@ -170,7 +169,7 @@ mod test {
let init_status = ll::timer_init(loop_ptr, timer_ptr);
if(init_status == 0i32) {
ll::set_data_for_uv_handle(
timer_ptr as *libc::c_void,
timer_ptr as *Void,
exit_ch_ptr);
let start_status = ll::timer_start(timer_ptr,
simple_timer_cb,
Expand Down
18 changes: 8 additions & 10 deletions src/libextra/uv_iotask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
use ll = uv_ll;

use std::comm::{stream, Port, Chan, SharedChan};
use std::libc::c_void;
use std::libc;
use std::task;

/// Used to abstract-away direct interaction with a libuv loop.
Expand Down Expand Up @@ -76,7 +74,7 @@ pub fn spawn_iotask(mut task: task::TaskBuilder) -> IoTask {
* module. It is not safe to send the `loop_ptr` param to this callback out
* via ports/chans.
*/
pub fn interact(iotask: &IoTask, cb: ~fn(*c_void)) {
pub fn interact(iotask: &IoTask, cb: ~fn(*Void)) {
send_msg(iotask, Interaction(cb));
}

Expand All @@ -95,7 +93,7 @@ pub fn exit(iotask: &IoTask) {
// INTERNAL API

enum IoTaskMsg {
Interaction(~fn(*libc::c_void)),
Interaction(~fn(*Void)),
TeardownLoop
}

Expand Down Expand Up @@ -179,10 +177,10 @@ fn begin_teardown(data: *IoTaskLoopData) {
unsafe {
debug!("iotask begin_teardown() called, close async_handle");
let async_handle = (*data).async_handle;
ll::close(async_handle as *c_void, tear_down_close_cb);
ll::close(async_handle as *Void, tear_down_close_cb);
}
}
extern fn tear_down_walk_cb(handle: *libc::c_void, arg: *libc::c_void) {
extern fn tear_down_walk_cb(handle: *Void, arg: *Void) {
debug!("IN TEARDOWN WALK CB");
// pretty much, if we still have an active handle and it is *not*
// the async handle that facilities global loop communication, we
Expand All @@ -194,7 +192,7 @@ extern fn tear_down_close_cb(handle: *ll::uv_async_t) {
unsafe {
let loop_ptr = ll::get_loop_for_uv_handle(handle);
debug!("in tear_down_close_cb");
ll::walk(loop_ptr, tear_down_walk_cb, handle as *libc::c_void);
ll::walk(loop_ptr, tear_down_walk_cb, handle as *Void);
}
}

Expand Down Expand Up @@ -241,7 +239,7 @@ fn impl_uv_iotask_async(iotask: &IoTask) {
debug!("interacting");
ll::async_init(loop_ptr, ah_ptr, async_handle_cb);
ll::set_data_for_uv_handle(
ah_ptr, ah_data_ptr as *libc::c_void);
ah_ptr, ah_data_ptr as *Void);
ll::async_send(ah_ptr);
}
};
Expand All @@ -263,12 +261,12 @@ fn spawn_test_loop(exit_ch: ~Chan<()>) -> IoTask {
}

#[cfg(test)]
extern fn lifetime_handle_close(handle: *libc::c_void) {
extern fn lifetime_handle_close(handle: *Void) {
debug!("lifetime_handle_close ptr %?", handle);
}

#[cfg(test)]
extern fn lifetime_async_callback(handle: *libc::c_void,
extern fn lifetime_async_callback(handle: *Void,
status: libc::c_int) {
debug!("lifetime_handle_close ptr %? status %?",
handle, status);
Expand Down
Loading