Skip to content

Commit b663e23

Browse files
committed
---
yaml --- r: 140477 b: refs/heads/try2 c: c50a9d5 h: refs/heads/master i: 140475: d0e75f3 v: v3
1 parent 01a8cf3 commit b663e23

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
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: 84f7ecce5c8b727309d0d48e84a965a5a3437fd1
8+
refs/heads/try2: c50a9d5b664478e533ba1d1d353213d70c8ad589
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: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rt::{context, OldTaskContext};
2222
use rt::local_services::borrow_local_services;
2323
use option::{Option, Some, None};
2424
use io;
25-
use task::rt::rust_get_task;
2625

2726
#[allow(non_camel_case_types)]
2827
pub type rust_task = c_void;
@@ -56,6 +55,9 @@ pub mod rustrt {
5655
#[rust_stack]
5756
fn rust_set_task_borrow_list(task: *rust_task, map: *c_void);
5857

58+
#[rust_stack]
59+
fn rust_try_get_task() -> *rust_task;
60+
5961
fn rust_dbg_breakpoint();
6062
}
6163
}
@@ -84,26 +86,32 @@ struct BorrowRecord {
8486

8587
fn try_take_task_borrow_list() -> Option<~[BorrowRecord]> {
8688
unsafe {
87-
let cur_task = rust_get_task();
88-
let ptr = rustrt::rust_take_task_borrow_list(cur_task);
89-
if ptr.is_null() {
90-
None
89+
let cur_task: *rust_task = rustrt::rust_try_get_task();
90+
if cur_task.is_not_null() {
91+
let ptr = rustrt::rust_take_task_borrow_list(cur_task);
92+
if ptr.is_null() {
93+
None
94+
} else {
95+
let v: ~[BorrowRecord] = transmute(ptr);
96+
Some(v)
97+
}
9198
} else {
92-
let v: ~[BorrowRecord] = transmute(ptr);
93-
Some(v)
99+
None
94100
}
95101
}
96102
}
97103

98104
fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) {
99105
unsafe {
100-
let cur_task = rust_get_task();
101-
let mut borrow_list: ~[BorrowRecord] = {
102-
let ptr = rustrt::rust_take_task_borrow_list(cur_task);
103-
if ptr.is_null() { ~[] } else { transmute(ptr) }
104-
};
105-
borrow_list = f(borrow_list);
106-
rustrt::rust_set_task_borrow_list(cur_task, transmute(borrow_list));
106+
let cur_task: *rust_task = rustrt::rust_try_get_task();
107+
if cur_task.is_not_null() {
108+
let mut borrow_list: ~[BorrowRecord] = {
109+
let ptr = rustrt::rust_take_task_borrow_list(cur_task);
110+
if ptr.is_null() { ~[] } else { transmute(ptr) }
111+
};
112+
borrow_list = f(borrow_list);
113+
rustrt::rust_set_task_borrow_list(cur_task, transmute(borrow_list));
114+
}
107115
}
108116
}
109117

@@ -128,9 +136,7 @@ unsafe fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
128136
for borrow_list.each_reverse |entry| {
129137
if entry.box == box {
130138
str::push_str(&mut msg, sep);
131-
let filename = unsafe {
132-
str::raw::from_c_str(entry.file)
133-
};
139+
let filename = str::raw::from_c_str(entry.file);
134140
str::push_str(&mut msg, filename);
135141
str::push_str(&mut msg, fmt!(":%u", entry.line as uint));
136142
sep = " and at ";
@@ -351,25 +357,21 @@ pub unsafe fn record_borrow(a: *u8, old_ref_count: uint,
351357
pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint,
352358
file: *c_char, line: size_t) {
353359
if (old_ref_count & ALL_BITS) == 0 {
354-
// was not borrowed before
360+
// was not borrowed before, so we should find the record at
361+
// the end of the list
355362
let a: *mut BoxRepr = transmute(a);
356363
debug_borrow("unrecord_borrow:", a, old_ref_count, 0, file, line);
357364
do swap_task_borrow_list |borrow_list| {
358365
let mut borrow_list = borrow_list;
359-
let br = BorrowRecord {box: a, file: file, line: line};
360-
match borrow_list.rposition_elem(&br) {
361-
Some(idx) => {
362-
borrow_list.remove(idx);
363-
borrow_list
364-
}
365-
None => {
366-
let err = fmt!("no borrow found, br=%?, borrow_list=%?",
367-
br, borrow_list);
368-
do str::as_buf(err) |msg_p, _| {
369-
fail_(msg_p as *c_char, file, line)
370-
}
366+
assert!(!borrow_list.is_empty());
367+
let br = borrow_list.pop();
368+
if br.box != a || br.file != file || br.line != line {
369+
let err = fmt!("wrong borrow found, br=%?", br);
370+
do str::as_buf(err) |msg_p, _| {
371+
fail_(msg_p as *c_char, file, line)
371372
}
372373
}
374+
borrow_list
373375
}
374376
}
375377
}

0 commit comments

Comments
 (0)