Skip to content

Commit d20dc7a

Browse files
committed
---
yaml --- r: 42790 b: refs/heads/try c: 1b613ff h: refs/heads/master v: v3
1 parent 437e318 commit d20dc7a

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: a47fa9b32f664beb4a50527e547c81cf6d6629bf
5+
refs/heads/try: 1b613ff9fcec4b4468de76779ccd37c7281e09b5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/libcore/rt.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! Runtime calls emitted by the compiler.
1515
1616
use cast::transmute;
17-
use libc::{c_char, c_void, size_t, uintptr_t};
17+
use libc::{c_char, c_uchar, c_void, size_t, uintptr_t};
1818
use managed::raw::BoxRepr;
1919
use str;
2020
use sys;
@@ -123,6 +123,11 @@ pub unsafe fn check_not_borrowed(a: *u8) {
123123
}
124124
}
125125

126+
#[lang="strdup_uniq"]
127+
pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str {
128+
str::raw::from_buf_len(ptr, len)
129+
}
130+
126131
// Local Variables:
127132
// mode: rust;
128133
// fill-column: 78;

branches/try/src/librustc/middle/lang_items.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ pub enum LangItem {
7474
BorrowAsImmFnLangItem, // 30
7575
ReturnToMutFnLangItem, // 31
7676
CheckNotBorrowedFnLangItem, // 32
77+
StrDupUniqFnLangItem, // 33
7778
}
7879

7980
struct LanguageItems {
80-
items: [ Option<def_id> * 33 ]
81+
items: [ Option<def_id> * 34 ]
8182
}
8283

8384
impl LanguageItems {
8485
static pub fn new() -> LanguageItems {
8586
LanguageItems {
86-
items: [ None, ..33 ]
87+
items: [ None, ..34 ]
8788
}
8889
}
8990

@@ -133,6 +134,7 @@ impl LanguageItems {
133134
30 => "borrow_as_imm",
134135
31 => "return_to_mut",
135136
32 => "check_not_borrowed",
137+
33 => "strdup_uniq",
136138

137139
_ => "???"
138140
}
@@ -243,6 +245,9 @@ impl LanguageItems {
243245
pub fn check_not_borrowed_fn(&const self) -> def_id {
244246
self.items[CheckNotBorrowedFnLangItem as uint].get()
245247
}
248+
pub fn strdup_uniq_fn(&const self) -> def_id {
249+
self.items[StrDupUniqFnLangItem as uint].get()
250+
}
246251
}
247252

248253
fn LanguageItemCollector(crate: @crate,
@@ -289,6 +294,7 @@ fn LanguageItemCollector(crate: @crate,
289294
item_refs.insert(~"return_to_mut", ReturnToMutFnLangItem as uint);
290295
item_refs.insert(~"check_not_borrowed",
291296
CheckNotBorrowedFnLangItem as uint);
297+
item_refs.insert(~"strdup_uniq", StrDupUniqFnLangItem as uint);
292298

293299
LanguageItemCollector {
294300
crate: crate,

branches/try/src/librustc/middle/trans/tvec.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,9 @@ fn trans_lit_str(bcx: block,
276276

277277

278278
fn trans_uniq_or_managed_vstore(bcx: block,
279-
heap: heap,
280-
vstore_expr: @ast::expr,
281-
content_expr: @ast::expr) -> DatumBlock
282-
{
279+
heap: heap,
280+
vstore_expr: @ast::expr,
281+
content_expr: @ast::expr) -> DatumBlock {
283282
//!
284283
//
285284
// @[...] or ~[...] (also @"..." or ~"...") allocate boxes in the
@@ -289,6 +288,34 @@ fn trans_uniq_or_managed_vstore(bcx: block,
289288
bcx.expr_to_str(vstore_expr), heap);
290289
let _indenter = indenter();
291290

291+
// Handle ~"".
292+
match heap {
293+
heap_exchange => {
294+
match content_expr.node {
295+
ast::expr_lit(@ast::spanned {
296+
node: ast::lit_str(s), _
297+
}) => {
298+
let llptrval = C_cstr(bcx.ccx(), copy *s);
299+
let llptrval = PointerCast(bcx, llptrval, T_ptr(T_i8()));
300+
let llsizeval = C_uint(bcx.ccx(), s.len());
301+
let typ = ty::mk_estr(bcx.tcx(), ty::vstore_uniq);
302+
let lldestval = datum::scratch_datum(bcx, typ, false);
303+
let bcx = callee::trans_rtcall_or_lang_call(
304+
bcx,
305+
bcx.tcx().lang_items.strdup_uniq_fn(),
306+
~[ llptrval, llsizeval ],
307+
expr::SaveIn(lldestval.to_ref_llval(bcx)));
308+
return datum::DatumBlock {
309+
bcx: bcx,
310+
datum: lldestval
311+
};
312+
}
313+
_ => {}
314+
}
315+
}
316+
heap_shared => {}
317+
}
318+
292319
let vt = vec_types_from_expr(bcx, vstore_expr);
293320
let count = elements_required(bcx, content_expr);
294321

0 commit comments

Comments
 (0)