@@ -148,28 +148,30 @@ fn trans_vstore(bcx: block, e: @ast::expr,
148
148
fn trans_estr( bcx: block, s: str, vstore: ast:: vstore,
149
149
sp: span, dest: dest) -> block {
150
150
let _icx = bcx. insn_ctxt( "tvec::trans_estr" ) ;
151
- alt vstore {
151
+ let ccx = bcx. ccx( ) ;
152
+
153
+ let c = alt vstore {
152
154
ast : : vstore_fixed( _)
153
155
{
154
- let c = str:: as_bytes( s) { |bytes|
155
- // NB: The byte vector we have here includes the trailing \0,
156
- // but we are doing a fixed-size str, meaning we _exclude_
157
- // the trailing \0. And we don't let LLVM null-terminate
158
- // either.
159
- unsafe {
160
- lib : : llvm:: llvm:: LLVMConstString (
161
- unsafe:: reinterpret_cast( vec:: unsafe:: to_ptr( bytes) ) ,
162
- ( bytes. len( ) - 1 u) as libc:: c_uint, lib:: llvm:: True )
163
- }
164
- } ;
156
+ // "hello"/_ => [i8 x 6] in llvm
157
+ #debug( "trans_estr: fixed: %s" , s) ;
158
+ C_postr ( s)
159
+ }
165
160
166
- #debug( "trans_estr: src %s" , val_str( bcx. ccx( ) . tn, c) ) ;
167
- ret base:: store_in_dest( bcx, c, dest) ;
161
+ ast:: vstore_slice( _) {
162
+ // "hello" => (*i8,uint) in llvm
163
+ #debug( "trans_estr: slice '%s'" , s) ;
164
+ let cs = PointerCast ( bcx, C_cstr ( ccx, s) , T_ptr ( T_i8 ( ) ) ) ;
165
+ C_struct ( [ cs, C_uint ( ccx, str:: len( s) ) ] )
168
166
}
167
+
169
168
_ {
170
169
bcx. ccx( ) . sess. span_unimpl( sp, "unhandled tvec::trans_estr" ) ;
171
170
}
172
- }
171
+ } ;
172
+
173
+ #debug( "trans_estr: type: %s" , val_str( ccx. tn, c) ) ;
174
+ base:: store_in_dest( bcx, c, dest)
173
175
}
174
176
175
177
fn trans_str( bcx: block, s: str, dest: dest) -> block {
0 commit comments