@@ -457,32 +457,32 @@ mod write {
457
457
*
458
458
*/
459
459
460
- fn build_link_meta ( sess : Session , c : & ast:: crate , output : & Path ,
460
+ fn build_link_meta ( sess : Session , c : ast:: crate , output : & Path ,
461
461
symbol_hasher : & hash:: State ) -> link_meta {
462
462
463
463
type provided_metas =
464
- { name : Option < @ str > ,
465
- vers : Option < @ str > ,
464
+ { name : Option < ~ str > ,
465
+ vers : Option < ~ str > ,
466
466
cmh_items : ~[ @ast:: meta_item ] } ;
467
467
468
- fn provided_link_metas ( sess : Session , c : & ast:: crate ) ->
468
+ fn provided_link_metas ( sess : Session , c : ast:: crate ) ->
469
469
provided_metas {
470
- let mut name = None ;
471
- let mut vers = None ;
472
- let mut cmh_items = ~[ ] ;
473
- let linkage_metas = attr:: find_linkage_metas ( c. node . attrs ) ;
474
- attr:: require_unique_names ( sess. diagnostic ( ) , linkage_metas) ;
470
+ let mut name: Option < ~str > = None ;
471
+ let mut vers: Option < ~str > = None ;
472
+ let mut cmh_items: ~[ @ast:: meta_item ] = ~[ ] ;
473
+ let linkage_metas =
474
+ attr:: find_linkage_metas ( /*bad*/ copy c. node . attrs ) ;
475
+ // XXX: Bad copy.
476
+ attr:: require_unique_names ( sess. diagnostic ( ) , copy linkage_metas) ;
475
477
for linkage_metas. each |meta| {
476
478
if attr:: get_meta_item_name ( * meta) == ~"name" {
477
479
match attr:: get_meta_item_value_str ( * meta) {
478
- // Changing attr would avoid the need for the copy
479
- // here
480
- Some ( v) => { name = Some ( v. to_managed ( ) ) ; }
480
+ Some ( ref v) => { name = Some ( ( /*bad*/ copy * v) ) ; }
481
481
None => cmh_items. push ( * meta)
482
482
}
483
483
} else if attr:: get_meta_item_name ( * meta) == ~"vers" {
484
484
match attr:: get_meta_item_value_str ( * meta) {
485
- Some ( v) => { vers = Some ( v . to_managed ( ) ) ; }
485
+ Some ( ref v) => { vers = Some ( ( /*bad*/ copy * v ) ) ; }
486
486
None => cmh_items. push ( * meta)
487
487
}
488
488
} else { cmh_items. push ( * meta) ; }
@@ -492,8 +492,9 @@ fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
492
492
493
493
// This calculates CMH as defined above
494
494
fn crate_meta_extras_hash ( symbol_hasher : & hash:: State ,
495
- -cmh_items : ~[ @ast:: meta_item ] ,
496
- dep_hashes : ~[ ~str ] ) -> @str {
495
+ _crate : ast:: crate ,
496
+ metas : provided_metas ,
497
+ dep_hashes : ~[ ~str ] ) -> ~str {
497
498
fn len_and_str ( s : ~str ) -> ~str {
498
499
return fmt ! ( "%u_%s" , str :: len( s) , s) ;
499
500
}
@@ -502,7 +503,7 @@ fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
502
503
return len_and_str ( pprust:: lit_to_str ( @l) ) ;
503
504
}
504
505
505
- let cmh_items = attr:: sort_meta_items ( cmh_items) ;
506
+ let cmh_items = attr:: sort_meta_items ( /*bad*/ copy metas . cmh_items ) ;
506
507
507
508
symbol_hasher. reset ( ) ;
508
509
for cmh_items. each |m| {
@@ -525,53 +526,52 @@ fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
525
526
symbol_hasher. write_str ( len_and_str ( * dh) ) ;
526
527
}
527
528
528
- // tjc: allocation is unfortunate; need to change core::hash
529
- return truncated_hash_result ( symbol_hasher) . to_managed ( ) ;
529
+ return truncated_hash_result ( symbol_hasher) ;
530
530
}
531
531
532
- fn warn_missing ( sess : Session , name : & str , default : & str ) {
532
+ fn warn_missing ( sess : Session , name : ~ str , default : ~ str ) {
533
533
if !sess. building_library { return ; }
534
534
sess. warn ( fmt ! ( "missing crate link meta `%s`, using `%s` as default" ,
535
535
name, default ) ) ;
536
536
}
537
537
538
- fn crate_meta_name ( sess : Session , output : & Path , - opt_name : Option < @ str > )
539
- -> @ str {
540
- return match opt_name {
541
- Some ( v) => v ,
538
+ fn crate_meta_name ( sess : Session , _crate : ast :: crate ,
539
+ output : & Path , metas : provided_metas ) -> ~ str {
540
+ return match metas . name {
541
+ Some ( ref v) => ( /*bad*/ copy * v ) ,
542
542
None => {
543
- // to_managed could go away if there was a version of
544
- // filestem that returned an @str
545
- let name = session:: expect ( sess,
546
- output. filestem ( ) ,
547
- || fmt ! ( "output file name `%s` doesn't\
543
+ let name = match output. filestem ( ) {
544
+ None => sess. fatal ( fmt ! ( "output file name `%s` doesn't\
548
545
appear to have a stem",
549
- output. to_str( ) ) ) . to_managed ( ) ;
550
- warn_missing ( sess, ~"name", name) ;
546
+ output. to_str( ) ) ) ,
547
+ Some ( ref s) => ( /*bad*/ copy * s)
548
+ } ;
549
+ // XXX: Bad copy.
550
+ warn_missing ( sess, ~"name", copy name) ;
551
551
name
552
552
}
553
553
} ;
554
554
}
555
555
556
- fn crate_meta_vers ( sess : Session , opt_vers : Option < @str > ) -> @str {
557
- return match opt_vers {
558
- Some ( v) => v,
556
+ fn crate_meta_vers ( sess : Session , _crate : ast:: crate ,
557
+ metas : provided_metas ) -> ~str {
558
+ return match metas. vers {
559
+ Some ( ref v) => ( /*bad*/ copy * v) ,
559
560
None => {
560
- let vers = @"0.0 ";
561
- warn_missing ( sess, ~"vers", vers) ;
561
+ let vers = ~"0.0 ";
562
+ // Bad copy.
563
+ warn_missing ( sess, ~"vers", copy vers) ;
562
564
vers
563
565
}
564
566
} ;
565
567
}
566
568
567
- let { name: opt_name , vers: opt_vers ,
568
- cmh_items : cmh_items } = provided_link_metas ( sess, c) ;
569
- let name = crate_meta_name ( sess, output, move opt_name) ;
570
- let vers = crate_meta_vers ( sess, move opt_vers) ;
569
+ let provided_metas = provided_link_metas ( sess, c) ;
570
+ let name = crate_meta_name ( sess, c, output, provided_metas) ;
571
+ let vers = crate_meta_vers ( sess, c, provided_metas) ;
571
572
let dep_hashes = cstore:: get_dep_hashes ( sess. cstore ) ;
572
573
let extras_hash =
573
- crate_meta_extras_hash ( symbol_hasher, move cmh_items,
574
- dep_hashes) ;
574
+ crate_meta_extras_hash ( symbol_hasher, c, provided_metas, dep_hashes) ;
575
575
576
576
return { name: name, vers: vers, extras_hash: extras_hash} ;
577
577
}
@@ -583,7 +583,7 @@ fn truncated_hash_result(symbol_hasher: &hash::State) -> ~str unsafe {
583
583
584
584
// This calculates STH for a symbol, as defined above
585
585
fn symbol_hash ( tcx : ty:: ctxt , symbol_hasher : & hash:: State , t : ty:: t ,
586
- link_meta : link_meta ) -> @ str {
586
+ link_meta : link_meta ) -> ~ str {
587
587
// NB: do *not* use abbrevs here as we want the symbol names
588
588
// to be independent of one another in the crate.
589
589
@@ -593,20 +593,20 @@ fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t,
593
593
symbol_hasher.write_str(link_meta.extras_hash);
594
594
symbol_hasher.write_str(~" -");
595
595
symbol_hasher.write_str(encoder::encoded_ty(tcx, t));
596
- let mut hash = truncated_hash_result(symbol_hasher);
596
+ let hash = truncated_hash_result(symbol_hasher);
597
597
// Prefix with _ so that it never blends into adjacent digits
598
- str::unshift_char(&mut hash, '_');
599
- // tjc: allocation is unfortunate; need to change core::hash
600
- hash.to_managed()
598
+
599
+ return ~" _" + hash;
601
600
}
602
601
603
- fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> @ str {
602
+ fn get_symbol_hash ( ccx : @crate_ctxt , t : ty:: t ) -> ~ str {
604
603
match ccx. type_hashcodes . find ( t) {
605
- Some(h) => h ,
604
+ Some ( ref h) => return ( /*bad*/ copy * h ) ,
606
605
None => {
607
606
let hash = symbol_hash ( ccx. tcx , ccx. symbol_hasher , t, ccx. link_meta ) ;
608
- ccx.type_hashcodes.insert(t, hash);
609
- hash
607
+ // XXX: Bad copy. Prefer `@str`?
608
+ ccx. type_hashcodes . insert ( t, copy hash) ;
609
+ return hash;
610
610
}
611
611
}
612
612
}
@@ -664,30 +664,30 @@ fn mangle(sess: Session, ss: path) -> ~str {
664
664
665
665
fn exported_name ( sess : Session ,
666
666
+path : path,
667
- hash : & str ,
668
- vers : & str ) -> ~str {
667
+ + hash : ~ str ,
668
+ + vers : ~ str ) -> ~str {
669
669
return mangle ( sess,
670
- vec:: append_one (
671
- vec:: append_one ( path, path_name ( sess. ident_of ( hash. to_owned ( ) ) ) ) ,
672
- path_name ( sess. ident_of ( vers. to_owned ( ) ) ) ) ) ;
670
+ vec:: append_one (
671
+ vec:: append_one ( path, path_name ( sess. ident_of ( hash) ) ) ,
672
+ path_name ( sess. ident_of ( vers) ) ) ) ;
673
673
}
674
674
675
675
fn mangle_exported_name ( ccx : @crate_ctxt , +path : path, t : ty:: t ) -> ~str {
676
676
let hash = get_symbol_hash ( ccx, t) ;
677
677
return exported_name ( ccx. sess , path,
678
678
hash,
679
- ccx. link_meta . vers ) ;
679
+ /*bad*/ copy ccx. link_meta . vers ) ;
680
680
}
681
681
682
682
fn mangle_internal_name_by_type_only ( ccx : @crate_ctxt ,
683
683
t : ty:: t ,
684
- name : & str ) -> ~str {
684
+ + name : ~ str ) -> ~str {
685
685
let s = ppaux:: ty_to_short_str ( ccx. tcx , t) ;
686
686
let hash = get_symbol_hash ( ccx, t) ;
687
687
return mangle ( ccx. sess ,
688
- ~[ path_name ( ccx. sess . ident_of ( name. to_owned ( ) ) ) ,
689
- path_name ( ccx. sess . ident_of ( s) ) ,
690
- path_name ( ccx. sess . ident_of ( hash. to_owned ( ) ) ) ] ) ;
688
+ ~[ path_name ( ccx. sess . ident_of ( name) ) ,
689
+ path_name ( ccx. sess . ident_of ( s) ) ,
690
+ path_name ( ccx. sess . ident_of ( hash) ) ] ) ;
691
691
}
692
692
693
693
fn mangle_internal_name_by_path_and_seq ( ccx : @crate_ctxt ,
@@ -706,7 +706,7 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, +flav: ~str) -> ~str {
706
706
}
707
707
708
708
709
- fn output_dll_filename ( os : session:: os , lm : link_meta ) -> ~str {
709
+ fn output_dll_filename ( os : session:: os , lm : & link_meta ) -> ~str {
710
710
let libname = fmt ! ( "%s-%s-%s" , lm. name, lm. extras_hash, lm. vers) ;
711
711
let ( dll_prefix, dll_suffix) = match os {
712
712
session:: os_win32 => ( win32:: DLL_PREFIX , win32:: DLL_SUFFIX ) ,
@@ -736,7 +736,7 @@ fn link_binary(sess: Session,
736
736
}
737
737
738
738
let output = if sess. building_library {
739
- let long_libname = output_dll_filename ( sess. targ_cfg . os , lm) ;
739
+ let long_libname = output_dll_filename ( sess. targ_cfg . os , & lm) ;
740
740
debug ! ( "link_meta.name: %s" , lm. name) ;
741
741
debug ! ( "long_libname: %s" , long_libname) ;
742
742
debug ! ( "out_filename: %s" , out_filename. to_str( ) ) ;
0 commit comments