about summary refs log tree commit diff
path: root/src/rt/rust_upcall.cpp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-02-17 12:08:03 -0800
committerBrian Anderson <banderson@mozilla.com>2012-02-17 12:08:03 -0800
commit54d7bffbb8f79d4680b6200ee50e0ca8eb2dc3c3 (patch)
treea1765238a29fad32c6f3ee7f9df8a8ba6a154d19 /src/rt/rust_upcall.cpp
parentdb62154062534a61b618f46d4c8715479ce150af (diff)
downloadrust-54d7bffbb8f79d4680b6200ee50e0ca8eb2dc3c3.tar.gz
rust-54d7bffbb8f79d4680b6200ee50e0ca8eb2dc3c3.zip
rt: Make upcall_vec_push an intrinsic
Diffstat (limited to 'src/rt/rust_upcall.cpp')
-rw-r--r--src/rt/rust_upcall.cpp50
1 files changed, 20 insertions, 30 deletions
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp
index 905b546b0b7..fcd9483eb63 100644
--- a/src/rt/rust_upcall.cpp
+++ b/src/rt/rust_upcall.cpp
@@ -270,6 +270,26 @@ upcall_shared_free(void* ptr) {
     UPCALL_SWITCH_STACK(&args, upcall_s_shared_free);
 }
 
+struct s_shared_realloc_args {
+    void *retval;
+    void *ptr;
+    size_t size;
+};
+
+extern "C" CDECL void
+upcall_s_shared_realloc(s_shared_realloc_args *args) {
+    rust_task *task = rust_task_thread::get_task();
+    LOG_UPCALL_ENTRY(task);
+    args->retval = task->kernel->realloc(args->ptr, args->size);
+}
+
+extern "C" CDECL void *
+upcall_shared_realloc(void *ptr, size_t size) {
+    s_shared_realloc_args args = {NULL, ptr, size};
+    UPCALL_SWITCH_STACK(&args, upcall_s_shared_realloc);
+    return args.retval;
+}
+
 /**********************************************************************
  * Called to deep copy a type descriptor onto the exchange heap.
  * Used when sending closures.  It's possible that we should have
@@ -431,36 +451,6 @@ upcall_vec_grow(rust_vec** vp, size_t new_sz) {
     UPCALL_SWITCH_STACK(&args, upcall_s_vec_grow);
 }
 
-// Copy elements from one vector to another,
-// dealing with reference counts
-static inline void
-copy_elements(type_desc *elem_t,
-              void *pdst, void *psrc, size_t n) {
-    char *dst = (char *)pdst, *src = (char *)psrc;
-    memmove(dst, src, n);
-
-    // increment the refcount of each element of the vector
-    if (elem_t->take_glue) {
-        glue_fn *take_glue = elem_t->take_glue;
-        size_t elem_size = elem_t->size;
-        const type_desc **tydescs = elem_t->first_param;
-        for (char *p = dst; p < dst+n; p += elem_size) {
-            take_glue(NULL, NULL, tydescs, p);
-        }
-    }
-}
-
-extern "C" CDECL void
-upcall_vec_push(rust_vec** vp, type_desc* elt_ty, void* elt) {
-    // NB: This runs entirely on the Rust stack because it invokes take glue
-
-    size_t new_sz = (*vp)->fill + elt_ty->size;
-    reserve_vec_fast(vp, new_sz);
-    rust_vec* v = *vp;
-    copy_elements(elt_ty, &v->data[0] + v->fill,
-                  elt, elt_ty->size);
-    v->fill += elt_ty->size;
-}
 
 /**********************************************************************
  * Returns a token that can be used to deallocate all of the allocated space