diff options
| author | Eric Holk <eholk@mozilla.com> | 2011-07-07 13:06:38 -0700 |
|---|---|---|
| committer | Eric Holk <eholk@mozilla.com> | 2011-07-07 18:22:27 -0700 |
| commit | 5d9a5b7d556f6573508c83242a0e7b7795d2c2dd (patch) | |
| tree | 2e213089a38b3ae68795b791f3b2345e77567048 /src/rt | |
| parent | 8acadb17c2d679291aa94e94af8cc96513cab830 (diff) | |
| download | rust-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.h | 31 | ||||
| -rw-r--r-- | src/rt/rust_internal.h | 10 | ||||
| -rw-r--r-- | src/rt/rust_util.h | 4 |
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. |
