From 88ec259cee17df6b78ce52b966148f0e03f02270 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Mon, 18 Jun 2012 13:16:38 -0700 Subject: [PATCH] Put type descriptors in strings created by the runtime. Progress on #2638. --- mk/rt.mk | 1 + src/rt/rust_upcall.cpp | 5 ++--- src/rt/rust_util.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++ src/rt/rust_util.h | 5 +++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/rt/rust_util.cpp diff --git a/mk/rt.mk b/mk/rt.mk index 02fcdc0def6..f51c7b1caef 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -62,6 +62,7 @@ RUNTIME_CS_$(1) := \ rt/rust_uv.cpp \ rt/rust_log.cpp \ rt/rust_port_selector.cpp \ + rt/rust_util.cpp \ rt/circular_buffer.cpp \ rt/isaac/randport.cpp \ rt/rust_kernel.cpp \ diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 9e736252fd6..ea938d386f4 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -373,9 +373,7 @@ upcall_s_str_new_shared(s_str_new_shared_args *args) { size_t str_fill = args->len + 1; size_t str_alloc = str_fill; args->retval = (rust_opaque_box *) - task->kernel->malloc(sizeof(rust_opaque_box) + - vec_size(str_fill), - "str_new_shared"); + task->boxed.malloc(&str_body_tydesc, str_fill); rust_str *str = (rust_str *)box_body(args->retval); str->body.fill = str_fill; str->body.alloc = str_alloc; @@ -425,6 +423,7 @@ upcall_s_str_concat(s_str_concat_args *args) { rust_vec_box* v = (rust_vec_box*) task->kernel->malloc(fill + sizeof(rust_vec_box), "str_concat"); + v->header.td = args->lhs->header.td; v->body.fill = v->body.alloc = fill; memmove(&v->body.data[0], &lhs->data[0], lhs->fill - 1); memmove(&v->body.data[lhs->fill - 1], &rhs->data[0], rhs->fill); diff --git a/src/rt/rust_util.cpp b/src/rt/rust_util.cpp new file mode 100644 index 00000000000..07f89ece662 --- /dev/null +++ b/src/rt/rust_util.cpp @@ -0,0 +1,43 @@ +#include "rust_type.h" +#include "rust_shape.h" + + +// A hardcoded type descriptor for strings, since the runtime needs to +// be able to create them. + +struct rust_shape_tables empty_shape_tables; + +uint8_t str_body_shape[] = { + shape::SHAPE_UNBOXED_VEC, + 0x1, // is_pod + 0x1, 0x0, // size field: 1 + shape::SHAPE_U8 +}; + +struct type_desc str_body_tydesc = { + 0, // unused + 1, // size + 1, // align + NULL, // take_glue + NULL, // drop_glue + NULL, // free_glue + NULL, // visit_glue + 0, // unused + 0, // unused + 0, // unused + 0, // unused + str_body_shape, // shape + &empty_shape_tables, // shape_tables + 0, // unused + 0, // unused +}; + +// +// Local Variables: +// mode: C++ +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// End: +// diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index a7bb56c7c37..2040a641c47 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -5,6 +5,8 @@ #include "rust_task.h" #include "rust_env.h" +extern struct type_desc str_body_tydesc; + // Inline fn used regularly elsewhere. static inline size_t @@ -82,6 +84,7 @@ make_str(rust_kernel* kernel, const char* c, size_t strlen, size_t str_alloc = str_fill; rust_str *str = (rust_str *) kernel->malloc(vec_size(str_fill), name); + str->header.td = &str_body_tydesc; str->body.fill = str_fill; str->body.alloc = str_alloc; memcpy(&str->body.data, c, strlen); @@ -94,6 +97,8 @@ make_str_vec(rust_kernel* kernel, size_t nstrs, char **strs) { rust_vec_box *v = (rust_vec_box *) kernel->malloc(vec_size(nstrs), "str vec interior"); + // FIXME: should have a real td (Issue #2639) + v->header.td = NULL; v->body.fill = v->body.alloc = sizeof(rust_vec_box*) * nstrs; for (size_t i = 0; i < nstrs; ++i) { rust_str *str = make_str(kernel, strs[i],