@@ -51,6 +51,8 @@ pub mod rustrt {
51
51
52
52
#[ rust_stack]
53
53
fn rust_set_task_borrow_list ( task : * rust_task , map : * c_void ) ;
54
+
55
+ fn rust_dbg_breakpoint ( ) ;
54
56
}
55
57
}
56
58
@@ -88,6 +90,8 @@ fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) {
88
90
}
89
91
90
92
pub fn fail_borrowed ( box : * mut BoxRepr , file : * c_char , line : size_t ) {
93
+ debug_ptr ( "fail_borrowed: " , box) ;
94
+
91
95
if !:: rt:: env:: get ( ) . debug_borrows {
92
96
let msg = "borrowed" ;
93
97
do str:: as_buf ( msg) |msg_p, _| {
@@ -130,15 +134,15 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
130
134
static ENABLE_DEBUG_PTR : bool = false ;
131
135
132
136
#[ inline]
133
- pub fn debug_ptr < T > ( tag : & ' static str , p : * T ) {
137
+ pub fn debug_ptr < T > ( tag : & ' static str , p : * const T ) {
134
138
//! A useful debugging function that prints a pointer + tag + newline
135
139
//! without allocating memory.
136
140
137
141
if ENABLE_DEBUG_PTR && :: rt:: env:: get ( ) . debug_mem {
138
142
debug_ptr_slow ( tag, p) ;
139
143
}
140
144
141
- fn debug_ptr_slow < T > ( tag : & ' static str , p : * T ) {
145
+ fn debug_ptr_slow < T > ( tag : & ' static str , p : * const T ) {
142
146
use io;
143
147
let dbg = STDERR_FILENO as io:: fd_t ;
144
148
let letters = [ '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' ,
@@ -209,14 +213,17 @@ fn add_borrow_to_task_list(a: *mut BoxRepr, file: *c_char, line: size_t) {
209
213
#[ inline( always) ]
210
214
pub unsafe fn borrow_as_imm ( a : * u8 , file : * c_char , line : size_t ) -> uint {
211
215
let a: * mut BoxRepr = transmute ( a) ;
212
-
213
216
let ref_count = ( * a) . header . ref_count ;
217
+
218
+ debug_ptr ( "borrow_as_imm (ptr): " , a) ;
219
+ debug_ptr ( "borrow_as_imm (ref): " , ref_count as * ( ) ) ;
220
+
214
221
if ( ref_count & MUT_BIT ) != 0 {
215
222
fail_borrowed ( a, file, line) ;
216
223
} else {
217
224
( * a) . header . ref_count |= FROZEN_BIT ;
218
225
if :: rt:: env:: get ( ) . debug_borrows {
219
- add_borrow_to_list ( a, file, line) ;
226
+ add_borrow_to_task_list ( a, file, line) ;
220
227
}
221
228
}
222
229
ref_count
@@ -228,13 +235,16 @@ pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint {
228
235
pub unsafe fn borrow_as_mut ( a : * u8 , file : * c_char , line : size_t ) -> uint {
229
236
let a: * mut BoxRepr = transmute ( a) ;
230
237
238
+ debug_ptr ( "borrow_as_mut (ptr): " , a) ;
239
+ debug_ptr ( "borrow_as_mut (line): " , line as * ( ) ) ;
240
+
231
241
let ref_count = ( * a) . header . ref_count ;
232
242
if ( ref_count & ( MUT_BIT |FROZEN_BIT ) ) != 0 {
233
243
fail_borrowed ( a, file, line) ;
234
244
} else {
235
245
( * a) . header . ref_count |= ( MUT_BIT |FROZEN_BIT ) ;
236
246
if :: rt:: env:: get ( ) . debug_borrows {
237
- add_borrow_to_list ( a, file, line) ;
247
+ add_borrow_to_task_list ( a, file, line) ;
238
248
}
239
249
}
240
250
ref_count
@@ -261,6 +271,9 @@ pub unsafe fn return_to_mut(a: *u8, old_ref_count: uint) {
261
271
if !a. is_null ( ) {
262
272
let a: * mut BoxRepr = transmute ( a) ;
263
273
274
+ debug_ptr ( "return_to_mut (ptr): " , a) ;
275
+ debug_ptr ( "return_to_mut (ref): " , old_ref_count as * ( ) ) ;
276
+
264
277
let ref_count = ( * a) . header . ref_count & !ALL_BITS ;
265
278
let old_bits = old_ref_count & ALL_BITS ;
266
279
( * a) . header . ref_count = ref_count | old_bits;
0 commit comments