From 92b032433af36f2ef2352e954664c56cf306c2cd Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 13 May 2013 16:13:20 -0700 Subject: [PATCH 1/2] librustc: Disallow `use` from reaching into impls or traits. This can perhaps be restored in the future. For now this is a precursor to making typedefs work as expected. --- src/librustc/middle/resolve.rs | 194 +++++++++++++++------ src/librustpkg/rustpkg.rc | 21 ++- src/test/auxiliary/use_from_trait_xc.rs | 10 ++ src/test/compile-fail/use-from-trait-xc.rs | 12 ++ src/test/compile-fail/use-from-trait.rs | 17 ++ 5 files changed, 187 insertions(+), 67 deletions(-) create mode 100644 src/test/auxiliary/use_from_trait_xc.rs create mode 100644 src/test/compile-fail/use-from-trait-xc.rs create mode 100644 src/test/compile-fail/use-from-trait.rs diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index d2c8320d8baf5..7eed50855c436 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -290,8 +290,20 @@ pub enum AllowCapturingSelfFlag { #[deriving(Eq)] enum NameSearchType { - SearchItemsAndPublicImports, //< Search items and public imports. - SearchItemsAndAllImports, //< Search items and all imports. + /// We're doing a name search in order to resolve a `use` directive. + ImportSearch, + + /// We're doing a name search in order to resolve a path type, a path + /// expression, or a path pattern. We can select public or private + /// names. + /// + /// XXX: This should be ripped out of resolve and handled later, in + /// the privacy checking phase. + PathPublicOrPrivateSearch, + + /// We're doing a name search in order to resolve a path type, a path + /// expression, or a path pattern. Allow only public names to be selected. + PathPublicOnlySearch, } pub enum BareIdentifierPatternResolution { @@ -425,7 +437,10 @@ pub struct ImportState { } pub fn ImportState() -> ImportState { - ImportState{ used: false, warned: false } + ImportState { + used: false, + warned: false, + } } /// The link from a module up to its nearest parent node. @@ -440,6 +455,7 @@ pub enum ModuleKind { NormalModuleKind, ExternModuleKind, TraitModuleKind, + ImplModuleKind, AnonymousModuleKind, } @@ -470,7 +486,6 @@ pub struct Module { // // There will be an anonymous module created around `g` with the ID of the // entry block for `f`. - anonymous_children: @mut HashMap, // The status of resolving each import in this module. @@ -562,6 +577,38 @@ pub impl NameBindings { self.type_span = Some(sp); } + /// Sets the kind of the module, creating a new one if necessary. + fn set_module_kind(@mut self, + privacy: Privacy, + parent_link: ParentLink, + def_id: Option, + kind: ModuleKind, + sp: span) { + match self.type_def { + None => { + let module = @mut Module(parent_link, def_id, kind); + self.type_def = Some(TypeNsDef { + privacy: privacy, + module_def: Some(module), + type_def: None + }) + } + Some(type_def) => { + match type_def.module_def { + None => { + let module = @mut Module(parent_link, def_id, kind); + self.type_def = Some(TypeNsDef { + privacy: privacy, + module_def: Some(module), + type_def: type_def.type_def + }) + } + Some(module_def) => module_def.kind = kind, + } + } + } + } + /// Records a type definition. fn define_type(@mut self, privacy: Privacy, def: def, sp: span) { // Merges the type with the existing type def or creates a new one. @@ -1228,7 +1275,7 @@ pub impl Resolver { name_bindings.define_module(Public, parent_link, Some(def_id), - TraitModuleKind, + ImplModuleKind, sp); let new_parent = ModuleReducedGraphParent( @@ -1608,8 +1655,8 @@ pub impl Resolver { // If this is a trait, add all the method names // to the trait info. - let method_def_ids = get_trait_method_def_ids(self.session.cstore, - def_id); + let method_def_ids = + get_trait_method_def_ids(self.session.cstore, def_id); let mut interned_method_names = HashSet::new(); for method_def_ids.each |&method_def_id| { let (method_name, self_ty) = @@ -1629,6 +1676,14 @@ pub impl Resolver { self.trait_info.insert(def_id, interned_method_names); child_name_bindings.define_type(Public, def, dummy_sp()); + + // Define a module if necessary. + let parent_link = self.get_parent_link(new_parent, ident); + child_name_bindings.set_module_kind(Public, + parent_link, + Some(def_id), + TraitModuleKind, + dummy_sp()) } def_ty(_) => { debug!("(building reduced graph for external \ @@ -1771,6 +1826,10 @@ pub impl Resolver { // We already have a module. This // is OK. type_module = module_def; + + // Mark it as an impl module if + // necessary. + type_module.kind = ImplModuleKind; } Some(_) | None => { let parent_link = @@ -1780,7 +1839,7 @@ pub impl Resolver { Public, parent_link, Some(def), - NormalModuleKind, + ImplModuleKind, dummy_sp()); type_module = child_name_bindings. @@ -1891,10 +1950,8 @@ pub impl Resolver { // remain or unsuccessfully when no forward progress in resolving imports // is made. - /** - * Resolves all imports for the crate. This method performs the fixed- - * point iteration. - */ + /// Resolves all imports for the crate. This method performs the fixed- + /// point iteration. fn resolve_imports(@mut self) { let mut i = 0; let mut prev_unresolved_imports = 0; @@ -2016,9 +2073,10 @@ pub impl Resolver { /// don't know whether the name exists at the moment due to other /// currently-unresolved imports, or success if we know the name exists. /// If successful, the resolved bindings are written into the module. - fn resolve_import_for_module(@mut self, module_: @mut Module, + fn resolve_import_for_module(@mut self, + module_: @mut Module, import_directive: @ImportDirective) - -> ResolveResult<()> { + -> ResolveResult<()> { let mut resolution_result = Failed; let module_path = &import_directive.module_path; @@ -2032,10 +2090,11 @@ pub impl Resolver { // Use the crate root. Some(self.graph_root.get_module()) } else { - match self.resolve_module_path_for_import(module_, - *module_path, - DontUseLexicalScope, - import_directive.span) { + match self.resolve_module_path(module_, + *module_path, + DontUseLexicalScope, + import_directive.span, + ImportSearch) { Failed => None, Indeterminate => { @@ -2122,7 +2181,7 @@ pub impl Resolver { containing_module: @mut Module, target: ident, source: ident) - -> ResolveResult<()> { + -> ResolveResult<()> { debug!("(resolving single import) resolving `%s` = `%s::%s` from \ `%s`", *self.session.str_of(target), @@ -2159,9 +2218,7 @@ pub impl Resolver { // Unless we managed to find a result in both namespaces (unlikely), // search imports as well. match (value_result, type_result) { - (BoundResult(*), BoundResult(*)) => { - // Continue. - } + (BoundResult(*), BoundResult(*)) => {} // Continue. _ => { // If there is an unresolved glob at this point in the // containing module, bail out. We don't know enough to be @@ -2489,7 +2546,6 @@ pub impl Resolver { // Resolve the module part of the path. This does not involve looking // upward though scope chains; we simply resolve names directly in // modules as we go. - while index < module_path_len { let name = module_path[index]; match self.resolve_name_in_module(search_module, @@ -2499,12 +2555,17 @@ pub impl Resolver { Failed => { let segment_name = self.session.str_of(name); let module_name = self.module_to_str(search_module); - if module_name == ~"???" { - self.session.span_err(span {lo: span.lo, hi: span.lo + - BytePos(str::len(*segment_name)), expn_info: - span.expn_info}, fmt!("unresolved import. maybe \ - a missing `extern mod %s`?", - *segment_name)); + if "???" == module_name { + let span = span { + lo: span.lo, + hi: span.lo + BytePos(str::len(*segment_name)), + expn_info: span.expn_info, + }; + self.session.span_err(span, + fmt!("unresolved import. maybe \ + a missing `extern mod \ + %s`?", + *segment_name)); return Failed; } self.session.span_err(span, fmt!("unresolved import: could not find `%s` in \ @@ -2533,8 +2594,22 @@ pub impl Resolver { name))); return Failed; } - Some(copy module_def) => { - search_module = module_def; + Some(module_def) => { + // If we're doing the search for an + // import, do not allow traits and impls + // to be selected. + match (name_search_type, + module_def.kind) { + (ImportSearch, TraitModuleKind) | + (ImportSearch, ImplModuleKind) => { + self.session.span_err( + span, + ~"cannot import from a trait \ + or type implementation"); + return Failed; + } + (_, _) => search_module = module_def, + } } } } @@ -2552,18 +2627,13 @@ pub impl Resolver { index += 1; - // After the first element of the path, allow searching through - // items and imports unconditionally. This allows things like: - // - // pub mod core { - // pub use vec; - // } + // After the first element of the path, allow searching only + // through public identifiers. // - // pub mod something_else { - // use core::vec; - // } - - name_search_type = SearchItemsAndPublicImports; + // XXX: Rip this out and move it to the privacy checker. + if name_search_type == PathPublicOrPrivateSearch { + name_search_type = PathPublicOnlySearch + } } return Success(search_module); @@ -2571,12 +2641,13 @@ pub impl Resolver { /// Attempts to resolve the module part of an import directive or path /// rooted at the given module. - fn resolve_module_path_for_import(@mut self, - module_: @mut Module, - module_path: &[ident], - use_lexical_scope: UseLexicalScopeFlag, - span: span) - -> ResolveResult<@mut Module> { + fn resolve_module_path(@mut self, + module_: @mut Module, + module_path: &[ident], + use_lexical_scope: UseLexicalScopeFlag, + span: span, + name_search_type: NameSearchType) + -> ResolveResult<@mut Module> { let module_path_len = module_path.len(); assert!(module_path_len > 0); @@ -2648,7 +2719,7 @@ pub impl Resolver { module_path, start_index, span, - SearchItemsAndPublicImports) + name_search_type) } /// Invariant: This must only be called during main resolution, not during @@ -2740,6 +2811,7 @@ pub impl Resolver { } ExternModuleKind | TraitModuleKind | + ImplModuleKind | AnonymousModuleKind => { search_module = parent_module_node; } @@ -2759,7 +2831,7 @@ pub impl Resolver { match self.resolve_name_in_module(search_module, name, namespace, - SearchItemsAndAllImports) { + PathPublicOrPrivateSearch) { Failed => { // Continue up the search chain. } @@ -2840,6 +2912,7 @@ pub impl Resolver { NormalModuleKind => return Some(new_module), ExternModuleKind | TraitModuleKind | + ImplModuleKind | AnonymousModuleKind => module_ = new_module, } } @@ -2856,7 +2929,10 @@ pub impl Resolver { -> @mut Module { match module_.kind { NormalModuleKind => return module_, - ExternModuleKind | TraitModuleKind | AnonymousModuleKind => { + ExternModuleKind | + TraitModuleKind | + ImplModuleKind | + AnonymousModuleKind => { match self.get_nearest_normal_module_parent(module_) { None => module_, Some(new_module) => new_module @@ -2940,7 +3016,8 @@ pub impl Resolver { // If this is a search of all imports, we should be done with glob // resolution at this point. - if name_search_type == SearchItemsAndAllImports { + if name_search_type == PathPublicOrPrivateSearch || + name_search_type == PathPublicOnlySearch { assert!(module_.glob_count == 0); } @@ -2962,7 +3039,7 @@ pub impl Resolver { } Some(target) if name_search_type == - SearchItemsAndAllImports || + PathPublicOrPrivateSearch || import_resolution.privacy == Public => { debug!("(resolving name in module) resolved to \ import"); @@ -4488,10 +4565,11 @@ pub impl Resolver { let module_path_idents = self.intern_module_part_of_path(path); let containing_module; - match self.resolve_module_path_for_import(self.current_module, - module_path_idents, - UseLexicalScope, - path.span) { + match self.resolve_module_path(self.current_module, + module_path_idents, + UseLexicalScope, + path.span, + PathPublicOnlySearch) { Failed => { self.session.span_err(path.span, fmt!("use of undeclared module `%s`", @@ -4540,7 +4618,7 @@ pub impl Resolver { module_path_idents, 0, path.span, - SearchItemsAndAllImports) { + PathPublicOrPrivateSearch) { Failed => { self.session.span_err(path.span, fmt!("use of undeclared module `::%s`", diff --git a/src/librustpkg/rustpkg.rc b/src/librustpkg/rustpkg.rc index 502f34a4d9e47..95fba0fa227a4 100644 --- a/src/librustpkg/rustpkg.rc +++ b/src/librustpkg/rustpkg.rc @@ -712,7 +712,6 @@ impl PkgSrc { /// Infers crates to build. Called only in the case where there /// is no custom build logic fn find_crates(&mut self) { - use PkgSrc::push_crate; use conditions::missing_pkg_files::cond; let dir = self.check_dir(); @@ -720,14 +719,18 @@ impl PkgSrc { debug!("Matching against %?", self.id.path.filestem()); for os::walk_dir(&dir) |pth| { match pth.filename() { - Some(~"lib.rs") => push_crate(&mut self.libs, - prefix, pth), - Some(~"main.rs") => push_crate(&mut self.mains, - prefix, pth), - Some(~"test.rs") => push_crate(&mut self.tests, - prefix, pth), - Some(~"bench.rs") => push_crate(&mut self.benchs, - prefix, pth), + Some(~"lib.rs") => PkgSrc::push_crate(&mut self.libs, + prefix, + pth), + Some(~"main.rs") => PkgSrc::push_crate(&mut self.mains, + prefix, + pth), + Some(~"test.rs") => PkgSrc::push_crate(&mut self.tests, + prefix, + pth), + Some(~"bench.rs") => PkgSrc::push_crate(&mut self.benchs, + prefix, + pth), _ => () } } diff --git a/src/test/auxiliary/use_from_trait_xc.rs b/src/test/auxiliary/use_from_trait_xc.rs new file mode 100644 index 0000000000000..2ab95c271aec7 --- /dev/null +++ b/src/test/auxiliary/use_from_trait_xc.rs @@ -0,0 +1,10 @@ +pub trait Trait { + fn foo(); +} + +struct Foo; + +impl Foo { + pub fn new() {} +} + diff --git a/src/test/compile-fail/use-from-trait-xc.rs b/src/test/compile-fail/use-from-trait-xc.rs new file mode 100644 index 0000000000000..56805f58ad29a --- /dev/null +++ b/src/test/compile-fail/use-from-trait-xc.rs @@ -0,0 +1,12 @@ +// aux-build:use_from_trait_xc.rs + +extern mod use_from_trait_xc; + +use use_from_trait_xc::Trait::foo; //~ ERROR cannot import from a trait or type implementation +//~^ ERROR failed to resolve import +use use_from_trait_xc::Foo::new; //~ ERROR cannot import from a trait or type implementation +//~^ ERROR failed to resolve import + +fn main() { +} + diff --git a/src/test/compile-fail/use-from-trait.rs b/src/test/compile-fail/use-from-trait.rs new file mode 100644 index 0000000000000..10a30f0a266b3 --- /dev/null +++ b/src/test/compile-fail/use-from-trait.rs @@ -0,0 +1,17 @@ +use Trait::foo; //~ ERROR cannot import from a trait or type implementation +//~^ ERROR failed to resolve import +use Foo::new; //~ ERROR cannot import from a trait or type implementation +//~^ ERROR failed to resolve import + +pub trait Trait { + fn foo(); +} + +struct Foo; + +impl Foo { + fn new() {} +} + +fn main() {} + From 3e143ad34f12354b1373386e79ace13ba26a0062 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 14 May 2013 19:49:02 -0700 Subject: [PATCH 2/2] 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. --- src/libcore/rt/context.rs | 2 +- src/libcore/rt/local_services.rs | 7 + src/libcore/rt/uv/net.rs | 22 +- src/libcore/rt/uvll.rs | 124 ++++++++++- src/libcore/task/local_data_priv.rs | 3 +- src/libcore/task/rt.rs | 7 + src/librustc/middle/trans/expr.rs | 10 +- src/librustc/middle/ty.rs | 9 + src/librustc/middle/typeck/check/mod.rs | 32 ++- src/librustc/middle/typeck/collect.rs | 6 +- src/libstd/net_tcp.rs | 3 +- src/libstd/rl.rs | 7 +- src/libstd/uv_iotask.rs | 2 +- src/libstd/uv_ll.rs | 273 +++++++++++++++++++++--- 14 files changed, 437 insertions(+), 70 deletions(-) diff --git a/src/libcore/rt/context.rs b/src/libcore/rt/context.rs index 9c1e566f218f6..4ba54f2ad8dfb 100644 --- a/src/libcore/rt/context.rs +++ b/src/libcore/rt/context.rs @@ -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) }; diff --git a/src/libcore/rt/local_services.rs b/src/libcore/rt/local_services.rs index 01bef5e245888..e5b1eb60f7d05 100644 --- a/src/libcore/rt/local_services.rs +++ b/src/libcore/rt/local_services.rs @@ -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; } } diff --git a/src/libcore/rt/uv/net.rs b/src/libcore/rt/uv/net.rs index 376231e3b27c5..ee961834961ec 100644 --- a/src/libcore/rt/uv/net.rs +++ b/src/libcore/rt/uv/net.rs @@ -62,7 +62,6 @@ 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) }); @@ -70,7 +69,9 @@ pub impl StreamWatcher { 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); @@ -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) { @@ -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); @@ -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!() @@ -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) { diff --git a/src/libcore/rt/uvll.rs b/src/libcore/rt/uvll.rs index 4bff3bff7d3ae..070f27bdd3993 100644 --- a/src/libcore/rt/uvll.rs +++ b/src/libcore/rt/uvll.rs @@ -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; @@ -146,10 +149,17 @@ pub unsafe fn run(loop_handle: *c_void) { rust_uv_run(loop_handle); } +#[cfg(stage0)] pub unsafe fn close(handle: *T, cb: *u8) { rust_uv_close(handle as *c_void, cb); } +#[cfg(not(stage0))] +pub unsafe fn close(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); } @@ -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, @@ -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(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(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(req: *uv_write_t, stream: *T, buf_in: &[uv_buf_t], cb: *u8) -> c_int { +#[cfg(stage0)] +pub unsafe fn write(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(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); } @@ -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; @@ -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 @@ -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; diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index a30db039f30d7..87acbe275e92b 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -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]; +pub type TaskLocalMap = @mut ~[Option]; fn cleanup_task_local_map(map_ptr: *libc::c_void) { unsafe { @@ -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); } diff --git a/src/libcore/task/rt.rs b/src/libcore/task/rt.rs index 760812252bc73..2a4f3de023f21 100644 --- a/src/libcore/task/rt.rs +++ b/src/libcore/task/rt.rs @@ -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; @@ -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)); } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 59526ffbe498d..08a5fb9ff1be0 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1644,10 +1644,16 @@ fn trans_imm_cast(bcx: block, expr: @ast::expr, val_ty(lldiscrim_a), lldiscrim_a, true), cast_float => SIToFP(bcx, lldiscrim_a, ll_t_out), - _ => ccx.sess.bug(~"translating unsupported cast.") + _ => { + ccx.sess.span_bug(expr.span, + ~"translating unsupported cast.") + } } } - _ => ccx.sess.bug(~"translating unsupported cast.") + _ => { + ccx.sess.span_bug(expr.span, + ~"translating unsupported cast.") + } }; return immediate_rvalue_bcx(bcx, newval, t_out); } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 5eaa6478ecfb6..395dbc758f109 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1769,6 +1769,15 @@ pub fn type_is_unique(ty: t) -> bool { } } +pub fn type_is_castable(ty: t) -> bool { + match get(ty).sty { + ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) | + ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) | ty_type | + ty_ptr(_) => true, + _ => false + } +} + /* A scalar type is one that denotes an atomic datum, with no sub-components. (A ty_ptr is scalar because it represents a non-managed pointer, so its diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 2096299f2cff5..285c7afbe552c 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2644,9 +2644,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, }, t_e, None); } - let t_1_is_scalar = type_is_scalar(fcx, expr.span, t_1); + let t_1_is_castable = type_is_castable(fcx, + expr.span, + t_1); if type_is_c_like_enum(fcx,expr.span,t_e) - && t_1_is_scalar { + && t_1_is_castable { /* this case is allowed */ } else if type_is_region_ptr(fcx, expr.span, t_e) && type_is_unsafe_ptr(fcx, expr.span, t_1) { @@ -2689,8 +2691,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, demand::coerce(fcx, e.span, t_1, e); } } - } else if !(type_is_scalar(fcx,expr.span,t_e) - && t_1_is_scalar) { + } else if !(type_is_castable(fcx,expr.span,t_e) + && t_1_is_castable) { /* If more type combinations should be supported than are supported here, then file an enhancement issue and @@ -3214,21 +3216,6 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt, let typ = fcx.local_ty(sp, nid); return no_params(typ); } - ast::def_fn(_, ast::extern_fn) => { - // extern functions are just u8 pointers - return ty_param_bounds_and_ty { - generics: ty::Generics { - type_param_defs: @~[], - region_param: None - }, - ty: ty::mk_ptr( - fcx.ccx.tcx, - ty::mt { - ty: ty::mk_mach_uint(ast::ty_u8), - mutbl: ast::m_imm - }) - }; - } ast::def_fn(id, ast::unsafe_fn) | ast::def_static_method(id, _, ast::unsafe_fn) => { @@ -3248,7 +3235,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt, ast::def_trait(_) | ast::def_ty(_) | ast::def_prim_ty(_) | - ast::def_ty_param(*)=> { + ast::def_ty_param(*) => { fcx.ccx.tcx.sess.span_bug(sp, "expected value but found type"); } ast::def_mod(*) | ast::def_foreign_mod(*) => { @@ -3360,6 +3347,11 @@ pub fn type_is_integral(fcx: @mut FnCtxt, sp: span, typ: ty::t) -> bool { return ty::type_is_integral(typ_s); } +pub fn type_is_castable(fcx: @mut FnCtxt, sp: span, typ: ty::t) -> bool { + let typ_s = structurally_resolved_type(fcx, sp, typ); + return ty::type_is_castable(typ_s); +} + pub fn type_is_scalar(fcx: @mut FnCtxt, sp: span, typ: ty::t) -> bool { let typ_s = structurally_resolved_type(fcx, sp, typ); return ty::type_is_scalar(typ_s); diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 03601a716c020..9bd0e12023ff6 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -1069,10 +1069,14 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item) ast::item_fn(ref decl, purity, _, ref generics, _) => { assert!(rp.is_none()); let ty_generics = ty_generics(ccx, None, generics, 0); + let abi = match purity { + ast::extern_fn => AbiSet::C(), + _ => AbiSet::Rust(), + }; let tofd = astconv::ty_of_bare_fn(ccx, &empty_rscope, purity, - AbiSet::Rust(), + abi, &generics.lifetimes, decl); let tpt = ty_param_bounds_and_ty { diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 20e1a272910cc..956f73d8dcd22 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -1408,7 +1408,8 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t, result_ch.send(ConnFailure(err_data)); uv::ll::set_data_for_uv_handle(tcp_stream_ptr, conn_data_ptr); - uv::ll::close(tcp_stream_ptr, stream_error_close_cb); + uv::ll::close(tcp_stream_ptr as *uv::ll::uv_tcp_t, + stream_error_close_cb); } } debug!("leaving tcp_connect_on_connect_cb"); diff --git a/src/libstd/rl.rs b/src/libstd/rl.rs index 81152430e784b..77cdc8f935a7f 100644 --- a/src/libstd/rl.rs +++ b/src/libstd/rl.rs @@ -22,8 +22,13 @@ pub mod rustrt { pub unsafe fn linenoiseHistorySetMaxLen(len: c_int) -> c_int; pub unsafe fn linenoiseHistorySave(file: *c_char) -> c_int; pub unsafe fn linenoiseHistoryLoad(file: *c_char) -> c_int; - pub unsafe fn linenoiseSetCompletionCallback(callback: *u8); pub unsafe fn linenoiseAddCompletion(completions: *(), line: *c_char); + + #[cfg(stage0)] + pub unsafe fn linenoiseSetCompletionCallback(callback: *u8); + #[cfg(not(stage0))] + pub unsafe fn linenoiseSetCompletionCallback( + callback: extern "C" fn(a: *i8, b: *())); } } diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index 2922f403f34a6..b8f214c488fa4 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -175,7 +175,7 @@ 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 *ll::uv_async_t, tear_down_close_cb); } } extern fn tear_down_walk_cb(handle: *libc::c_void, arg: *libc::c_void) { diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index a14c048b8ded5..6f2e0a8b3b16d 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -735,9 +735,21 @@ extern { unsafe fn rust_uv_loop_new() -> *libc::c_void; unsafe fn rust_uv_loop_delete(lp: *libc::c_void); unsafe fn rust_uv_run(loop_handle: *libc::c_void); + + #[cfg(stage0)] unsafe fn rust_uv_close(handle: *libc::c_void, cb: *u8); + #[cfg(not(stage0))] + unsafe fn rust_uv_close(handle: *libc::c_void, + cb: extern "C" fn(a: *c_void)); + + #[cfg(stage0)] unsafe fn rust_uv_walk(loop_handle: *libc::c_void, cb: *u8, arg: *libc::c_void); + #[cfg(not(stage0))] + unsafe fn rust_uv_walk(loop_handle: *libc::c_void, + cb: extern "C" fn(a: *libc::c_void, + b: *libc::c_void), + arg: *libc::c_void); unsafe fn rust_uv_idle_new() -> *uv_idle_t; unsafe fn rust_uv_idle_delete(handle: *uv_idle_t); @@ -748,9 +760,18 @@ extern { unsafe fn rust_uv_idle_stop(handle: *uv_idle_t) -> libc::c_int; unsafe fn rust_uv_async_send(handle: *uv_async_t); + + #[cfg(stage0)] unsafe fn rust_uv_async_init(loop_handle: *libc::c_void, - async_handle: *uv_async_t, - cb: *u8) -> libc::c_int; + async_handle: *uv_async_t, + cb: *u8) + -> libc::c_int; + #[cfg(not(stage0))] + unsafe fn rust_uv_async_init(loop_handle: *libc::c_void, + async_handle: *uv_async_t, + cb: extern "C" fn(a: *uv_async_t, b: int)) + -> libc::c_int; + unsafe fn rust_uv_tcp_init( loop_handle: *libc::c_void, handle_ptr: *uv_tcp_t) -> libc::c_int; @@ -776,53 +797,114 @@ extern { -> libc::c_int; unsafe fn rust_uv_ip4_port(src: *sockaddr_in) -> libc::c_uint; unsafe fn rust_uv_ip6_port(src: *sockaddr_in6) -> libc::c_uint; + // FIXME ref #2064 + #[cfg(stage0)] unsafe fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t, after_cb: *u8, addr: *sockaddr_in) -> libc::c_int; + + // FIXME ref #2064 + #[cfg(not(stage0))] + unsafe fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t, + tcp_handle_ptr: *uv_tcp_t, + after_cb: extern "C" fn(a: *uv_connect_t, + b: i32), + addr: *sockaddr_in) + -> libc::c_int; + // FIXME ref #2064 unsafe fn rust_uv_tcp_bind(tcp_server: *uv_tcp_t, addr: *sockaddr_in) -> libc::c_int; + // FIXME ref #2064 + #[cfg(stage0)] unsafe fn rust_uv_tcp_connect6(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t, after_cb: *u8, addr: *sockaddr_in6) -> libc::c_int; // FIXME ref #2064 + #[cfg(not(stage0))] + unsafe fn rust_uv_tcp_connect6(connect_ptr: *uv_connect_t, + tcp_handle_ptr: *uv_tcp_t, + after_cb: extern "C" fn(a: *uv_connect_t, + b: i32), + addr: *sockaddr_in6) + -> libc::c_int; + + // FIXME ref #2064 unsafe fn rust_uv_tcp_bind6(tcp_server: *uv_tcp_t, addr: *sockaddr_in6) -> libc::c_int; unsafe fn rust_uv_tcp_getpeername(tcp_handle_ptr: *uv_tcp_t, name: *sockaddr_in) -> libc::c_int; unsafe fn rust_uv_tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t, name: *sockaddr_in6) ->libc::c_int; + + #[cfg(stage0)] unsafe fn rust_uv_listen(stream: *libc::c_void, backlog: libc::c_int, cb: *u8) -> libc::c_int; + #[cfg(not(stage0))] + unsafe fn rust_uv_listen(stream: *libc::c_void, + backlog: libc::c_int, + cb: extern "C" fn(a: *uv_tcp_t, b: i32)) + -> libc::c_int; + unsafe fn rust_uv_accept(server: *libc::c_void, client: *libc::c_void) -> libc::c_int; + + #[cfg(stage0)] unsafe fn rust_uv_write(req: *libc::c_void, stream: *libc::c_void, buf_in: *uv_buf_t, buf_cnt: libc::c_int, cb: *u8) -> libc::c_int; + #[cfg(not(stage0))] + unsafe fn rust_uv_write(req: *libc::c_void, + stream: *libc::c_void, + buf_in: *uv_buf_t, + buf_cnt: libc::c_int, + cb: extern "C" fn(*uv_write_t, i32)) + -> libc::c_int; + + #[cfg(stage0)] unsafe fn rust_uv_read_start(stream: *libc::c_void, on_alloc: *u8, on_read: *u8) -> libc::c_int; + #[cfg(not(stage0))] + unsafe fn rust_uv_read_start(stream: *libc::c_void, + on_alloc: extern "C" fn(a: *c_void, b: u64) + -> uv_buf_t, + on_read: extern "C" fn(a: *uv_stream_t, + b: i64, + c: uv_buf_t)) + -> libc::c_int; + unsafe fn rust_uv_read_stop(stream: *libc::c_void) -> libc::c_int; unsafe fn rust_uv_timer_init(loop_handle: *libc::c_void, timer_handle: *uv_timer_t) -> libc::c_int; + + #[cfg(stage0)] unsafe fn rust_uv_timer_start( timer_handle: *uv_timer_t, cb: *u8, timeout: libc::c_uint, repeat: libc::c_uint) -> libc::c_int; + #[cfg(not(stage0))] + unsafe fn rust_uv_timer_start( + timer_handle: *uv_timer_t, + cb: extern "C" fn(a: *uv_timer_t, b: i32), + timeout: libc::c_uint, + repeat: libc::c_uint) -> libc::c_int; + unsafe fn rust_uv_timer_stop(handle: *uv_timer_t) -> libc::c_int; + #[cfg(stage0)] unsafe fn rust_uv_getaddrinfo(loop_ptr: *libc::c_void, handle: *uv_getaddrinfo_t, cb: *u8, @@ -830,7 +912,21 @@ extern { service_name_ptr: *u8, // should probably only pass ptr::null() hints: *addrinfo) - -> libc::c_int; + -> libc::c_int; + + #[cfg(not(stage0))] + unsafe fn rust_uv_getaddrinfo(loop_ptr: *libc::c_void, + handle: *uv_getaddrinfo_t, + cb: extern "C" fn( + a: *uv_getaddrinfo_t, + b: i32, + c: *addrinfo_impl::addrinfo), + node_name_ptr: *u8, + service_name_ptr: *u8, + // should probably only pass ptr::null() + hints: *addrinfo) + -> libc::c_int; + unsafe fn rust_uv_freeaddrinfo(res: *addrinfo); // data accessors/helpers for rust-mapped uv structs @@ -894,14 +990,28 @@ pub unsafe fn run(loop_handle: *libc::c_void) { rust_uv_run(loop_handle); } +#[cfg(stage0)] pub unsafe fn close(handle: *T, cb: *u8) { rust_uv_close(handle as *libc::c_void, cb); } +#[cfg(not(stage0))] +pub unsafe fn close(handle: *T, cb: extern "C" fn(a: *T)) { + rust_uv_close(handle as *libc::c_void, ::core::cast::transmute(cb)); +} + +#[cfg(stage0)] pub unsafe fn walk(loop_handle: *libc::c_void, cb: *u8, arg: *libc::c_void) { rust_uv_walk(loop_handle, cb, arg); } +#[cfg(not(stage0))] +pub unsafe fn walk(loop_handle: *libc::c_void, + cb: extern "C" fn(a: *c_void, b: *c_void), + arg: *libc::c_void) { + rust_uv_walk(loop_handle, cb, arg); +} + pub unsafe fn idle_new() -> *uv_idle_t { rust_uv_idle_new() } @@ -927,16 +1037,36 @@ pub unsafe fn tcp_init(loop_handle: *libc::c_void, handle: *uv_tcp_t) -> libc::c_int { return rust_uv_tcp_init(loop_handle, handle); } + // 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) --> libc::c_int { - return rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr, - after_connect_cb, addr_ptr); + tcp_handle_ptr: *uv_tcp_t, + addr_ptr: *sockaddr_in, + after_connect_cb: *u8) + -> libc::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: extern "C" fn(a: *uv_connect_t, + b: i32)) + -> libc::c_int { + return rust_uv_tcp_connect(connect_ptr, + tcp_handle_ptr, + after_connect_cb, + addr_ptr); } + // FIXME ref #2064 +#[cfg(stage0)] pub unsafe fn tcp_connect6(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t, addr_ptr: *sockaddr_in6, @@ -945,6 +1075,21 @@ pub unsafe fn tcp_connect6(connect_ptr: *uv_connect_t, return rust_uv_tcp_connect6(connect_ptr, tcp_handle_ptr, after_connect_cb, addr_ptr); } + +// FIXME ref #2064 +#[cfg(not(stage0))] +pub unsafe fn tcp_connect6(connect_ptr: *uv_connect_t, + tcp_handle_ptr: *uv_tcp_t, + addr_ptr: *sockaddr_in6, + after_connect_cb: extern "C" fn(a: *uv_connect_t, + b: i32)) + -> libc::c_int { + return rust_uv_tcp_connect6(connect_ptr, + tcp_handle_ptr, + after_connect_cb, + addr_ptr); +} + // FIXME ref #2064 pub unsafe fn tcp_bind(tcp_server_ptr: *uv_tcp_t, addr_ptr: *sockaddr_in) -> libc::c_int { @@ -968,30 +1113,64 @@ pub unsafe fn tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t, return rust_uv_tcp_getpeername6(tcp_handle_ptr, name); } +#[cfg(stage0)] pub unsafe fn listen(stream: *T, backlog: libc::c_int, cb: *u8) -> libc::c_int { return rust_uv_listen(stream as *libc::c_void, backlog, cb); } +#[cfg(not(stage0))] +pub unsafe fn listen(stream: *T, backlog: libc::c_int, + cb: extern "C" fn(a: *uv_tcp_t, b: i32)) -> libc::c_int { + return rust_uv_listen(stream as *libc::c_void, backlog, cb); +} + pub unsafe fn accept(server: *libc::c_void, client: *libc::c_void) -> libc::c_int { return rust_uv_accept(server as *libc::c_void, client as *libc::c_void); } -pub unsafe fn write(req: *uv_write_t, stream: *T, - buf_in: *~[uv_buf_t], cb: *u8) -> libc::c_int { +#[cfg(stage0)] +pub unsafe fn write(req: *uv_write_t, + stream: *T, + buf_in: *~[uv_buf_t], + cb: *u8) -> libc::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 *libc::c_void, stream as *libc::c_void, buf_ptr, buf_cnt, cb); } +#[cfg(not(stage0))] +pub unsafe fn write(req: *uv_write_t, + stream: *T, + buf_in: *~[uv_buf_t], + cb: extern "C" fn(*uv_write_t, i32)) -> libc::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 *libc::c_void, + stream as *libc::c_void, + buf_ptr, buf_cnt, cb); +} + +#[cfg(stage0)] pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8) -> libc::c_int { return rust_uv_read_start(stream as *libc::c_void, on_alloc, on_read); } +#[cfg(not(stage0))] +pub unsafe fn read_start(stream: *uv_stream_t, + on_alloc: extern "C" fn(a: *c_void, b: u64) + -> uv_buf_t, + on_read: extern "C" fn(a: *uv_stream_t, + b: i64, + c: uv_buf_t)) + -> libc::c_int { + return rust_uv_read_start(stream as *libc::c_void, + on_alloc, on_read); +} pub unsafe fn read_stop(stream: *uv_stream_t) -> libc::c_int { return rust_uv_read_stop(stream as *libc::c_void); @@ -1008,12 +1187,23 @@ pub unsafe fn err_name(err: *uv_err_t) -> *libc::c_char { return rust_uv_err_name(err); } +#[cfg(stage0)] +pub unsafe fn async_init(loop_handle: *libc::c_void, + async_handle: *uv_async_t, + cb: *u8) + -> libc::c_int { + return rust_uv_async_init(loop_handle, + async_handle, + cb); +} +#[cfg(not(stage0))] pub unsafe fn async_init(loop_handle: *libc::c_void, - async_handle: *uv_async_t, - cb: *u8) -> libc::c_int { + async_handle: *uv_async_t, + cb: extern "C" fn(a: *uv_async_t, b: int)) + -> libc::c_int { return rust_uv_async_init(loop_handle, - async_handle, - cb); + async_handle, + cb); } pub unsafe fn async_send(async_handle: *uv_async_t) { @@ -1082,27 +1272,60 @@ pub unsafe fn timer_init(loop_ptr: *libc::c_void, timer_ptr: *uv_timer_t) -> libc::c_int { return rust_uv_timer_init(loop_ptr, timer_ptr); } + +#[cfg(stage0)] pub unsafe fn timer_start(timer_ptr: *uv_timer_t, cb: *u8, timeout: uint, repeat: uint) -> libc::c_int { return rust_uv_timer_start(timer_ptr, cb, timeout as libc::c_uint, repeat as libc::c_uint); } +#[cfg(not(stage0))] +pub unsafe fn timer_start(timer_ptr: *uv_timer_t, + cb: extern "C" fn(a: *uv_timer_t, b: i32), + timeout: uint, + repeat: uint) -> libc::c_int { + return rust_uv_timer_start(timer_ptr, cb, timeout as libc::c_uint, + repeat as libc::c_uint); +} + pub unsafe fn timer_stop(timer_ptr: *uv_timer_t) -> libc::c_int { return rust_uv_timer_stop(timer_ptr); } + +#[cfg(stage0)] +pub unsafe fn getaddrinfo(loop_ptr: *libc::c_void, + handle: *uv_getaddrinfo_t, + cb: *u8, + node_name_ptr: *u8, + service_name_ptr: *u8, + hints: *addrinfo) + -> libc::c_int { + rust_uv_getaddrinfo(loop_ptr, + handle, + cb, + node_name_ptr, + service_name_ptr, + hints) +} + +#[cfg(not(stage0))] pub unsafe fn getaddrinfo(loop_ptr: *libc::c_void, - handle: *uv_getaddrinfo_t, - cb: *u8, - node_name_ptr: *u8, - service_name_ptr: *u8, - hints: *addrinfo) -> libc::c_int { + handle: *uv_getaddrinfo_t, + cb: extern "C" fn(*uv_getaddrinfo_t, + i32, + *addrinfo), + node_name_ptr: *u8, + service_name_ptr: *u8, + hints: *addrinfo) + -> libc::c_int { rust_uv_getaddrinfo(loop_ptr, - handle, - cb, - node_name_ptr, - service_name_ptr, - hints) + handle, + cb, + node_name_ptr, + service_name_ptr, + hints) } + pub unsafe fn freeaddrinfo(res: *addrinfo) { rust_uv_freeaddrinfo(res); }