Skip to content

Commit 7bf7c0c

Browse files
committed
---
yaml --- r: 140239 b: refs/heads/try2 c: 6210de9 h: refs/heads/master i: 140237: f207feb 140235: 7139566 140231: a51b9ad 140223: ce352c7 v: v3
1 parent 6bddd77 commit 7bf7c0c

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: d231c427e655b7164571a1a712563ba5fd2e4a3c
8+
refs/heads/try2: 6210de9529f37bb4ff51050bca19dfd6f28026c9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/unstable/lang.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use sys;
1919
use unstable::exchange_alloc;
2020
use cast::transmute;
2121
use task::rt::rust_get_task;
22+
use option::{Some, None};
2223

2324
#[allow(non_camel_case_types)]
2425
pub type rust_task = c_void;
@@ -71,6 +72,7 @@ pub fn fail_bounds_check(file: *c_char, line: size_t,
7172
}
7273
}
7374

75+
#[deriving(Eq)]
7476
struct BorrowRecord {
7577
box: *mut BoxRepr,
7678
file: *c_char,
@@ -108,7 +110,7 @@ pub fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
108110
str::raw::from_c_str(entry.file)
109111
};
110112
str::push_str(&mut msg, filename);
111-
str::push_str(&mut msg, fmt!(":%u", line as uint));
113+
str::push_str(&mut msg, fmt!(":%u", entry.line as uint));
112114
sep = " and at ";
113115
}
114116
}
@@ -208,15 +210,36 @@ fn add_borrow_to_task_list(a: *mut BoxRepr, file: *c_char, line: size_t) {
208210
}
209211
}
210212

213+
fn remove_borrow_from_task_list(a: *mut BoxRepr, file: *c_char, line: size_t) {
214+
do swap_task_borrow_list |borrow_list| {
215+
let mut borrow_list = borrow_list;
216+
let br = BorrowRecord {box: a, file: file, line: line};
217+
match borrow_list.rposition_elem(&br) {
218+
Some(idx) => {
219+
borrow_list.remove(idx);
220+
borrow_list
221+
}
222+
None => {
223+
let err = fmt!("no borrow found, br=%?, borrow_list=%?",
224+
br, borrow_list);
225+
do str::as_buf(err) |msg_p, _| {
226+
fail_(msg_p as *c_char, file, line)
227+
}
228+
}
229+
}
230+
}
231+
}
232+
211233
#[cfg(not(stage0))]
212234
#[lang="borrow_as_imm"]
213235
#[inline(always)]
214236
pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint {
215237
let a: *mut BoxRepr = transmute(a);
216238
let ref_count = (*a).header.ref_count;
217239

218-
debug_ptr("borrow_as_imm (ptr): ", a);
219-
debug_ptr("borrow_as_imm (ref): ", ref_count as *());
240+
debug_ptr("borrow_as_imm (ptr) :", a);
241+
debug_ptr(" (ref) :", ref_count as *());
242+
debug_ptr(" (line): ", line as *());
220243

221244
if (ref_count & MUT_BIT) != 0 {
222245
fail_borrowed(a, file, line);
@@ -236,7 +259,7 @@ pub unsafe fn borrow_as_mut(a: *u8, file: *c_char, line: size_t) -> uint {
236259
let a: *mut BoxRepr = transmute(a);
237260

238261
debug_ptr("borrow_as_mut (ptr): ", a);
239-
debug_ptr("borrow_as_mut (line): ", line as *());
262+
debug_ptr(" (line): ", line as *());
240263

241264
let ref_count = (*a).header.ref_count;
242265
if (ref_count & (MUT_BIT|FROZEN_BIT)) != 0 {
@@ -265,18 +288,25 @@ pub unsafe fn return_to_mut(a: *u8) {
265288
#[cfg(not(stage0))]
266289
#[lang="return_to_mut"]
267290
#[inline(always)]
268-
pub unsafe fn return_to_mut(a: *u8, old_ref_count: uint) {
291+
pub unsafe fn return_to_mut(a: *u8, old_ref_count: uint,
292+
file: *c_char, line: size_t) {
269293
// Sometimes the box is null, if it is conditionally frozen.
270294
// See e.g. #4904.
271295
if !a.is_null() {
272296
let a: *mut BoxRepr = transmute(a);
297+
let ref_count = (*a).header.ref_count;
298+
let combined = (ref_count & !ALL_BITS) | (old_ref_count & ALL_BITS);
299+
(*a).header.ref_count = combined;
273300

274-
debug_ptr("return_to_mut (ptr): ", a);
275-
debug_ptr("return_to_mut (ref): ", old_ref_count as *());
301+
debug_ptr("return_to_mut (ptr) : ", a);
302+
debug_ptr(" (line): ", line as *());
303+
debug_ptr(" (old) : ", old_ref_count as *());
304+
debug_ptr(" (new) : ", ref_count as *());
305+
debug_ptr(" (comb): ", combined as *());
276306

277-
let ref_count = (*a).header.ref_count & !ALL_BITS;
278-
let old_bits = old_ref_count & ALL_BITS;
279-
(*a).header.ref_count = ref_count | old_bits;
307+
if ::rt::env::get().debug_borrows {
308+
remove_borrow_from_task_list(a, file, line);
309+
}
280310
}
281311
}
282312

branches/try2/src/librustc/middle/trans/common.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ pub fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) {
469469
}
470470
pub fn add_clean_return_to_mut(bcx: block,
471471
frozen_val_ref: ValueRef,
472-
bits_val_ref: ValueRef) {
472+
bits_val_ref: ValueRef,
473+
filename_val: ValueRef,
474+
line_val: ValueRef) {
473475
//! When an `@mut` has been frozen, we have to
474476
//! call the lang-item `return_to_mut` when the
475477
//! freeze goes out of scope. We need to pass
@@ -495,7 +497,9 @@ pub fn add_clean_return_to_mut(bcx: block,
495497
build::PointerCast(bcx,
496498
frozen_val_ref,
497499
T_ptr(T_ptr(T_i8())))),
498-
build::Load(bcx, bits_val_ref)
500+
build::Load(bcx, bits_val_ref),
501+
filename_val,
502+
line_val
499503
],
500504
expr::Ignore
501505
)

branches/try2/src/librustc/middle/trans/datum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ pub impl Datum {
578578
expr::SaveIn(scratch_bits.val));
579579

580580
add_clean_return_to_mut(
581-
cleanup_bcx, scratch.val, scratch_bits.val);
581+
cleanup_bcx, scratch.val, scratch_bits.val,
582+
filename, line);
582583
}
583584
}
584585

0 commit comments

Comments
 (0)