Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest mruby #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/cfunc_pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,11 @@ mrb_value
cfunc_pointer_to_s(mrb_state *mrb, mrb_value self)
{
struct cfunc_type_data *data = DATA_PTR(self);
size_t len;
mrb_value str;
struct RString *s;

const char* p = (const char*)get_cfunc_pointer_data(data);

len = strlen(p);
str = mrb_str_new(mrb, 0, len);
s = mrb_str_ptr(str);
strcpy(s->ptr, p);
s->len = strlen(s->ptr);

str = mrb_str_new_cstr(mrb, p);
return str;
}

Expand Down Expand Up @@ -252,8 +247,15 @@ cfunc_pointer_addr(mrb_state *mrb, mrb_value self)
static mrb_value
cfunc_string_addr(mrb_state *mrb, mrb_value self)
{
mrb_value ptr = cfunc_pointer_new_with_pointer(mrb, &RSTRING_PTR(self), false);
mrb_obj_iv_set(mrb, mrb_obj_ptr(ptr), mrb_intern_cstr(mrb, "parent_pointer"), self); // keep for GC
mrb_value ptr;

if (RSTRING(self)->flags & MRB_STR_EMBED) {
const char* p = RSTRING(self)->as.ary;
ptr = cfunc_pointer_new_with_pointer(mrb, &p, false);
} else {
ptr = cfunc_pointer_new_with_pointer(mrb, &(RSTRING(self)->as.heap.ptr), false);
}
mrb_obj_iv_set(mrb, mrb_obj_ptr(ptr), mrb_intern_cstr(mrb, "parent_pointer"), self); // keep for GC
return ptr;
}

Expand Down
7 changes: 3 additions & 4 deletions src/cfunc_rubyvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct task_arg* mrb_value_to_task_arg(mrb_state *mrb, mrb_value v)

case MRB_TT_SYMBOL:
{
size_t len;
mrb_int len;
const char* name = mrb_sym2name_len(mrb, v.value.sym, &len);
arg->value.string.len = len;
arg->value.string.ptr = mrb_malloc(mrb, len + 1);
Expand All @@ -89,10 +89,9 @@ struct task_arg* mrb_value_to_task_arg(mrb_state *mrb, mrb_value v)

case MRB_TT_STRING:
{
struct RString *str = mrb_str_ptr(v);
arg->value.string.len = str->len;
arg->value.string.len = RSTRING_LEN(v);
arg->value.string.ptr = mrb_malloc(mrb, arg->value.string.len+1);
memcpy(arg->value.string.ptr, str->ptr, arg->value.string.len+1);
memcpy(arg->value.string.ptr, RSTRING_PTR(v), arg->value.string.len+1);
}
break;

Expand Down