-
-
Save killerswan/1625204 to your computer and use it in GitHub Desktop.
reserve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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