about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-07-07 13:06:38 -0700
committerEric Holk <eholk@mozilla.com>2011-07-07 18:22:27 -0700
commit5d9a5b7d556f6573508c83242a0e7b7795d2c2dd (patch)
tree2e213089a38b3ae68795b791f3b2345e77567048 /src/rt
parent8acadb17c2d679291aa94e94af8cc96513cab830 (diff)
downloadrust-5d9a5b7d556f6573508c83242a0e7b7795d2c2dd.tar.gz
rust-5d9a5b7d556f6573508c83242a0e7b7795d2c2dd.zip
Tightened up the scoping for our various new operators, which should
make it harder to use the wrong one.
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/memory.h31
-rw-r--r--src/rt/rust_internal.h10
-rw-r--r--src/rt/rust_util.h4
3 files changed, 34 insertions, 11 deletions
diff --git a/src/rt/memory.h b/src/rt/memory.h
index edf8d27eb2d..a42795c8b64 100644
--- a/src/rt/memory.h
+++ b/src/rt/memory.h
@@ -2,33 +2,42 @@
 #ifndef MEMORY_H
 #define MEMORY_H
 
-inline void *operator new(size_t size, void *mem) {
-    return mem;
+#if 0
+inline void operator delete(void *mem, rust_task *task) {
+    task->free(mem);
+    return;
 }
+#endif
 
-inline void *operator new(size_t size, rust_kernel *kernel) {
-    return kernel->malloc(size);
+// FIXME: It would be really nice to be able to get rid of this.
+inline void *operator new[](size_t size, rust_task *task) {
+    return task->malloc(size);
 }
 
-inline void *operator new(size_t size, rust_task *task) {
+template <typename T>
+inline void *task_owned<T>::operator new(size_t size, rust_task *task) {
     return task->malloc(size);
 }
 
-inline void *operator new[](size_t size, rust_task *task) {
+template <typename T>
+inline void *task_owned<T>::operator new[](size_t size, rust_task *task) {
     return task->malloc(size);
 }
 
-inline void *operator new(size_t size, rust_task &task) {
+template <typename T>
+inline void *task_owned<T>::operator new(size_t size, rust_task &task) {
     return task.malloc(size);
 }
 
-inline void *operator new[](size_t size, rust_task &task) {
+template <typename T>
+inline void *task_owned<T>::operator new[](size_t size, rust_task &task) {
     return task.malloc(size);
 }
 
-inline void operator delete(void *mem, rust_task *task) {
-    task->free(mem);
-    return;
+template <typename T>
+inline void *kernel_owned<T>::operator new(size_t size, rust_kernel *kernel) {
+    return kernel->malloc(size);
 }
 
+
 #endif /* MEMORY_H */
diff --git a/src/rt/rust_internal.h b/src/rt/rust_internal.h
index 9d7d714064f..cd4a162cb3c 100644
--- a/src/rt/rust_internal.h
+++ b/src/rt/rust_internal.h
@@ -115,12 +115,22 @@ template <typename T> struct rc_base {
 };
 
 template <typename T> struct task_owned {
+    inline void *operator new(size_t size, rust_task *task);
+
+    inline void *operator new[](size_t size, rust_task *task);
+
+    inline void *operator new(size_t size, rust_task &task);
+
+    inline void *operator new[](size_t size, rust_task &task);
+
     void operator delete(void *ptr) {
         ((T *)ptr)->task->free(ptr);
     }
 };
 
 template <typename T> struct kernel_owned {
+    inline void *operator new(size_t size, rust_kernel *kernel);
+
     void operator delete(void *ptr) {
         ((T *)ptr)->kernel->free(ptr);
     }
diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h
index 984cd978ec2..b7c742cdb79 100644
--- a/src/rt/rust_util.h
+++ b/src/rt/rust_util.h
@@ -184,6 +184,10 @@ rust_vec : public rc_base<rust_vec>
             memcpy(&data[0], d, fill);
     }
     ~rust_vec() {}
+
+    inline void *operator new(size_t size, void *mem) {
+        return mem;
+    }
 };
 
 // Rust types vec and str look identical from our perspective.