about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-08-26 12:22:33 -0700
committerBrian Anderson <banderson@mozilla.com>2011-08-26 13:20:23 -0700
commit4e136d1fd9bd5536d441c062d41e7b71b375a942 (patch)
tree004b199b79917efabbb804050bd60acc8c8686e8 /src/comp
parent3aef2c1d7db86ff842796e9ea93acf8c09aac44c (diff)
downloadrust-4e136d1fd9bd5536d441c062d41e7b71b375a942.tar.gz
rust-4e136d1fd9bd5536d441c062d41e7b71b375a942.zip
Add rustc::middle::cstrcache for getting c string bufs safely
We continue to leak string buffers in trans so this creates a way to get c
string buffers from strings while guaranteeing that they are not freed before
use.

Hopefully this can be made efficient in the istr regime.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/cstrcache.rs29
-rw-r--r--src/comp/rustc.rc1
2 files changed, 30 insertions, 0 deletions
diff --git a/src/comp/middle/cstrcache.rs b/src/comp/middle/cstrcache.rs
new file mode 100644
index 00000000000..0b0cd320578
--- /dev/null
+++ b/src/comp/middle/cstrcache.rs
@@ -0,0 +1,29 @@
+// Provides a safe way to get C pointers to strings, because in many
+// places LLVM wants a string but doesn't take a copy.
+
+import std::str;
+
+export t;
+export mk;
+export get_cstr;
+
+type t_ = @{
+    // This string is boxed so that I remember that it has to be boxed
+    // after the ivec conversion.
+    mutable cache: [@str]
+};
+
+tag t {
+    private(t_);
+}
+
+fn mk() -> t {
+    ret private(@{mutable cache: []});
+}
+
+fn get_cstr(t: &t, s: &str) -> str::rustrt::sbuf {
+    let boxed = @s;
+    let buf = str::buf(*boxed);
+    (*t).cache += [boxed];
+    ret buf;
+}
\ No newline at end of file
diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc
index c9f0d2f067b..0dd9f004ad8 100644
--- a/src/comp/rustc.rc
+++ b/src/comp/rustc.rc
@@ -30,6 +30,7 @@ mod middle {
     mod freevars;
     mod shape;
     mod gc;
+    mod cstrcache;
 
     mod tstate {
         mod ck;