Skip to content

Commit

Permalink
auto merge of #5149 : brson/rust/rt, r=brson
Browse files Browse the repository at this point in the history
Just a few minor things required for freestanding Rust.
  • Loading branch information
bors committed Feb 28, 2013
2 parents 6ebc761 + 1b10170 commit 269409f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/rt/rust_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down
7 changes: 6 additions & 1 deletion src/rt/rust_upcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions src/rt/rust_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 269409f

Please sign in to comment.