@@ -457,11 +457,14 @@ pub fn add_clean(bcx: @Block, val: ValueRef, t: ty::t) {
457
457
458
458
let cleanup_type = cleanup_type ( bcx. tcx ( ) , t) ;
459
459
in_scope_cx ( bcx, None , |scope_info| {
460
- scope_info. cleanups . push ( clean ( @TypeDroppingCleanupFunction {
461
- val : val,
462
- t : t,
463
- } as @CleanupFunction ,
464
- cleanup_type) ) ;
460
+ {
461
+ let mut cleanups = scope_info. cleanups . borrow_mut ( ) ;
462
+ cleanups. get ( ) . push ( clean ( @TypeDroppingCleanupFunction {
463
+ val : val,
464
+ t : t,
465
+ } as @CleanupFunction ,
466
+ cleanup_type) ) ;
467
+ }
465
468
grow_scope_clean ( scope_info) ;
466
469
} )
467
470
}
@@ -473,12 +476,15 @@ pub fn add_clean_temp_immediate(cx: @Block, val: ValueRef, ty: ty::t) {
473
476
ty. repr( cx. tcx( ) ) ) ;
474
477
let cleanup_type = cleanup_type ( cx. tcx ( ) , ty) ;
475
478
in_scope_cx ( cx, None , |scope_info| {
476
- scope_info. cleanups . push ( clean_temp ( val,
477
- @ImmediateTypeDroppingCleanupFunction {
478
- val : val,
479
- t : ty,
480
- } as @CleanupFunction ,
481
- cleanup_type) ) ;
479
+ {
480
+ let mut cleanups = scope_info. cleanups . borrow_mut ( ) ;
481
+ cleanups. get ( ) . push ( clean_temp ( val,
482
+ @ImmediateTypeDroppingCleanupFunction {
483
+ val : val,
484
+ t : ty,
485
+ } as @CleanupFunction ,
486
+ cleanup_type) ) ;
487
+ }
482
488
grow_scope_clean ( scope_info) ;
483
489
} )
484
490
}
@@ -502,12 +508,15 @@ pub fn add_clean_temp_mem_in_scope_(bcx: @Block, scope_id: Option<ast::NodeId>,
502
508
t. repr( bcx. tcx( ) ) ) ;
503
509
let cleanup_type = cleanup_type ( bcx. tcx ( ) , t) ;
504
510
in_scope_cx ( bcx, scope_id, |scope_info| {
505
- scope_info. cleanups . push ( clean_temp ( val,
506
- @TypeDroppingCleanupFunction {
507
- val : val,
508
- t : t,
509
- } as @CleanupFunction ,
510
- cleanup_type) ) ;
511
+ {
512
+ let mut cleanups = scope_info. cleanups . borrow_mut ( ) ;
513
+ cleanups. get ( ) . push ( clean_temp ( val,
514
+ @TypeDroppingCleanupFunction {
515
+ val : val,
516
+ t : t,
517
+ } as @CleanupFunction ,
518
+ cleanup_type) ) ;
519
+ }
511
520
grow_scope_clean ( scope_info) ;
512
521
} )
513
522
}
@@ -531,16 +540,19 @@ pub fn add_clean_return_to_mut(bcx: @Block,
531
540
bcx. val_to_str( frozen_val_ref) ,
532
541
bcx. val_to_str( bits_val_ref) ) ;
533
542
in_scope_cx ( bcx, Some ( scope_id) , |scope_info| {
534
- scope_info. cleanups . push ( clean_temp (
535
- frozen_val_ref,
536
- @WriteGuardReleasingCleanupFunction {
537
- root_key : root_key,
538
- frozen_val_ref : frozen_val_ref,
539
- bits_val_ref : bits_val_ref,
540
- filename_val : filename_val,
541
- line_val : line_val,
542
- } as @CleanupFunction ,
543
- normal_exit_only) ) ;
543
+ {
544
+ let mut cleanups = scope_info. cleanups . borrow_mut ( ) ;
545
+ cleanups. get ( ) . push ( clean_temp (
546
+ frozen_val_ref,
547
+ @WriteGuardReleasingCleanupFunction {
548
+ root_key : root_key,
549
+ frozen_val_ref : frozen_val_ref,
550
+ bits_val_ref : bits_val_ref,
551
+ filename_val : filename_val,
552
+ line_val : line_val,
553
+ } as @CleanupFunction ,
554
+ normal_exit_only) ) ;
555
+ }
544
556
grow_scope_clean ( scope_info) ;
545
557
} )
546
558
}
@@ -558,9 +570,12 @@ pub fn add_clean_free(cx: @Block, ptr: ValueRef, heap: heap) {
558
570
}
559
571
} ;
560
572
in_scope_cx ( cx, None , |scope_info| {
561
- scope_info. cleanups . push ( clean_temp ( ptr,
562
- free_fn,
563
- normal_exit_and_unwind) ) ;
573
+ {
574
+ let mut cleanups = scope_info. cleanups . borrow_mut ( ) ;
575
+ cleanups. get ( ) . push ( clean_temp ( ptr,
576
+ free_fn,
577
+ normal_exit_and_unwind) ) ;
578
+ }
564
579
grow_scope_clean ( scope_info) ;
565
580
} )
566
581
}
@@ -571,16 +586,23 @@ pub fn add_clean_free(cx: @Block, ptr: ValueRef, heap: heap) {
571
586
// drop glue checks whether it is zero.
572
587
pub fn revoke_clean ( cx : @Block , val : ValueRef ) {
573
588
in_scope_cx ( cx, None , |scope_info| {
574
- let cleanup_pos = scope_info. cleanups . iter ( ) . position (
575
- |cu| match * cu {
576
- clean_temp( v, _, _) if v == val => true ,
577
- _ => false
578
- } ) ;
589
+ let cleanup_pos = {
590
+ let mut cleanups = scope_info. cleanups . borrow_mut ( ) ;
591
+ cleanups. get ( ) . iter ( ) . position ( |cu| {
592
+ match * cu {
593
+ clean_temp( v, _, _) if v == val => true ,
594
+ _ => false
595
+ }
596
+ } )
597
+ } ;
579
598
for i in cleanup_pos. iter ( ) {
580
- scope_info. cleanups =
581
- vec:: append ( scope_info. cleanups . slice ( 0 u, * i) . to_owned ( ) ,
582
- scope_info. cleanups . slice ( * i + 1 u,
583
- scope_info. cleanups . len ( ) ) ) ;
599
+ let new_cleanups = {
600
+ let cleanups = scope_info. cleanups . borrow ( ) ;
601
+ vec:: append ( cleanups. get ( ) . slice ( 0 u, * i) . to_owned ( ) ,
602
+ cleanups. get ( ) . slice ( * i + 1 u, cleanups. get ( )
603
+ . len ( ) ) )
604
+ } ;
605
+ scope_info. cleanups . set ( new_cleanups) ;
584
606
shrink_scope_clean ( scope_info, * i) ;
585
607
}
586
608
} )
@@ -589,7 +611,7 @@ pub fn revoke_clean(cx: @Block, val: ValueRef) {
589
611
pub fn block_cleanups ( bcx : & Block ) -> ~[ cleanup ] {
590
612
match bcx. scope . get ( ) {
591
613
None => ~[ ] ,
592
- Some ( inf) => inf. cleanups . clone ( ) ,
614
+ Some ( inf) => inf. cleanups . get ( ) ,
593
615
}
594
616
}
595
617
@@ -600,7 +622,7 @@ pub struct ScopeInfo {
600
622
// A list of functions that must be run at when leaving this
601
623
// block, cleaning up any variables that were introduced in the
602
624
// block.
603
- cleanups : ~[ cleanup ] ,
625
+ cleanups : RefCell < ~[ cleanup ] > ,
604
626
// Existing cleanup paths that may be reused, indexed by destination and
605
627
// cleared when the set of cleanups changes.
606
628
cleanup_paths : ~[ cleanup_path ] ,
@@ -612,7 +634,8 @@ pub struct ScopeInfo {
612
634
613
635
impl ScopeInfo {
614
636
pub fn empty_cleanups ( & mut self ) -> bool {
615
- self . cleanups . is_empty ( )
637
+ let cleanups = self . cleanups . borrow ( ) ;
638
+ cleanups. get ( ) . is_empty ( )
616
639
}
617
640
}
618
641
0 commit comments