From 1c76d189c02ddc6cb6fcf15ae94f3a3ae4de5fa7 Mon Sep 17 00:00:00 2001 From: Gareth Daniel Smith Date: Sat, 29 Sep 2012 12:34:11 +0100 Subject: When a vec/str bounds check fails, include the bad index and the length of the str/vec in the fail message. --- src/libcore/rt.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/libcore/rt.rs') diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs index 644edb69d56..da598fc3e7f 100644 --- a/src/libcore/rt.rs +++ b/src/libcore/rt.rs @@ -40,6 +40,16 @@ fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) { rustrt::rust_upcall_fail(expr, file, line); } +#[rt(fail_bounds_check)] +fn rt_fail_bounds_check(file: *c_char, line: size_t, + index: size_t, len: size_t) { + let msg = fmt!("index out of bounds: the len is %d but the index is %d", + len as int, index as int); + do str::as_buf(msg) |p, _len| { + rt_fail_(p as *c_char, file, line); + } +} + #[rt(exchange_malloc)] fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { return rustrt::rust_upcall_exchange_malloc(td, size); -- cgit 1.4.1-3-g733a5 From c31a88c7f4fddb217c022ac214c0a49501d9ded3 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 2 Oct 2012 16:31:52 -0700 Subject: De-export the submodules of task. Part of #3583. --- src/libcore/core.rc | 12 ++------ src/libcore/rt.rs | 15 +++++----- src/libcore/task/local_data_priv.rs | 24 ++++++++-------- src/libcore/task/rt.rs | 8 +++--- src/libcore/task/spawn.rs | 55 +++++++++++++++++++------------------ src/test/run-pass/issue-783.rs | 2 +- 6 files changed, 55 insertions(+), 61 deletions(-) (limited to 'src/libcore/rt.rs') diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 6cada58fa02..818e1e890ec 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -216,17 +216,11 @@ mod send_map; // Concurrency mod comm; -#[legacy_exports] mod task { - #[legacy_exports]; - #[legacy_exports] - mod local_data; - #[legacy_exports] + pub mod local_data; mod local_data_priv; - #[legacy_exports] - mod spawn; - #[legacy_exports] - mod rt; + pub mod spawn; + pub mod rt; } mod future; mod pipes; diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs index da598fc3e7f..9bc83a5f904 100644 --- a/src/libcore/rt.rs +++ b/src/libcore/rt.rs @@ -11,10 +11,9 @@ use libc::uintptr_t; use gc::{cleanup_stack_for_failure, gc, Word}; #[allow(non_camel_case_types)] -type rust_task = c_void; +pub type rust_task = c_void; extern mod rustrt { - #[legacy_exports]; #[rust_stack] fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t); @@ -35,13 +34,13 @@ extern mod rustrt { // 'rt_', otherwise the compiler won't find it. To fix this, see // gather_rust_rtcalls. #[rt(fail_)] -fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) { +pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) { cleanup_stack_for_failure(); rustrt::rust_upcall_fail(expr, file, line); } #[rt(fail_bounds_check)] -fn rt_fail_bounds_check(file: *c_char, line: size_t, +pub fn rt_fail_bounds_check(file: *c_char, line: size_t, index: size_t, len: size_t) { let msg = fmt!("index out of bounds: the len is %d but the index is %d", len as int, index as int); @@ -51,7 +50,7 @@ fn rt_fail_bounds_check(file: *c_char, line: size_t, } #[rt(exchange_malloc)] -fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { +pub fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { return rustrt::rust_upcall_exchange_malloc(td, size); } @@ -59,12 +58,12 @@ fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { // inside a landing pad may corrupt the state of the exception handler. If a // problem occurs, call exit instead. #[rt(exchange_free)] -fn rt_exchange_free(ptr: *c_char) { +pub fn rt_exchange_free(ptr: *c_char) { rustrt::rust_upcall_exchange_free(ptr); } #[rt(malloc)] -fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char { +pub fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char { return rustrt::rust_upcall_malloc(td, size); } @@ -72,7 +71,7 @@ fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char { // inside a landing pad may corrupt the state of the exception handler. If a // problem occurs, call exit instead. #[rt(free)] -fn rt_free(ptr: *c_char) { +pub fn rt_free(ptr: *c_char) { rustrt::rust_upcall_free(ptr); } diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index 499dd073060..9849ce7b68c 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -3,7 +3,7 @@ use local_data::LocalDataKey; use rt::rust_task; -trait LocalData { } +pub trait LocalData { } impl @T: LocalData { } impl LocalData: Eq { @@ -17,11 +17,11 @@ impl LocalData: Eq { // We use dvec because it's the best data structure in core. If TLS is used // heavily in future, this could be made more efficient with a proper map. -type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); +pub type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); // Has to be a pointer at outermost layer; the foreign call returns void *. -type TaskLocalMap = @dvec::DVec>; +pub type TaskLocalMap = @dvec::DVec>; -extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { +pub extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { assert !map_ptr.is_null(); // Get and keep the single reference that was created at the beginning. let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr); @@ -29,7 +29,7 @@ extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { } // Gets the map from the runtime. Lazily initialises if not done so already. -unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { +pub unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { // Relies on the runtime initialising the pointer to null. // NOTE: The map's box lives in TLS invisibly referenced once. Each time @@ -52,7 +52,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { } } -unsafe fn key_to_key_value( +pub unsafe fn key_to_key_value( key: LocalDataKey) -> *libc::c_void { // Keys are closures, which are (fnptr,envptr) pairs. Use fnptr. @@ -62,7 +62,7 @@ unsafe fn key_to_key_value( } // If returning Some(..), returns with @T with the map's reference. Careful! -unsafe fn local_data_lookup( +pub unsafe fn local_data_lookup( map: TaskLocalMap, key: LocalDataKey) -> Option<(uint, *libc::c_void)> { @@ -80,7 +80,7 @@ unsafe fn local_data_lookup( } } -unsafe fn local_get_helper( +pub unsafe fn local_get_helper( task: *rust_task, key: LocalDataKey, do_pop: bool) -> Option<@T> { @@ -102,21 +102,21 @@ unsafe fn local_get_helper( } -unsafe fn local_pop( +pub unsafe fn local_pop( task: *rust_task, key: LocalDataKey) -> Option<@T> { local_get_helper(task, key, true) } -unsafe fn local_get( +pub unsafe fn local_get( task: *rust_task, key: LocalDataKey) -> Option<@T> { local_get_helper(task, key, false) } -unsafe fn local_set( +pub unsafe fn local_set( task: *rust_task, key: LocalDataKey, data: @T) { let map = get_task_local_map(task); @@ -148,7 +148,7 @@ unsafe fn local_set( } } -unsafe fn local_modify( +pub unsafe fn local_modify( task: *rust_task, key: LocalDataKey, modify_fn: fn(Option<@T>) -> Option<@T>) { diff --git a/src/libcore/task/rt.rs b/src/libcore/task/rt.rs index b1f7b99bd07..db3d1ec9f70 100644 --- a/src/libcore/task/rt.rs +++ b/src/libcore/task/rt.rs @@ -7,16 +7,16 @@ The task interface to the runtime #[doc(hidden)]; // FIXME #3538 #[allow(non_camel_case_types)] // runtime type -type sched_id = int; +pub type sched_id = int; #[allow(non_camel_case_types)] // runtime type -type task_id = int; +pub type task_id = int; // These are both opaque runtime/compiler types that we don't know the // structure of and should only deal with via unsafe pointer #[allow(non_camel_case_types)] // runtime type -type rust_task = libc::c_void; +pub type rust_task = libc::c_void; #[allow(non_camel_case_types)] // runtime type -type rust_closure = libc::c_void; +pub type rust_closure = libc::c_void; extern { #[rust_stack] diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 786255fe7fa..0e1284da3bc 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -69,25 +69,25 @@ macro_rules! move_it ( { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); move y } } ) -type TaskSet = send_map::linear::LinearMap<*rust_task,()>; +pub type TaskSet = send_map::linear::LinearMap<*rust_task,()>; -fn new_taskset() -> TaskSet { +pub fn new_taskset() -> TaskSet { send_map::linear::LinearMap() } -fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { +pub fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { let didnt_overwrite = tasks.insert(task, ()); assert didnt_overwrite; } -fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { +pub fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { let was_present = tasks.remove(&task); assert was_present; } -fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { +pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { tasks.each_key(|k| blk(*k)) } // One of these per group of linked-failure tasks. -type TaskGroupData = { +pub type TaskGroupData = { // All tasks which might kill this group. When this is empty, the group // can be "GC"ed (i.e., its link in the ancestor list can be removed). mut members: TaskSet, @@ -95,12 +95,12 @@ type TaskGroupData = { // tasks in this group. mut descendants: TaskSet, }; -type TaskGroupArc = private::Exclusive>; +pub type TaskGroupArc = private::Exclusive>; -type TaskGroupInner = &mut Option; +pub type TaskGroupInner = &mut Option; // A taskgroup is 'dead' when nothing can cause it to fail; only members can. -pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { +pub pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { (&tg.members).is_empty() } @@ -111,7 +111,7 @@ pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { // taskgroup which was spawned-unlinked. Tasks from intermediate generations // have references to the middle of the list; when intermediate generations // die, their node in the list will be collected at a descendant's spawn-time. -type AncestorNode = { +pub type AncestorNode = { // Since the ancestor list is recursive, we end up with references to // exclusives within other exclusives. This is dangerous business (if // circular references arise, deadlock and memory leaks are imminent). @@ -124,16 +124,16 @@ type AncestorNode = { // Recursive rest of the list. mut ancestors: AncestorList, }; -enum AncestorList = Option>; +pub enum AncestorList = Option>; // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. #[inline(always)] -fn access_group(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U { +pub fn access_group(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U { unsafe { x.with(blk) } } #[inline(always)] -fn access_ancestors(x: &private::Exclusive, +pub fn access_ancestors(x: &private::Exclusive, blk: fn(x: &mut AncestorNode) -> U) -> U { unsafe { x.with(blk) } } @@ -146,9 +146,9 @@ fn access_ancestors(x: &private::Exclusive, // (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list. // FIXME(#2190): Change Option to Option, to save on // allocations. Once that bug is fixed, changing the sigil should suffice. -fn each_ancestor(list: &mut AncestorList, - bail_opt: Option, - forward_blk: fn(TaskGroupInner) -> bool) +pub fn each_ancestor(list: &mut AncestorList, + bail_opt: Option, + forward_blk: fn(TaskGroupInner) -> bool) -> bool { // "Kickoff" call - there was no last generation. return !coalesce(list, bail_opt, forward_blk, uint::max_value); @@ -271,7 +271,7 @@ fn each_ancestor(list: &mut AncestorList, } // One of these per task. -struct TCB { +pub struct TCB { me: *rust_task, // List of tasks with whose fates this one's is intertwined. tasks: TaskGroupArc, // 'none' means the group has failed. @@ -303,7 +303,7 @@ struct TCB { } } -fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, +pub fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, is_main: bool, notifier: Option) -> TCB { let notifier = move notifier; @@ -318,7 +318,7 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, } } -struct AutoNotify { +pub struct AutoNotify { notify_chan: Chan, mut failed: bool, drop { @@ -327,15 +327,15 @@ struct AutoNotify { } } -fn AutoNotify(chan: Chan) -> AutoNotify { +pub fn AutoNotify(chan: Chan) -> AutoNotify { AutoNotify { notify_chan: chan, failed: true // Un-set above when taskgroup successfully made. } } -fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, - is_member: bool) -> bool { +pub fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, + is_member: bool) -> bool { let newstate = util::replace(state, None); // If 'None', the group was failing. Can't enlist. if newstate.is_some() { @@ -350,7 +350,8 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, } // NB: Runs in destructor/post-exit context. Can't 'fail'. -fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) { +pub fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, + is_member: bool) { let newstate = util::replace(state, None); // If 'None', already failing and we've already gotten a kill signal. if newstate.is_some() { @@ -362,7 +363,7 @@ fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) { } // NB: Runs in destructor/post-exit context. Can't 'fail'. -fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { +pub fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { // NB: We could do the killing iteration outside of the group arc, by // having "let mut newstate" here, swapping inside, and iterating after. // But that would let other exiting tasks fall-through and exit while we @@ -404,8 +405,8 @@ macro_rules! taskgroup_key ( () => (cast::transmute((-2 as uint, 0u))) ) -fn gen_child_taskgroup(linked: bool, supervised: bool) - -> (TaskGroupArc, AncestorList, bool) { +pub fn gen_child_taskgroup(linked: bool, supervised: bool) + -> (TaskGroupArc, AncestorList, bool) { let spawner = rt::rust_get_task(); /*######################################################################* * Step 1. Get spawner's taskgroup info. @@ -486,7 +487,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) } } -fn spawn_raw(opts: TaskOpts, +f: fn~()) { +pub fn spawn_raw(opts: TaskOpts, +f: fn~()) { let (child_tg, ancestors, is_main) = gen_child_taskgroup(opts.linked, opts.supervised); diff --git a/src/test/run-pass/issue-783.rs b/src/test/run-pass/issue-783.rs index 752101e651b..a9c6fed8eca 100644 --- a/src/test/run-pass/issue-783.rs +++ b/src/test/run-pass/issue-783.rs @@ -1,6 +1,6 @@ extern mod std; use comm::*; -use task::*; +use task::spawn; fn a() { fn doit() { -- cgit 1.4.1-3-g733a5