Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/incoming' into incoming
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Feb 28, 2013
2 parents 3953bdd + b171d0e commit d2c4b64
Show file tree
Hide file tree
Showing 34 changed files with 168 additions and 102 deletions.
2 changes: 1 addition & 1 deletion doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ the following forms:
num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?
| '0' [ [ dec_digit | '_' ] + num_suffix ?
| 'b' [ '1' | '0' | '_' ] + int_suffix ?
| 'x' [ hex_digit | '-' ] + int_suffix ? ] ;
| 'x' [ hex_digit | '_' ] + int_suffix ? ] ;
num_suffix : int_suffix | float_suffix ;
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn debug_mem() -> bool {
#[cfg(notest)]
#[lang="annihilate"]
pub unsafe fn annihilate() {
use rt::rt_free;
use rt::local_free;
use io::WriterUtil;
use io;
use libc;
Expand Down Expand Up @@ -192,7 +192,7 @@ pub unsafe fn annihilate() {
stats.n_bytes_freed +=
(*((*box).header.type_desc)).size
+ sys::size_of::<BoxRepr>();
rt_free(transmute(box));
local_free(transmute(box));
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,10 @@ impl<R:Reader,C> Reader for Wrapper<R, C> {

pub struct FILERes {
f: *libc::FILE,
drop {
}

impl Drop for FILERes {
fn finalize(&self) {
unsafe {
libc::fclose(self.f);
}
Expand Down Expand Up @@ -683,7 +686,10 @@ impl Writer for fd_t {

pub struct FdRes {
fd: fd_t,
drop {
}

impl Drop for FdRes {
fn finalize(&self) {
unsafe {
libc::close(self.fd);
}
Expand Down
5 changes: 4 additions & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,10 @@ fn test_unwrap_str() {
fn test_unwrap_resource() {
struct R {
i: @mut int,
drop { *(self.i) += 1; }
}

impl ::ops::Drop for R {
fn finalize(&self) { *(self.i) += 1; }
}

fn R(i: @mut int) -> R {
Expand Down
5 changes: 4 additions & 1 deletion src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ pub unsafe fn get_buffer<T>(p: *PacketHeader) -> ~Buffer<T> {
struct BufferResource<T> {
buffer: ~Buffer<T>,

drop {
}

impl<T> ::ops::Drop for BufferResource<T> {
fn finalize(&self) {
unsafe {
let b = move_it!(self.buffer);
//let p = ptr::addr_of(*b);
Expand Down
15 changes: 12 additions & 3 deletions src/libcore/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ struct ArcData<T> {

struct ArcDestruct<T> {
mut data: *libc::c_void,
drop {
}

impl<T> Drop for ArcDestruct<T>{
fn finalize(&self) {
unsafe {
if self.data.is_null() {
return; // Happens when destructing an unwrapper's handle.
Expand Down Expand Up @@ -178,7 +181,10 @@ pub unsafe fn unwrap_shared_mutable_state<T:Owned>(rc: SharedMutableState<T>)
struct DeathThroes<T> {
mut ptr: Option<~ArcData<T>>,
mut response: Option<comm::ChanOne<bool>>,
drop {
}

impl<T> Drop for DeathThroes<T>{
fn finalize(&self) {
unsafe {
let response = option::swap_unwrap(&mut self.response);
// In case we get killed early, we need to tell the person who
Expand Down Expand Up @@ -311,7 +317,10 @@ type rust_little_lock = *libc::c_void;

struct LittleLock {
l: rust_little_lock,
drop {
}

impl Drop for LittleLock {
fn finalize(&self) {
unsafe {
rustrt::rust_destroy_little_lock(self.l);
}
Expand Down
5 changes: 4 additions & 1 deletion src/libcore/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ impl Rng {

struct RandRes {
rng: *rust_rng,
drop {
}

impl Drop for RandRes {
fn finalize(&self) {
unsafe {
rustrt::rand_free(self.rng);
}
Expand Down
28 changes: 11 additions & 17 deletions src/libcore/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,54 @@ pub extern mod rustrt {
unsafe fn rust_upcall_free(ptr: *c_char);
}

#[rt(fail_)]
#[lang="fail_"]
pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
sys::begin_unwind_(expr, file, line);
}

#[rt(fail_bounds_check)]
#[lang="fail_bounds_check"]
pub unsafe fn rt_fail_bounds_check(file: *c_char, line: size_t,
index: size_t, len: size_t) {
pub unsafe fn 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);
fail_(p as *c_char, file, line);
}
}

pub unsafe fn rt_fail_borrowed() {
pub unsafe fn fail_borrowed() {
let msg = "borrowed";
do str::as_buf(msg) |msg_p, _| {
do str::as_buf("???") |file_p, _| {
rt_fail_(msg_p as *c_char, file_p as *c_char, 0);
fail_(msg_p as *c_char, file_p as *c_char, 0);
}
}
}

// FIXME #4942: Make these signatures agree with exchange_alloc's signatures
#[rt(exchange_malloc)]
#[lang="exchange_malloc"]
pub unsafe fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
transmute(exchange_alloc::malloc(transmute(td), transmute(size)))
}

// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
// inside a landing pad may corrupt the state of the exception handler. If a
// problem occurs, call exit instead.
#[rt(exchange_free)]
#[lang="exchange_free"]
pub unsafe fn rt_exchange_free(ptr: *c_char) {
pub unsafe fn exchange_free(ptr: *c_char) {
exchange_alloc::free(transmute(ptr))
}

#[rt(malloc)]
#[lang="malloc"]
pub unsafe fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
return rustrt::rust_upcall_malloc(td, size);
}

// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
// inside a landing pad may corrupt the state of the exception handler. If a
// problem occurs, call exit instead.
#[rt(free)]
#[lang="free"]
pub unsafe fn rt_free(ptr: *c_char) {
pub unsafe fn local_free(ptr: *c_char) {
rustrt::rust_upcall_free(ptr);
}

Expand All @@ -112,7 +106,7 @@ pub unsafe fn return_to_mut(a: *u8) {
pub unsafe fn check_not_borrowed(a: *u8) {
let a: *mut BoxRepr = transmute(a);
if ((*a).header.ref_count & FROZEN_BIT) != 0 {
rt_fail_borrowed();
fail_borrowed();
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/libcore/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
}
struct ProgRes {
r: ProgRepr,
drop {
}

impl Drop for ProgRes {
fn finalize(&self) {
unsafe {
// FIXME #4943: This is bad.
destroy_repr(cast::transmute(&self.r));
Expand Down
10 changes: 8 additions & 2 deletions src/libcore/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ struct TCB {
mut ancestors: AncestorList,
is_main: bool,
notifier: Option<AutoNotify>,
}

impl Drop for TCB {
// Runs on task exit.
drop {
fn finalize(&self) {
unsafe {
// If we are failing, the whole taskgroup needs to die.
if rt::rust_task_is_unwinding(self.me) {
Expand Down Expand Up @@ -353,7 +356,10 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
struct AutoNotify {
notify_chan: Chan<TaskResult>,
mut failed: bool,
drop {
}

impl Drop for AutoNotify {
fn finalize(&self) {
let result = if self.failed { Failure } else { Success };
self.notify_chan.send(result);
}
Expand Down
26 changes: 5 additions & 21 deletions src/libcore/to_str.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -137,15 +137,6 @@ impl<A:ToStr> ToStr for @[A] {
}
}
impl<A:ToStr> ToStr for @A {
#[inline(always)]
pure fn to_str(&self) -> ~str { ~"@" + (**self).to_str() }
}
impl<A:ToStr> ToStr for ~A {
#[inline(always)]
pure fn to_str(&self) -> ~str { ~"~" + (**self).to_str() }
}

#[cfg(test)]
#[allow(non_implicitly_copyable_typarams)]
mod tests {
Expand All @@ -170,19 +161,12 @@ mod tests {
}

#[test]
#[ignore]
fn test_vectors() {
let x: ~[int] = ~[];
assert x.to_str() == ~"~[]";
assert (~[1]).to_str() == ~"~[1]";
assert (~[1, 2, 3]).to_str() == ~"~[1, 2, 3]";
assert x.to_str() == ~"[]";
assert (~[1]).to_str() == ~"[1]";
assert (~[1, 2, 3]).to_str() == ~"[1, 2, 3]";
assert (~[~[], ~[1], ~[1, 1]]).to_str() ==
~"~[~[], ~[1], ~[1, 1]]";
}

#[test]
fn test_pointer_types() {
assert (@1).to_str() == ~"@1";
assert (~(true, false)).to_str() == ~"~(true, false)";
~"[[], [1], [1, 1]]";
}
}
5 changes: 4 additions & 1 deletion src/libcore/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ pub fn replace<T>(dest: &mut T, src: T) -> T {
/// A non-copyable dummy type.
pub struct NonCopyable {
i: (),
drop { }
}

impl Drop for NonCopyable {
fn finalize(&self) { }
}

pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } }
Expand Down
20 changes: 16 additions & 4 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,10 @@ pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] {

pub struct target_data_res {
TD: TargetDataRef,
drop {
}

impl Drop for target_data_res {
fn finalize(&self) {
unsafe {
llvm::LLVMDisposeTargetData(self.TD);
}
Expand Down Expand Up @@ -1492,7 +1495,10 @@ pub fn mk_target_data(string_rep: ~str) -> TargetData {

pub struct pass_manager_res {
PM: PassManagerRef,
drop {
}

impl Drop for pass_manager_res {
fn finalize(&self) {
unsafe {
llvm::LLVMDisposePassManager(self.PM);
}
Expand Down Expand Up @@ -1525,7 +1531,10 @@ pub fn mk_pass_manager() -> PassManager {

pub struct object_file_res {
ObjectFile: ObjectFileRef,
drop {
}

impl Drop for object_file_res {
fn finalize(&self) {
unsafe {
llvm::LLVMDisposeObjectFile(self.ObjectFile);
}
Expand Down Expand Up @@ -1559,7 +1568,10 @@ pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {

pub struct section_iter_res {
SI: SectionIteratorRef,
drop {
}

impl Drop for section_iter_res {
fn finalize(&self) {
unsafe {
llvm::LLVMDisposeSectionIterator(self.SI);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ pub fn compare_values(cx: block,
let scratch_rhs = alloca(cx, val_ty(rhs));
Store(cx, rhs, scratch_rhs);
let did = cx.tcx().lang_items.uniq_str_eq_fn();
let bcx = callee::trans_rtcall_or_lang_call(cx, did,
let bcx = callee::trans_lang_call(cx, did,
~[scratch_lhs,
scratch_rhs],
expr::SaveIn(
Expand All @@ -1069,7 +1069,7 @@ pub fn compare_values(cx: block,
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
false);
let did = cx.tcx().lang_items.str_eq_fn();
let bcx = callee::trans_rtcall_or_lang_call(cx, did,
let bcx = callee::trans_lang_call(cx, did,
~[lhs, rhs],
expr::SaveIn(
scratch_result.val));
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ use syntax::{ast, ast_util, codemap, ast_map};

pub struct icx_popper {
ccx: @CrateContext,
drop {
}

impl Drop for icx_popper {
fn finalize(&self) {
if self.ccx.sess.count_llvm_insns() {
self.ccx.stats.llvm_insn_ctxt.pop();
}
Expand Down Expand Up @@ -304,7 +307,7 @@ pub fn malloc_raw_dyn(bcx: block,
// Allocate space:
let tydesc = PointerCast(bcx, static_ti.tydesc, T_ptr(T_i8()));
let rval = alloca(bcx, T_ptr(T_i8()));
let bcx = callee::trans_rtcall_or_lang_call(
let bcx = callee::trans_lang_call(
bcx,
langcall,
~[tydesc, size],
Expand Down
Loading

7 comments on commit d2c4b64

@bors
Copy link
Contributor

@bors bors commented on d2c4b64 Feb 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at erickt@d2c4b64

@bors
Copy link
Contributor

@bors bors commented on d2c4b64 Feb 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/incoming = d2c4b64 into auto

@bors
Copy link
Contributor

@bors bors commented on d2c4b64 Feb 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/incoming = d2c4b64 merged ok, testing candidate = f58e9d54

@bors
Copy link
Contributor

@bors bors commented on d2c4b64 Feb 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on d2c4b64 Mar 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at erickt@d2c4b64

@bors
Copy link
Contributor

@bors bors commented on d2c4b64 Mar 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/incoming = d2c4b64 into auto

@bors
Copy link
Contributor

@bors bors commented on d2c4b64 Mar 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/incoming = d2c4b64 into auto failed

Please sign in to comment.