auto merge of #5149 : brson/rust/rt, r=brson

Just a few minor things required for freestanding Rust.
This commit is contained in:
bors 2013-02-27 16:42:42 -08:00
commit 269409f912
3 changed files with 12 additions and 8 deletions

View File

@ -124,8 +124,7 @@ vec_reserve_shared_actual(type_desc* ty, rust_vec_box** vp,
extern "C" CDECL void
vec_reserve_shared(type_desc* ty, rust_vec_box** vp,
size_t n_elts) {
rust_task *task = rust_get_current_task();
reserve_vec_exact(task, vp, n_elts * ty->size);
reserve_vec_exact(vp, n_elts * ty->size);
}
extern "C" CDECL size_t
@ -445,9 +444,8 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
out_tm->tm_nsec = nsec;
if (zone != NULL) {
rust_task *task = rust_get_current_task();
size_t size = strlen(zone);
reserve_vec_exact(task, &out_tm->tm_zone, size + 1);
reserve_vec_exact(&out_tm->tm_zone, size + 1);
memcpy(out_tm->tm_zone->body.data, zone, size);
out_tm->tm_zone->body.fill = size + 1;
out_tm->tm_zone->body.data[size] = '\0';

View File

@ -118,7 +118,12 @@ extern "C" CDECL void
upcall_fail(char const *expr,
char const *file,
size_t line) {
rust_task *task = rust_get_current_task();
rust_task *task = rust_try_get_current_task();
if (task == NULL) {
// NOTE: Need to think about what to do here
printf("failure outside of a task");
abort();
}
s_fail_args args = {task,expr,file,line};
UPCALL_SWITCH_STACK(task, &args, upcall_s_fail);
}

View File

@ -67,11 +67,12 @@ inline void reserve_vec_exact_shared(rust_task* task, rust_vec_box** vpp,
}
}
inline void reserve_vec_exact(rust_task* task, rust_vec_box** vpp,
inline void reserve_vec_exact(rust_vec_box** vpp,
size_t size) {
if (size > (*vpp)->body.alloc) {
*vpp = (rust_vec_box*)task->kernel
->realloc(*vpp, size + sizeof(rust_vec_box));
rust_exchange_alloc exchange_alloc;
*vpp = (rust_vec_box*)exchange_alloc
.realloc(*vpp, size + sizeof(rust_vec_box));
(*vpp)->body.alloc = size;
}
}