Skip to content

Commit 88ec259

Browse files
committed
Put type descriptors in strings created by the runtime. Progress on #2638.
1 parent b4484d5 commit 88ec259

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

mk/rt.mk

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ RUNTIME_CS_$(1) := \
6262
rt/rust_uv.cpp \
6363
rt/rust_log.cpp \
6464
rt/rust_port_selector.cpp \
65+
rt/rust_util.cpp \
6566
rt/circular_buffer.cpp \
6667
rt/isaac/randport.cpp \
6768
rt/rust_kernel.cpp \

src/rt/rust_upcall.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ upcall_s_str_new_shared(s_str_new_shared_args *args) {
373373
size_t str_fill = args->len + 1;
374374
size_t str_alloc = str_fill;
375375
args->retval = (rust_opaque_box *)
376-
task->kernel->malloc(sizeof(rust_opaque_box) +
377-
vec_size<char>(str_fill),
378-
"str_new_shared");
376+
task->boxed.malloc(&str_body_tydesc, str_fill);
379377
rust_str *str = (rust_str *)box_body(args->retval);
380378
str->body.fill = str_fill;
381379
str->body.alloc = str_alloc;
@@ -425,6 +423,7 @@ upcall_s_str_concat(s_str_concat_args *args) {
425423
rust_vec_box* v = (rust_vec_box*)
426424
task->kernel->malloc(fill + sizeof(rust_vec_box),
427425
"str_concat");
426+
v->header.td = args->lhs->header.td;
428427
v->body.fill = v->body.alloc = fill;
429428
memmove(&v->body.data[0], &lhs->data[0], lhs->fill - 1);
430429
memmove(&v->body.data[lhs->fill - 1], &rhs->data[0], rhs->fill);

src/rt/rust_util.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "rust_type.h"
2+
#include "rust_shape.h"
3+
4+
5+
// A hardcoded type descriptor for strings, since the runtime needs to
6+
// be able to create them.
7+
8+
struct rust_shape_tables empty_shape_tables;
9+
10+
uint8_t str_body_shape[] = {
11+
shape::SHAPE_UNBOXED_VEC,
12+
0x1, // is_pod
13+
0x1, 0x0, // size field: 1
14+
shape::SHAPE_U8
15+
};
16+
17+
struct type_desc str_body_tydesc = {
18+
0, // unused
19+
1, // size
20+
1, // align
21+
NULL, // take_glue
22+
NULL, // drop_glue
23+
NULL, // free_glue
24+
NULL, // visit_glue
25+
0, // unused
26+
0, // unused
27+
0, // unused
28+
0, // unused
29+
str_body_shape, // shape
30+
&empty_shape_tables, // shape_tables
31+
0, // unused
32+
0, // unused
33+
};
34+
35+
//
36+
// Local Variables:
37+
// mode: C++
38+
// fill-column: 78;
39+
// indent-tabs-mode: nil
40+
// c-basic-offset: 4
41+
// buffer-file-coding-system: utf-8-unix
42+
// End:
43+
//

src/rt/rust_util.h

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "rust_task.h"
66
#include "rust_env.h"
77

8+
extern struct type_desc str_body_tydesc;
9+
810
// Inline fn used regularly elsewhere.
911

1012
static inline size_t
@@ -82,6 +84,7 @@ make_str(rust_kernel* kernel, const char* c, size_t strlen,
8284
size_t str_alloc = str_fill;
8385
rust_str *str = (rust_str *)
8486
kernel->malloc(vec_size<char>(str_fill), name);
87+
str->header.td = &str_body_tydesc;
8588
str->body.fill = str_fill;
8689
str->body.alloc = str_alloc;
8790
memcpy(&str->body.data, c, strlen);
@@ -94,6 +97,8 @@ make_str_vec(rust_kernel* kernel, size_t nstrs, char **strs) {
9497
rust_vec_box *v = (rust_vec_box *)
9598
kernel->malloc(vec_size<rust_vec_box*>(nstrs),
9699
"str vec interior");
100+
// FIXME: should have a real td (Issue #2639)
101+
v->header.td = NULL;
97102
v->body.fill = v->body.alloc = sizeof(rust_vec_box*) * nstrs;
98103
for (size_t i = 0; i < nstrs; ++i) {
99104
rust_str *str = make_str(kernel, strs[i],

0 commit comments

Comments
 (0)