Exemple #1
0
extern "C" CDECL void
upcall_vec_append(rust_task *task, type_desc *t, type_desc *elem_t,
                  rust_vec **dst_ptr, rust_vec *src, bool skip_null)
{
    LOG_UPCALL_ENTRY(task);
    rust_vec *dst = *dst_ptr;
    uintptr_t need_copy;
    size_t n_src_bytes = skip_null ? src->fill - 1 : src->fill;
    size_t n_dst_bytes = skip_null ? dst->fill - 1 : dst->fill;
    rust_vec *new_vec = vec_grow(task, dst, n_src_bytes, &need_copy, t);

    // If src and dst are the same (due to "v += v"), then dst getting
    // resized causes src to move as well.
    if (dst == src && !need_copy) {
        src = new_vec;
    }

    if (need_copy) {
        // Copy any dst elements in, omitting null if doing str.
        copy_elements(task, elem_t, &new_vec->data, &dst->data, n_dst_bytes);
    }

    // Copy any src elements in, carrying along null if doing str.
    void *new_end = (void *)((char *)new_vec->data + n_dst_bytes);
    copy_elements(task, elem_t, new_end, &src->data, src->fill);
    new_vec->fill = n_dst_bytes + src->fill;

    // Write new_vec back through the alias we were given.
    *dst_ptr = new_vec;
}
Exemple #2
0
extern "C" CDECL void
upcall_s_vec_push(s_vec_push_args *args) {
    rust_task *task = rust_scheduler::get_task();
    LOG_UPCALL_ENTRY(task);
    size_t new_sz = (*args->vp)->fill + args->elt_ty->size;
    reserve_vec(task, args->vp, new_sz);
    rust_vec* v = *args->vp;
    copy_elements(task, args->elt_ty, &v->data[0] + v->fill, 
                  args->elt, args->elt_ty->size);
    v->fill += args->elt_ty->size;
}