Skip to content

Instantly share code, notes, and snippets.

@killerswan
Forked from brson/gist:1625144
Created January 17, 2012 06:39
Show Gist options
  • Save killerswan/1625204 to your computer and use it in GitHub Desktop.
Save killerswan/1625204 to your computer and use it in GitHub Desktop.
reserve
fn reserve(&ss: str, nn: uint) unsafe {
// start with an existing string
str::char_len(ss); std::io::println("+++A+++");
// make a vector
let vv: [u8] = unsafe::reinterpret_cast(ss);
str::char_len(ss); std::io::println("+++B+++");
// expand it to size + \0
vec::reserve(vv, nn+1u);
// FIXME:
// fails here sometimes on assertion in byte_len called by char_len
str::char_len(ss); std::io::println("+++C+++");
// forget the vector
unsafe::leak(vv);
str::char_len(ss); std::io::println("+++D+++");
}
/* EXAMPLE ERROR:
...
+++A+++
+++B+++
rust: upcall fail 'Assertion vlen > 0 failed', src/libcore/str.rs:133
rust: domain main @0x16d6510 root task failed
rust: fatal, 'live_allocs < 1' failed, ./src/rt/memory_region.cpp:54
Aborted
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment