introduce mrb_str_new_lit() to create strings from C string litrals

parent 2e564153
......@@ -252,6 +252,7 @@ void mrb_free(mrb_state*, void*);
mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len);
mrb_value mrb_str_new_cstr(mrb_state*, const char*);
mrb_value mrb_str_new_static(mrb_state *mrb, const char *p, size_t len);
#define mrb_str_new_lit(mrb, lit) mrb_str_new_static(mrb, (lit), sizeof(lit) - 1)
mrb_state* mrb_open(void);
mrb_state* mrb_open_allocf(mrb_allocf, void *ud);
......
......@@ -34,7 +34,7 @@ static mrb_value
mrb_proc_inspect(mrb_state *mrb, mrb_value self)
{
struct RProc *p = mrb_proc_ptr(self);
mrb_value str = mrb_str_new_cstr(mrb, "#<Proc:");
mrb_value str = mrb_str_new_lit(mrb, "#<Proc:");
mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_cptr(self)));
if (!MRB_PROC_CFUNC_P(p)) {
......
......@@ -5,10 +5,10 @@
void
mrb_mruby_version_gem_init(mrb_state* mrb)
{
mrb_define_global_const(mrb, "MRUBY_VERSION", mrb_str_new_cstr(mrb, MRUBY_VERSION));
mrb_define_global_const(mrb, "MRUBY_RELEASE_DATE", mrb_str_new_cstr(mrb, MRUBY_RELEASE_DATE));
mrb_define_global_const(mrb, "MRUBY_DESCRIPTION", mrb_str_new_cstr(mrb, MRUBY_DESCRIPTION));
mrb_define_global_const(mrb, "MRUBY_COPYRIGHT", mrb_str_new_cstr(mrb, MRUBY_COPYRIGHT));
mrb_define_global_const(mrb, "MRUBY_VERSION", mrb_str_new_lit(mrb, MRUBY_VERSION));
mrb_define_global_const(mrb, "MRUBY_RELEASE_DATE", mrb_str_new_lit(mrb, MRUBY_RELEASE_DATE));
mrb_define_global_const(mrb, "MRUBY_DESCRIPTION", mrb_str_new_lit(mrb, MRUBY_DESCRIPTION));
mrb_define_global_const(mrb, "MRUBY_COPYRIGHT", mrb_str_new_lit(mrb, MRUBY_COPYRIGHT));
}
void
......
......@@ -1338,7 +1338,7 @@ test_mrb_field_write_barrier(void)
puts("test_mrb_field_write_barrier");
mrb->is_generational_gc_mode = FALSE;
obj = mrb_basic_ptr(mrb_ary_new(mrb));
value = mrb_basic_ptr(mrb_str_new_cstr(mrb, "value"));
value = mrb_basic_ptr(mrb_str_new_lit(mrb, "value"));
paint_black(obj);
paint_partial_white(mrb,value);
......@@ -1380,7 +1380,7 @@ test_mrb_field_write_barrier(void)
{
puts("test_mrb_field_write_barrier_value");
obj = mrb_basic_ptr(mrb_ary_new(mrb));
mrb_value value = mrb_str_new_cstr(mrb, "value");
mrb_value value = mrb_str_new_lit(mrb, "value");
paint_black(obj);
paint_partial_white(mrb, mrb_basic_ptr(value));
......@@ -1429,12 +1429,12 @@ test_add_gray_list(void)
puts("test_add_gray_list");
change_gen_gc_mode(mrb, FALSE);
mrb_assert(mrb->gray_list == NULL);
obj1 = mrb_basic_ptr(mrb_str_new_cstr(mrb, "test"));
obj1 = mrb_basic_ptr(mrb_str_new_lit(mrb, "test"));
add_gray_list(mrb, obj1);
mrb_assert(mrb->gray_list == obj1);
mrb_assert(is_gray(obj1));
obj2 = mrb_basic_ptr(mrb_str_new_cstr(mrb, "test"));
obj2 = mrb_basic_ptr(mrb_str_new_lit(mrb, "test"));
add_gray_list(mrb, obj2);
mrb_assert(mrb->gray_list == obj2);
mrb_assert(mrb->gray_list->gcnext == obj1);
......@@ -1462,7 +1462,7 @@ test_gc_gray_mark(void)
puts(" in MRB_TT_ARRAY");
obj_v = mrb_ary_new(mrb);
value_v = mrb_str_new_cstr(mrb, "test");
value_v = mrb_str_new_lit(mrb, "test");
paint_gray(mrb_basic_ptr(obj_v));
paint_partial_white(mrb, mrb_basic_ptr(value_v));
mrb_ary_push(mrb, obj_v, value_v);
......
......@@ -59,7 +59,7 @@ mrb_show_version(mrb_state *mrb)
if (mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), mrb_intern_lit(mrb, "MRUBY_DESCRIPTION"))) {
msg = mrb_const_get(mrb, mrb_obj_value(mrb->object_class), mrb_intern_lit(mrb, "MRUBY_DESCRIPTION"));
msg = mrb_funcall(mrb, msg, "+", 1, mrb_str_new_cstr(mrb, "\n"));
msg = mrb_funcall(mrb, msg, "+", 1, mrb_str_new_lit(mrb, "\n"));
}
else {
msg = mrb_str_new(mrb, version_msg, sizeof(version_msg) - 1);
......@@ -75,7 +75,7 @@ mrb_show_copyright(mrb_state *mrb)
if (mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), mrb_intern_lit(mrb, "MRUBY_COPYRIGHT"))) {
msg = mrb_const_get(mrb, mrb_obj_value(mrb->object_class), mrb_intern_lit(mrb, "MRUBY_COPYRIGHT"));
msg = mrb_funcall(mrb, msg, "+", 1, mrb_str_new_cstr(mrb, "\n"));
msg = mrb_funcall(mrb, msg, "+", 1, mrb_str_new_lit(mrb, "\n"));
}
else {
msg = mrb_str_new(mrb, copyright_msg, sizeof(copyright_msg) - 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment