From d67e144f685783503c1406cb4f28ea19d91d1fec Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Wed, 13 Feb 2013 04:42:39 -0500 Subject: [PATCH 1/3] rt: get rid of rust_fn and replace with fn_env_pair plus a little cleanup. --- src/rt/rust_builtin.cpp | 34 ++++++++-------------------------- src/rt/rust_refcount.h | 8 -------- src/rt/rust_task.h | 2 -- src/rt/rustrt.def.in | 1 - 4 files changed, 8 insertions(+), 37 deletions(-) diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 86f371a30f3a..22ebc52edf09 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -249,24 +249,16 @@ debug_opaque(type_desc *t, uint8_t *front) { } } -// FIXME (#2667) this no longer reflects the actual structure of boxes! -struct rust_box { - RUST_REFCOUNTED(rust_box) - - // FIXME (#2667) `data` could be aligned differently from the actual - // box body data - uint8_t data[]; -}; - extern "C" CDECL void -debug_box(type_desc *t, rust_box *box) { +debug_box(type_desc *t, rust_opaque_box *box) { rust_task *task = rust_get_current_task(); LOG(task, stdlib, "debug_box(0x%" PRIxPTR ")", box); debug_tydesc_helper(t); LOG(task, stdlib, " refcount %" PRIdPTR, box->ref_count - 1); // -1 because we ref'ed for this call + uint8_t *data = (uint8_t *)box_body(box); for (uintptr_t i = 0; i < t->size; ++i) { - LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, box->data[i]); + LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, data[i]); } } @@ -288,20 +280,15 @@ debug_tag(type_desc *t, rust_tag *tag) { tag->variant[i]); } -struct rust_fn { - uintptr_t *thunk; - rust_box *closure; -}; - extern "C" CDECL void -debug_fn(type_desc *t, rust_fn *fn) { +debug_fn(type_desc *t, fn_env_pair *fn) { rust_task *task = rust_get_current_task(); LOG(task, stdlib, "debug_fn"); debug_tydesc_helper(t); - LOG(task, stdlib, " thunk at 0x%" PRIxPTR, fn->thunk); - LOG(task, stdlib, " closure at 0x%" PRIxPTR, fn->closure); - if (fn->closure) { - LOG(task, stdlib, " refcount %" PRIdPTR, fn->closure->ref_count); + LOG(task, stdlib, " fn at 0x%" PRIxPTR, fn->f); + LOG(task, stdlib, " env at 0x%" PRIxPTR, fn->env); + if (fn->env) { + LOG(task, stdlib, " refcount %" PRIdPTR, fn->env->ref_count); } } @@ -389,11 +376,6 @@ extern "C" CDECL FILE* rust_get_stdin() {return stdin;} extern "C" CDECL FILE* rust_get_stdout() {return stdout;} extern "C" CDECL FILE* rust_get_stderr() {return stderr;} -extern "C" CDECL int -rust_ptr_eq(type_desc *t, rust_box *a, rust_box *b) { - return a == b; -} - #if defined(__WIN32__) extern "C" CDECL void get_time(int64_t *sec, int32_t *nsec) { diff --git a/src/rt/rust_refcount.h b/src/rt/rust_refcount.h index ef7ae1f35e33..1ed05ec83395 100644 --- a/src/rt/rust_refcount.h +++ b/src/rt/rust_refcount.h @@ -17,14 +17,6 @@ // Refcounting defines typedef unsigned long ref_cnt_t; -#define RUST_REFCOUNTED(T) \ - RUST_REFCOUNTED_WITH_DTOR(T, delete (T*)this) - -#define RUST_REFCOUNTED_WITH_DTOR(T, dtor) \ - intptr_t ref_count; \ - void ref() { ++ref_count; } \ - void deref() { if (--ref_count == 0) { dtor; } } - #define RUST_ATOMIC_REFCOUNT() \ private: \ intptr_t ref_count; \ diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index cbde863fa231..23354918c504 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -168,8 +168,6 @@ #define RED_ZONE_SIZE RZ_MAC_32 #endif -struct rust_box; - struct frame_glue_fns { uintptr_t mark_glue_off; uintptr_t drop_glue_off; diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index c554489c4b35..a19f9053cbea 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -39,7 +39,6 @@ rust_list_files2 rust_log_console_on rust_log_console_off rust_process_wait -rust_ptr_eq rust_run_program rust_sched_current_nonlazy_threads rust_sched_threads From c22d0af14c621a847e71dac7fe0e7fe19bf851a1 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Wed, 13 Feb 2013 05:28:24 -0500 Subject: [PATCH 2/3] rt: take into account alignment for debug_opaque. Closes #2667 --- src/rt/rust_builtin.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 22ebc52edf09..a8e1e7a0be4b 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -241,10 +241,13 @@ debug_opaque(type_desc *t, uint8_t *front) { rust_task *task = rust_get_current_task(); LOG(task, stdlib, "debug_opaque"); debug_tydesc_helper(t); - // FIXME (#2667) may want to actually account for alignment. - // `front` may not indeed be the front byte of the passed-in - // argument. for (uintptr_t i = 0; i < t->size; ++front, ++i) { + + // Account for alignment. `front` may not indeed be the + // front byte of the passed-in argument + if (((uintptr_t)front % t->align) != 0) + front = (uint8_t *)align_to((uintptr_t)front, (size_t)t->align); + LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, *front); } } From 2c198561dd878dcfa4fca3b7785215fd3490ca84 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Wed, 13 Feb 2013 15:41:04 -0500 Subject: [PATCH 3/3] rt: Fix alignment in debug_opaque --- src/rt/rust_builtin.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index a8e1e7a0be4b..3f6545caaa8e 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -241,13 +241,12 @@ debug_opaque(type_desc *t, uint8_t *front) { rust_task *task = rust_get_current_task(); LOG(task, stdlib, "debug_opaque"); debug_tydesc_helper(t); + // Account for alignment. `front` may not indeed be the + // front byte of the passed-in argument + if (((uintptr_t)front % t->align) != 0) { + front = (uint8_t *)align_to((uintptr_t)front, (size_t)t->align); + } for (uintptr_t i = 0; i < t->size; ++front, ++i) { - - // Account for alignment. `front` may not indeed be the - // front byte of the passed-in argument - if (((uintptr_t)front % t->align) != 0) - front = (uint8_t *)align_to((uintptr_t)front, (size_t)t->align); - LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, *front); } }