From 110cdd82e025999e07a448577cc5191aed113ac8 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 2 Jun 2012 21:47:27 +0900 Subject: naming convention consistency for hash.h --- src/sprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sprintf.c') diff --git a/src/sprintf.c b/src/sprintf.c index 79bd101ad..296a7c73e 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -165,7 +165,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base) (mrb_raise(mrb, E_ARGUMENT_ERROR, "named%.*s after unnumbered(%d)", (len), (name), posarg), mrb_undef_value()) : \ posarg == -1 ? \ (mrb_raise(mrb, E_ARGUMENT_ERROR, "named%.*s after numbered", (len), (name)), mrb_undef_value()) : \ - (posarg = -2, mrb_hash_getWithDef(mrb, get_hash(mrb, &hash, argc, argv), id, mrb_undef_value()))) + (posarg = -2, mrb_hash_fetch(mrb, get_hash(mrb, &hash, argc, argv), id, mrb_undef_value()))) #define GETNUM(n, val) \ for (; p < end && ISDIGIT(*p); p++) {\ -- cgit v1.2.3 From e1e4ceb3e42dab35038a52d89064ca6378a08c7d Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 12 Jun 2012 17:46:38 +0900 Subject: Make sprintf/format optional. --- include/mrbconf.h | 3 +++ src/kernel.c | 2 ++ src/sprintf.c | 5 +++++ 3 files changed, 10 insertions(+) (limited to 'src/sprintf.c') diff --git a/include/mrbconf.h b/include/mrbconf.h index 5a54ebeef..f2b23258e 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -34,6 +34,9 @@ typedef intptr_t mrb_sym; # define INCLUDE_ENCODING /* Regexp depends Encoding */ #endif +//#undef INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method. */ +#define INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method. */ + #ifdef MRUBY_DEBUG_BUILD # define PARSER_DUMP #endif diff --git a/src/kernel.c b/src/kernel.c index 15a4158a4..bc8e0059b 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1425,8 +1425,10 @@ mrb_init_kernel(mrb_state *mrb) mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, ARGS_ANY()); /* 15.3.1.3.45 */ mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, ARGS_NONE()); /* 15.3.1.3.46 */ +#ifdef INCLUDE_KERNEL_SPRINTF mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ mrb_define_method(mrb, krn, "format", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ +#endif mrb_include_module(mrb, mrb->object_class, mrb->kernel_module); } diff --git a/src/sprintf.c b/src/sprintf.c index 296a7c73e..c7e7badc4 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -5,6 +5,9 @@ */ #include "mruby.h" + +#ifdef INCLUDE_KERNEL_SPRINTF + #include #include #include "encoding.h" @@ -1078,3 +1081,5 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) *buf++ = c; *buf = '\0'; } + +#endif //INCLUDE_KERNEL_SPRINTF -- cgit v1.2.3 From d8e0fbab51c3e0b4ecd0a0faa3a7c55bcf3ffb09 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 19 Jun 2012 09:45:58 +0900 Subject: forgot to replace INLCUDE_KERNEL_SPRINTF by ENABLE_KERNEL_SPRINTF --- src/kernel.c | 2 +- src/sprintf.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/sprintf.c') diff --git a/src/kernel.c b/src/kernel.c index 6dfe6be19..a38e88f47 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1354,7 +1354,7 @@ mrb_init_kernel(mrb_state *mrb) mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, ARGS_ANY()); /* 15.3.1.3.45 */ mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, ARGS_NONE()); /* 15.3.1.3.46 */ -#ifdef INCLUDE_KERNEL_SPRINTF +#ifdef ENABLE_KERNEL_SPRINTF mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ mrb_define_method(mrb, krn, "format", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ #endif diff --git a/src/sprintf.c b/src/sprintf.c index c7e7badc4..b4d460c83 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -6,7 +6,7 @@ #include "mruby.h" -#ifdef INCLUDE_KERNEL_SPRINTF +#ifdef ENABLE_KERNEL_SPRINTF #include #include @@ -1082,4 +1082,4 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) *buf = '\0'; } -#endif //INCLUDE_KERNEL_SPRINTF +#endif /* ENABLE_KERNEL_SPRINTF */ -- cgit v1.2.3 From a70c4e0c790b9ddb4dbca143cffa585b3841b9f6 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 21 Jun 2012 16:22:29 +0900 Subject: reduce calling of strlen(); #301 --- src/codegen.c | 7 ++++--- src/dump.c | 8 +++++--- src/hash.c | 4 ++-- src/re.c | 19 +++++++++---------- src/sprintf.c | 8 ++++---- src/string.c | 2 +- 6 files changed, 25 insertions(+), 23 deletions(-) (limited to 'src/sprintf.c') diff --git a/src/codegen.c b/src/codegen.c index 3374b2e7f..27fd20ee4 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -542,16 +542,17 @@ nosplat(node *t) static mrb_sym attrsym(codegen_scope *s, mrb_sym a) { - const char *name = mrb_sym2name(s->mrb, a); + const char *name; + int len; char *name2; - size_t len = strlen(name); + name = mrb_sym2name(s->mrb, a, &len); name2 = codegen_palloc(s, len+1); strcpy(name2, name); name2[len] = '='; name2[len+1] = '\0'; - return mrb_intern(s->mrb, name2); + return mrb_intern2(s->mrb, name2, len+1); } static int diff --git a/src/dump.c b/src/dump.c index daf2868f1..e1ebe2027 100644 --- a/src/dump.c +++ b/src/dump.c @@ -415,15 +415,17 @@ write_syms_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) uint16_t nlen =0; if (irep->syms[sym_no] != 0) { - name = mrb_sym2name(mrb, irep->syms[sym_no]); - nlen = str_dump_len((char*)name, strlen(name), type); + int len; + + name = mrb_sym2name(mrb, irep->syms[sym_no], &len); + nlen = str_dump_len((char*)name, len, type); if ( nlen > buf_size - 1) { buf_size = nlen + 1; if ((char_buf = mrb_realloc(mrb, char_buf, buf_size)) == 0) goto error_exit; } memset(char_buf, 0, buf_size); - str_dump((char*)name, char_buf, strlen(name), type); + str_dump((char*)name, char_buf, len, type); buf += uint16_dump(nlen, buf, type); /* length of symbol name */ memcpy(buf, char_buf, nlen); /* symbol name */ diff --git a/src/hash.c b/src/hash.c index 08f906800..7b9ae6a8a 100644 --- a/src/hash.c +++ b/src/hash.c @@ -904,14 +904,14 @@ inspect_hash(mrb_state *mrb, mrb_value hash, int recur) str2 = mrb_inspect(mrb, kh_key(h,k)); mrb_str_append(mrb, str, str2); - mrb_str_buf_cat(mrb, str, "=>", strlen("=>")); + mrb_str_buf_cat(mrb, str, "=>", sizeof("=>")); str2 = mrb_inspect(mrb, kh_value(h,k)); mrb_str_append(mrb, str, str2); mrb_gc_arena_restore(mrb, ai); } } - mrb_str_buf_cat(mrb, str, "}", strlen("}"));//mrb_str_buf_cat2(str, "}"); + mrb_str_buf_cat(mrb, str, "}", sizeof("}")); return str; } diff --git a/src/re.c b/src/re.c index b821d2e71..12061eacf 100644 --- a/src/re.c +++ b/src/re.c @@ -357,14 +357,14 @@ mrb_reg_desc(mrb_state *mrb, const char *s, long len, mrb_value re) mrb_value str = mrb_str_new_cstr(mrb, "/");//mrb_str_buf_new2("/"); mrb_reg_expr_str(mrb, str, s, len); - mrb_str_buf_cat(mrb, str, "/", strlen("/")); + mrb_str_buf_cat(mrb, str, "/", sizeof("/")); if (re.tt) { char opts[4]; mrb_reg_check(mrb, re); if (*option_to_str(opts, RREGEXP(re)->ptr->options)) mrb_str_buf_cat(mrb, str, opts, strlen(opts));//mrb_str_buf_cat2(str, opts); if (RBASIC(re)->flags & REG_ENCODING_NONE) - mrb_str_buf_cat(mrb, str, "n", strlen("n"));//mrb_str_buf_cat2(str, "n"); + mrb_str_buf_cat(mrb, str, "n", sizeof("n")); } return str; @@ -1796,9 +1796,9 @@ again: mrb_str_buf_cat(mrb, str, optbuf, strlen(optbuf)); } - mrb_str_buf_cat(mrb, str, ":", strlen(":")); + mrb_str_buf_cat(mrb, str, ":", sizeof(":")); mrb_reg_expr_str(mrb, str, (char*)ptr, len); - mrb_str_buf_cat(mrb, str, ")", strlen(")")); + mrb_str_buf_cat(mrb, str, ")", sizeof(")")); return str; } @@ -1919,29 +1919,28 @@ mrb_match_inspect(mrb_state *mrb, mrb_value match) match_inspect_name_iter, names); str = mrb_str_new_cstr(mrb, "#<");//mrb_str_buf_new2("#<"); - mrb_str_buf_cat(mrb, str, cname, strlen(cname));//mrb_str_buf_cat2(str, cname); + mrb_str_buf_cat(mrb, str, cname, strlen(cname)); for (i = 0; i < num_regs; i++) { char buf[sizeof(num_regs)*3+1]; mrb_value v; - mrb_str_buf_cat(mrb, str, " ", strlen(" "));//mrb_str_buf_cat2(str, " "); + mrb_str_buf_cat(mrb, str, " ", sizeof(" ")); if (0 < i) { if (names[i].name) mrb_str_buf_cat(mrb, str, (const char*)names[i].name, names[i].len); else { - //mrb_str_catf(mrb, str, "%d", i); sprintf(buf, "%d", i); mrb_str_buf_cat(mrb, str, (const char*)buf, strlen(buf)); } - mrb_str_buf_cat(mrb, str, ":", strlen(":"));//mrb_str_buf_cat2(str, ":"); + mrb_str_buf_cat(mrb, str, ":", sizeof(":")); } v = mrb_reg_nth_match(mrb, i, match); if (mrb_nil_p(v)) - mrb_str_buf_cat(mrb, str, "nil", strlen("nil"));//mrb_str_buf_cat2(str, "nil"); + mrb_str_buf_cat(mrb, str, "nil", sizeof("nil")); else mrb_str_buf_append(mrb, str, mrb_str_inspect(mrb, v)); } - mrb_str_buf_cat(mrb, str, ">", strlen(">"));//mrb_str_buf_cat2(str, ">"); + mrb_str_buf_cat(mrb, str, ">", sizeof(">")); return str; } diff --git a/src/sprintf.c b/src/sprintf.c index b4d460c83..c23969792 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -1069,13 +1069,13 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) if (flags & FSPACE) *buf++ = ' '; if (flags & FWIDTH) { - snprintf(buf, end - buf, "%d", width); - buf += strlen(buf); + snprintf(buf, end - buf, "%d", width); + buf += strlen(buf); } if (flags & FPREC) { - snprintf(buf, end - buf, ".%d", prec); - buf += strlen(buf); + snprintf(buf, end - buf, ".%d", prec); + buf += strlen(buf); } *buf++ = c; diff --git a/src/string.c b/src/string.c index 585edf8a3..894342463 100644 --- a/src/string.c +++ b/src/string.c @@ -2987,7 +2987,7 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str) continue; } } - mrb_str_buf_cat(mrb, result, "\"", strlen("\"")); + mrb_str_buf_cat(mrb, result, "\"", sizeof("\"")); return result; } -- cgit v1.2.3 From 21f2e5364b5c6cda244001d779aa67d86a22e6e7 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 22 Jun 2012 16:46:37 +0900 Subject: Use mrb_str_new() instead of mrb_str_new2() as possible. --- src/array.c | 4 ++-- src/numeric.c | 23 +++++++++++++++-------- src/range.c | 7 ++++++- src/sprintf.c | 2 +- src/string.c | 7 +++++-- src/struct.c | 4 ++-- 6 files changed, 31 insertions(+), 16 deletions(-) (limited to 'src/sprintf.c') diff --git a/src/array.c b/src/array.c index ca111bc0e..981da7afb 100644 --- a/src/array.c +++ b/src/array.c @@ -887,7 +887,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list) /* check recursive */ for(i=0; i #include #include +#include #if defined(__FreeBSD__) && __FreeBSD__ < 4 #include @@ -186,15 +187,21 @@ static mrb_value flo_to_s(mrb_state *mrb, mrb_value flt) { char buf[32]; + int n; mrb_float value = mrb_float(flt); - if (isinf(value)) - return mrb_str_new2(mrb, value < 0 ? "-inf" : "inf"); - else if(isnan(value)) - return mrb_str_new2(mrb, "NaN"); - - sprintf(buf, "%.14g", value); - return mrb_str_new2(mrb, buf); + if (isinf(value)) { + static const char s[2][5] = { "-inf", "inf" }; + static const int n[] = { 4, 3 }; + int idx; + idx = (value < 0) ? 0 : 1; + return mrb_str_new(mrb, s[idx], n[idx]); + } else if(isnan(value)) + return mrb_str_new(mrb, "NaN", 3); + + n = sprintf(buf, "%.14g", value); + assert(n >= 0); + return mrb_str_new(mrb, buf, n); } /* 15.2.9.3.2 */ @@ -1158,7 +1165,7 @@ mrb_fix2str(mrb_state *mrb, mrb_value x, int base) mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid radix %d", base); } if (val == 0) { - return mrb_str_new2(mrb, "0"); + return mrb_str_new(mrb, "0", 1); } if (val < 0) { val = -val; diff --git a/src/range.c b/src/range.c index 826481e93..859bb277e 100644 --- a/src/range.c +++ b/src/range.c @@ -343,7 +343,12 @@ inspect_range(mrb_state *mrb, mrb_value range, mrb_value dummy, int recur) struct RRange *r = mrb_range_ptr(range); if (recur) { - return mrb_str_new2(mrb, r->excl ? "(... ... ...)" : "(... .. ...)"); + static const char s[2][14] = { "(... ... ...)", "(... .. ...)" }; + static const int n[] = { 13, 12 }; + int idx; + + idx = (r->excl) ? 0 : 1; + return mrb_str_new(mrb, s[idx], n[idx]); } str = mrb_inspect(mrb, r->edges->beg); str2 = mrb_inspect(mrb, r->edges->end); diff --git a/src/sprintf.c b/src/sprintf.c index c23969792..e01bf572e 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -89,7 +89,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base) val &= 0x3ff; if (val == 0) { - return mrb_str_new2(mrb, "0"); + return mrb_str_new(mrb, "0", 1); } *--b = '\0'; do { diff --git a/src/string.c b/src/string.c index 894342463..6b2df1590 100644 --- a/src/string.c +++ b/src/string.c @@ -21,6 +21,7 @@ #include "regex.h" #include "st.h" #endif //ENABLE_REGEXP +#include const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -220,7 +221,9 @@ mrb_str_buf_cat(mrb_state *mrb, mrb_value str, const char *ptr, int len) mrb_value mrb_str_new(mrb_state *mrb, const char *p, int len) { - struct RString *s = str_new(mrb, p, len); + struct RString *s; + assert(!(!p && len)); + s = str_new(mrb, p, len); return mrb_obj_value(s); } @@ -1969,7 +1972,7 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) if (regs->num_regs == 1) { return mrb_reg_nth_match(mrb, 0, match); } - result = mrb_ary_new_capa(mrb, regs->num_regs);//mrb_ary_new2(regs->num_regs); + result = mrb_ary_new_capa(mrb, regs->num_regs); for (i=1; i < regs->num_regs; i++) { mrb_ary_push(mrb, result, mrb_reg_nth_match(mrb, i, match)); } diff --git a/src/struct.c b/src/struct.c index de0dbeeaa..7e422f140 100644 --- a/src/struct.c +++ b/src/struct.c @@ -93,7 +93,7 @@ mrb_struct_s_members_m(mrb_state *mrb, mrb_value klass) mrb_value *p, *pend; members = mrb_struct_s_members(mrb, klass); - ary = mrb_ary_new_capa(mrb, RARRAY_LEN(members));//mrb_ary_new2(RARRAY_LEN(members)); + ary = mrb_ary_new_capa(mrb, RARRAY_LEN(members)); p = RARRAY_PTR(members); pend = p + RARRAY_LEN(members); while (p < pend) { mrb_ary_push(mrb, ary, *p); @@ -493,7 +493,7 @@ static mrb_value inspect_struct(mrb_state *mrb, mrb_value s, mrb_value dummy, int recur) { const char *cn = mrb_class_name(mrb, mrb_obj_class(mrb, s)); - mrb_value members, str = mrb_str_new2(mrb, "# Date: Sat, 23 Jun 2012 13:51:50 +0900 Subject: reduce calling mrb_str_new_cstr() to avoid strlen(); #301 --- src/class.c | 17 ++++++++++++----- src/codegen.c | 10 ++++++---- src/hash.c | 6 +++--- src/kernel.c | 2 +- src/object.c | 8 +++----- src/re.c | 13 +++++++------ src/sprintf.c | 10 ++++++---- src/string.c | 5 ++--- src/struct.c | 9 +++++---- src/time.c | 13 +++++++------ src/vm.c | 18 ++++++++++-------- 11 files changed, 62 insertions(+), 49 deletions(-) (limited to 'src/sprintf.c') diff --git a/src/class.c b/src/class.c index 56ab8c06f..a9bf54a3b 100644 --- a/src/class.c +++ b/src/class.c @@ -972,15 +972,23 @@ mrb_class_path(mrb_state *mrb, struct RClass *c) struct RClass *outer = mrb_class_outer_module(mrb, c); mrb_sym sym = class_sym(mrb, c, outer); if (outer && outer != mrb->object_class) { + char *name; + int len; + mrb_value base = mrb_class_path(mrb, outer); - path = mrb_str_plus(mrb, base, mrb_str_new_cstr(mrb, "::")); - mrb_str_concat(mrb, path, mrb_str_new_cstr(mrb, mrb_sym2name(mrb, sym))); + path = mrb_str_plus(mrb, base, mrb_str_new(mrb, "::", 2)); + name = mrb_sym2name_len(mrb, sym, &len); + mrb_str_concat(mrb, path, mrb_str_new(mrb, name, len)); } else if (sym == 0) { return mrb_nil_value(); } else { - path = mrb_str_new_cstr(mrb, mrb_sym2name(mrb, sym)); + char *name; + int len; + + name = mrb_sym2name_len(mrb, sym, &len); + path = mrb_str_new(mrb, name, len); } mrb_obj_iv_set(mrb, (struct RObject*)c, mrb_intern(mrb, "__classpath__"), path); } @@ -1114,9 +1122,8 @@ mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const static mrb_value mrb_mod_to_s(mrb_state *mrb, mrb_value klass) { - //if (FL_TEST(klass, FL_SINGLETON)) { if (mrb_type(klass) == MRB_TT_SCLASS) { - mrb_value s = mrb_str_new_cstr(mrb, "#<"); + mrb_value s = mrb_str_new(mrb, "#<", 2); mrb_value v = mrb_iv_get(mrb, klass, mrb_intern(mrb, "__attached__")); mrb_str_cat2(mrb, s, "Class:"); diff --git a/src/codegen.c b/src/codegen.c index 72fc1097d..cbf401a1f 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1534,10 +1534,11 @@ codegen(codegen_scope *s, node *tree, int val) case NODE_BACK_REF: { char buf[4]; + int len; int sym; - snprintf(buf, 3, "$%c", (int)(intptr_t)tree); - sym = new_sym(s, mrb_intern(s->mrb, buf)); + len = snprintf(buf, 3, "$%c", (int)(intptr_t)tree); + sym = new_sym(s, mrb_intern2(s->mrb, buf, len)); genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); push(); } @@ -1546,10 +1547,11 @@ codegen(codegen_scope *s, node *tree, int val) case NODE_NTH_REF: { char buf[4]; + int len; int sym; - snprintf(buf, 3, "$%d", (int)(intptr_t)tree); - sym = new_sym(s, mrb_intern(s->mrb, buf)); + len = snprintf(buf, 3, "$%d", (int)(intptr_t)tree); + sym = new_sym(s, mrb_intern2(s->mrb, buf, len)); genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); push(); } diff --git a/src/hash.c b/src/hash.c index 0e06cd246..a87ca97d4 100644 --- a/src/hash.c +++ b/src/hash.c @@ -889,9 +889,9 @@ inspect_hash(mrb_state *mrb, mrb_value hash, int recur) khash_t(ht) *h = RHASH_TBL(hash); khiter_t k; - if (recur) return mrb_str_new_cstr(mrb, "{...}"); + if (recur) return mrb_str_new(mrb, "{...}", 5); - str = mrb_str_new_cstr(mrb, "{"); + str = mrb_str_new(mrb, "{", 1); if (h && kh_size(h) > 0) { for (k = kh_begin(h); k != kh_end(h); k++) { int ai; @@ -934,7 +934,7 @@ mrb_hash_inspect(mrb_state *mrb, mrb_value hash) khash_t(ht) *h = RHASH_TBL(hash); if (!h || kh_size(h) == 0) - return mrb_str_new_cstr(mrb, "{}"); + return mrb_str_new(mrb, "{}", 2); return inspect_hash(mrb, hash, 0); } diff --git a/src/kernel.c b/src/kernel.c index 8f2b15378..8da112ee5 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -117,7 +117,7 @@ mrb_obj_inspect(mrb_state *mrb, mrb_value obj) return mrb_any_to_s(mrb, obj); } else if (mrb_nil_p(obj)) { - return mrb_str_new_cstr(mrb, "nil"); + return mrb_str_new(mrb, "nil", 3); } return mrb_funcall(mrb, obj, "to_s", 0, 0); } diff --git a/src/object.c b/src/object.c index a30e7c58a..eb63c1293 100644 --- a/src/object.c +++ b/src/object.c @@ -151,7 +151,7 @@ true_xor(mrb_state *mrb, mrb_value obj) static mrb_value true_to_s(mrb_state *mrb, mrb_value obj) { - return mrb_str_new_cstr(mrb, "true"); + return mrb_str_new(mrb, "true", 4); } /* 15.2.5.3.4 */ @@ -264,7 +264,7 @@ false_or(mrb_state *mrb, mrb_value obj) static mrb_value false_to_s(mrb_state *mrb, mrb_value obj) { - return mrb_str_new_cstr(mrb, "false"); + return mrb_str_new(mrb, "false", 5); } void @@ -462,9 +462,7 @@ mrb_any_to_s(mrb_state *mrb, mrb_value obj) len = strlen(cname)+6+16; str = mrb_str_new(mrb, 0, len); /* 6:tags 16:addr */ s = mrb_str_ptr(str); - // snprintf(RSTRING(str)->ptr, len+1, "#<%s:0x%lx>", cname, obj); - sprintf(s->ptr, "#<%s:0x%lx>", cname, (unsigned long)(obj.value.p)); - s->len = strlen(s->ptr); + s->len = sprintf(s->ptr, "#<%s:0x%lx>", cname, (unsigned long)(obj.value.p)); return str; } diff --git a/src/re.c b/src/re.c index 12061eacf..a7552de11 100644 --- a/src/re.c +++ b/src/re.c @@ -354,10 +354,10 @@ mrb_reg_options(mrb_state *mrb, mrb_value re) static mrb_value mrb_reg_desc(mrb_state *mrb, const char *s, long len, mrb_value re) { - mrb_value str = mrb_str_new_cstr(mrb, "/");//mrb_str_buf_new2("/"); + mrb_value str = mrb_str_new(mrb, "/", 1); mrb_reg_expr_str(mrb, str, s, len); - mrb_str_buf_cat(mrb, str, "/", sizeof("/")); + mrb_str_buf_cat(mrb, str, "/", 1); if (re.tt) { char opts[4]; mrb_reg_check(mrb, re); @@ -1688,9 +1688,10 @@ mrb_reg_expr_str(mrb_state *mrb, mrb_value str, const char *s, long len) } else if (!ISSPACE(c)) { char b[8]; + int n; - snprintf(b, sizeof(b), "\\x%02X", c); - mrb_str_buf_cat(mrb, str, b, 4); + n = snprintf(b, sizeof(b), "\\x%02X", c); + mrb_str_buf_cat(mrb, str, b, n); } else { mrb_str_buf_cat(mrb, str, p, 1); @@ -1728,7 +1729,7 @@ mrb_reg_to_s(mrb_state *mrb, mrb_value re) const int embeddable = ONIG_OPTION_MULTILINE|ONIG_OPTION_IGNORECASE|ONIG_OPTION_EXTEND; long len; const UChar* ptr; - mrb_value str = mrb_str_new_cstr(mrb, "(?"); + mrb_value str = mrb_str_new(mrb, "(?", 2); char optbuf[5]; mrb_encoding *enc = mrb_enc_get(mrb, re); @@ -1918,7 +1919,7 @@ mrb_match_inspect(mrb_state *mrb, mrb_value match) onig_foreach_name(regexp->ptr, match_inspect_name_iter, names); - str = mrb_str_new_cstr(mrb, "#<");//mrb_str_buf_new2("#<"); + str = mrb_str_new(mrb, "#<", 2); mrb_str_buf_cat(mrb, str, cname, strlen(cname)); for (i = 0; i < num_regs; i++) { diff --git a/src/sprintf.c b/src/sprintf.c index e01bf572e..56141e482 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -1061,6 +1061,8 @@ static void fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) { char *end = buf + size; + int n; + *buf++ = '%'; if (flags & FSHARP) *buf++ = '#'; if (flags & FPLUS) *buf++ = '+'; @@ -1069,13 +1071,13 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) if (flags & FSPACE) *buf++ = ' '; if (flags & FWIDTH) { - snprintf(buf, end - buf, "%d", width); - buf += strlen(buf); + n = snprintf(buf, end - buf, "%d", width); + buf += n; } if (flags & FPREC) { - snprintf(buf, end - buf, ".%d", prec); - buf += strlen(buf); + n = snprintf(buf, end - buf, ".%d", prec); + buf += n; } *buf++ = c; diff --git a/src/string.c b/src/string.c index a943512c7..1ef0cdc33 100644 --- a/src/string.c +++ b/src/string.c @@ -2517,6 +2517,7 @@ bad: printf("Integer"); return mrb_fixnum_value(0); } + char * mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr) { @@ -2535,10 +2536,8 @@ mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck) char *s; int len; - //StringValue(str); mrb_string_value(mrb, &str); if (badcheck) { - //s = StringValueCStr(str); s = mrb_string_value_cstr(mrb, &str); } else { @@ -2949,7 +2948,7 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str) { const char *p, *pend; char buf[CHAR_ESC_LEN + 1]; - mrb_value result = mrb_str_new_cstr(mrb, "\""); + mrb_value result = mrb_str_new(mrb, "\"", 1); p = RSTRING_PTR(str); pend = RSTRING_END(str); for (;p < pend; p++) { diff --git a/src/struct.c b/src/struct.c index 7e422f140..60a0edb5b 100644 --- a/src/struct.c +++ b/src/struct.c @@ -521,8 +521,11 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_value dummy, int recur) slot = ptr_members[i]; id = SYM2ID(slot); if (mrb_is_local_id(id) || mrb_is_const_id(id)) { - //mrb_str_append(str, mrb_id2str(id)); - mrb_str_append(mrb, str, mrb_str_new_cstr(mrb, mrb_sym2name(mrb, id))); + char *name; + int len; + + name = mrb_sym2name_len(mrb, id, &len); + mrb_str_append(mrb, str, mrb_str_new(mrb, name, len)); } else { mrb_str_append(mrb, str, mrb_inspect(mrb, slot)); @@ -804,9 +807,7 @@ mrb_init_struct(mrb_state *mrb) { struct RClass *st; st = mrb_define_class(mrb, "Struct", mrb->object_class); - //mrb_include_module(mrb_cStruct, rb_mEnumerable); - //mrb_undef_alloc_func(mrb_cStruct); mrb_define_class_method(mrb, st, "new", mrb_struct_s_def, ARGS_ANY()); /* 15.2.18.3.1 */ mrb_define_method(mrb, st, "==", mrb_struct_equal, ARGS_REQ(1)); /* 15.2.18.4.1 */ diff --git a/src/time.c b/src/time.c index 55060729b..28cc3c1a3 100644 --- a/src/time.c +++ b/src/time.c @@ -430,16 +430,17 @@ mrb_time_asctime(mrb_state *mrb, mrb_value self) struct mrb_time *tm; struct tm *d; char buf[256]; + int len; tm = mrb_get_datatype(mrb, self, &mrb_time_type); if (!tm) return mrb_nil_value(); d = &tm->datetime; - snprintf(buf, 256, "%s %s %02d %02d:%02d:%02d %s%d", - wday_names[d->tm_wday], mon_names[d->tm_mon], d->tm_mday, - d->tm_hour, d->tm_min, d->tm_sec, - tm->timezone == MRB_TIMEZONE_UTC ? "UTC " : "", - d->tm_year + 1900); - return mrb_str_new_cstr(mrb, buf); + len = snprintf(buf, 256, "%s %s %02d %02d:%02d:%02d %s%d", + wday_names[d->tm_wday], mon_names[d->tm_mon], d->tm_mday, + d->tm_hour, d->tm_min, d->tm_sec, + tm->timezone == MRB_TIMEZONE_UTC ? "UTC " : "", + d->tm_year + 1900); + return mrb_str_new(mrb, buf, len); } /* 15.2.19.7.6 */ diff --git a/src/vm.c b/src/vm.c index 04392891f..daba0acc6 100644 --- a/src/vm.c +++ b/src/vm.c @@ -292,10 +292,11 @@ static void localjump_error(mrb_state *mrb, const char *kind) { char buf[256]; + int len; mrb_value exc; - snprintf(buf, 256, "unexpected %s", kind); - exc = mrb_exc_new(mrb, E_LOCALJUMP_ERROR, buf, strlen(buf)); + len = snprintf(buf, 256, "unexpected %s", kind); + exc = mrb_exc_new(mrb, E_LOCALJUMP_ERROR, buf, len); mrb->exc = (struct RObject*)mrb_object(exc); } @@ -303,18 +304,19 @@ static void argnum_error(mrb_state *mrb, int num) { char buf[256]; + int len; mrb_value exc; if (mrb->ci->mid) { - snprintf(buf, 256, "'%s': wrong number of arguments (%d for %d)", - mrb_sym2name(mrb, mrb->ci->mid), - mrb->ci->argc, num); + len = snprintf(buf, 256, "'%s': wrong number of arguments (%d for %d)", + mrb_sym2name(mrb, mrb->ci->mid), + mrb->ci->argc, num); } else { - snprintf(buf, 256, "wrong number of arguments (%d for %d)", - mrb->ci->argc, num); + len = snprintf(buf, 256, "wrong number of arguments (%d for %d)", + mrb->ci->argc, num); } - exc = mrb_exc_new(mrb, E_ARGUMENT_ERROR, buf, strlen(buf)); + exc = mrb_exc_new(mrb, E_ARGUMENT_ERROR, buf, len); mrb->exc = (struct RObject*)mrb_object(exc); } -- cgit v1.2.3 From 19638ded7367520333caf1b070b221ea18e4c352 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 25 Jun 2012 17:30:12 +0900 Subject: use mrb_intern_str instead of mrb_intern if possible --- src/class.c | 2 +- src/sprintf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sprintf.c') diff --git a/src/class.c b/src/class.c index 16fb36617..cda7ce643 100644 --- a/src/class.c +++ b/src/class.c @@ -1226,7 +1226,7 @@ static mrb_sym mrb_sym_value(mrb_state *mrb, mrb_value val) { if(val.tt == MRB_TT_STRING) { - return mrb_intern(mrb, RSTRING_PTR(val)); + return mrb_intern_str(mrb, val); } else if(val.tt != MRB_TT_SYMBOL) { mrb_value obj = mrb_funcall(mrb, val, "inspect", 0); diff --git a/src/sprintf.c b/src/sprintf.c index 56141e482..86c3b66bc 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -613,7 +613,7 @@ retry: (int)(p - start + 1), start, mrb_sym2name(mrb, id)); } symname = mrb_str_new(mrb, start + 1, p - start - 1); - id = mrb_intern(mrb, RSTRING_PTR(symname)); + id = mrb_intern_str(mrb, symname); nextvalue = GETNAMEARG(mrb_symbol_value(id), start, (int)(p - start + 1)); if (UNDEF_P(nextvalue)) { mrb_raise(mrb, E_KEY_ERROR, "key%.*s not found", (int)(p - start + 1), start); -- cgit v1.2.3 From 6410cdf3bffcbbb3d97f0153720922242c4f800f Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 27 Jun 2012 01:13:21 +0900 Subject: do not undef config macros --- include/mrbconf.h | 12 ++++++------ src/kernel.c | 2 +- src/sprintf.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/sprintf.c') diff --git a/include/mrbconf.h b/include/mrbconf.h index 21b8fea18..f496c53d9 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -15,10 +15,10 @@ /* -DDISABLE_XXXX to change to drop the feature */ #define DISABLE_REGEXP /* regular expression classes */ -#undef DISABLE_KERNEL_SPRINTF /* Kernel.sprintf method */ -#undef DISABLE_MATH /* Math functions */ -#undef DISABLE_TIME /* Time class */ -#undef DISABLE_STRUCT /* Struct class */ +//#define DISABLE_SPRINTF /* Kernel.sprintf method */ +//#define DISABLE_MATH /* Math functions */ +//#define DISABLE_TIME /* Time class */ +//#define DISABLE_STRUCT /* Struct class */ #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ @@ -38,8 +38,8 @@ typedef intptr_t mrb_sym; #ifndef DISABLE_REGEXP #define ENABLE_REGEXP #endif -#ifndef DISABLE_KERNEL_SPRINTF -#define ENABLE_KERNEL_SPRINTF +#ifndef DISABLE_SPRINTF +#define ENABLE_SPRINTF #endif #ifndef DISABLE_MATH #define ENABLE_MATH diff --git a/src/kernel.c b/src/kernel.c index 5e17d4b5a..605b84124 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1168,7 +1168,7 @@ mrb_init_kernel(mrb_state *mrb) mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, ARGS_ANY()); /* 15.3.1.3.45 */ mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, ARGS_NONE()); /* 15.3.1.3.46 */ -#ifdef ENABLE_KERNEL_SPRINTF +#ifdef ENABLE_SPRINTF mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ mrb_define_method(mrb, krn, "format", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ #endif diff --git a/src/sprintf.c b/src/sprintf.c index 86c3b66bc..68addef89 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -6,7 +6,7 @@ #include "mruby.h" -#ifdef ENABLE_KERNEL_SPRINTF +#ifdef ENABLE_SPRINTF #include #include @@ -1084,4 +1084,4 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) *buf = '\0'; } -#endif /* ENABLE_KERNEL_SPRINTF */ +#endif /* ENABLE_SPRINTF */ -- cgit v1.2.3 From 6f9ed1c5b21ba6ef2230e15bd3b39535f2f7bde9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 27 Jun 2012 15:14:56 +0900 Subject: use return value from sprintf/snprintf --- src/class.c | 10 +++++----- src/re.c | 4 ++-- src/sprintf.c | 22 ++++++++++------------ src/string.c | 4 ++-- 4 files changed, 19 insertions(+), 21 deletions(-) (limited to 'src/sprintf.c') diff --git a/src/class.c b/src/class.c index 071d7aebe..02fe9512a 100644 --- a/src/class.c +++ b/src/class.c @@ -1141,25 +1141,25 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass) } else { struct RClass *c = mrb_class_ptr(klass); - const char *cn = mrb_class_name(mrb, c); + const char *cn = mrb_class_name(mrb, c); if (!cn) { char buf[256]; - + int n = 0; switch (mrb_type(klass)) { case MRB_TT_CLASS: - snprintf(buf, 256, "#", c); + n = snprintf(buf, 256, "#", c); break; case MRB_TT_MODULE: - snprintf(buf, 256, "#", c); + n = snprintf(buf, 256, "#", c); break; default: break; } - return mrb_str_dup(mrb, mrb_str_new_cstr(mrb, buf)); + return mrb_str_dup(mrb, mrb_str_new(mrb, buf, n)); } else { return mrb_str_dup(mrb, mrb_str_new_cstr(mrb, cn)); diff --git a/src/re.c b/src/re.c index a7552de11..c7b27eac2 100644 --- a/src/re.c +++ b/src/re.c @@ -1930,8 +1930,8 @@ mrb_match_inspect(mrb_state *mrb, mrb_value match) if (names[i].name) mrb_str_buf_cat(mrb, str, (const char*)names[i].name, names[i].len); else { - sprintf(buf, "%d", i); - mrb_str_buf_cat(mrb, str, (const char*)buf, strlen(buf)); + int n = sprintf(buf, "%d", i); + mrb_str_buf_cat(mrb, str, (const char*)buf, n); } mrb_str_buf_cat(mrb, str, ":", sizeof(":")); } diff --git a/src/sprintf.c b/src/sprintf.c index 68addef89..d6104ad48 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -496,7 +496,7 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt) char *buf; long blen, bsiz; mrb_value result; - + int n; int width, prec, flags = FNONE; int nextarg = 1; int posarg = 0; @@ -533,7 +533,6 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt) for (; p < end; p++) { const char *t; - int n; mrb_sym id = 0; for (t = p; t < end && *t != '%'; t++) ; @@ -669,7 +668,6 @@ retry: mrb_value val = GETARG(); mrb_value tmp; unsigned int c; - int n; tmp = mrb_check_string_type(mrb, val); if (!mrb_nil_p(tmp)) { @@ -984,6 +982,7 @@ bin_retry: fval = mrb_float(mrb_Float(mrb, val)); if (isnan(fval) || isinf(fval)) { const char *expr; + const int elen = 3; if (isnan(fval)) { expr = "NaN"; @@ -991,14 +990,14 @@ bin_retry: else { expr = "Inf"; } - need = (int)strlen(expr); + need = elen; if ((!isnan(fval) && fval < 0.0) || (flags & FPLUS)) need++; if ((flags & FWIDTH) && need < width) need = width; CHECK(need + 1); - snprintf(&buf[blen], need + 1, "%*s", need, ""); + n = snprintf(&buf[blen], need + 1, "%*s", need, ""); if (flags & FMINUS) { if (!isnan(fval) && fval < 0.0) buf[blen++] = '-'; @@ -1006,17 +1005,16 @@ bin_retry: buf[blen++] = '+'; else if (flags & FSPACE) blen++; - memcpy(&buf[blen], expr, strlen(expr)); + memcpy(&buf[blen], expr, elen); } else { if (!isnan(fval) && fval < 0.0) - buf[blen + need - strlen(expr) - 1] = '-'; + buf[blen + need - elen - 1] = '-'; else if (flags & FPLUS) - buf[blen + need - strlen(expr) - 1] = '+'; + buf[blen + need - elen - 1] = '+'; else if ((flags & FSPACE) && need > width) blen++; - memcpy(&buf[blen + need - strlen(expr)], expr, - strlen(expr)); + memcpy(&buf[blen + need - elen], expr, elen); } blen += strlen(&buf[blen]); break; @@ -1036,8 +1034,8 @@ bin_retry: need += 20; CHECK(need); - snprintf(&buf[blen], need, fbuf, fval); - blen += strlen(&buf[blen]); + n = snprintf(&buf[blen], need, fbuf, fval); + blen += n; } break; } diff --git a/src/string.c b/src/string.c index c74dcedde..f01c08bce 100644 --- a/src/string.c +++ b/src/string.c @@ -2983,8 +2983,8 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str) continue; } else { - sprintf(buf, "\\%03o", c & 0377); - mrb_str_buf_cat(mrb, result, buf, strlen(buf)); + int n = sprintf(buf, "\\%03o", c & 0377); + mrb_str_buf_cat(mrb, result, buf, n); continue; } } -- cgit v1.2.3 From e3806922245c15ff9417ca4513c9052ebfa40021 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 14 Jul 2012 07:38:43 +0900 Subject: mrb_load_xxx to return undef + mrb_undef_p --- include/mruby.h | 2 +- src/kernel.c | 2 +- src/parse.y | 6 +++--- src/sprintf.c | 8 ++++---- tools/mrbc/mrbc.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/sprintf.c') diff --git a/include/mruby.h b/include/mruby.h index a9027d896..1124ba89c 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -81,7 +81,7 @@ typedef struct mrb_value { #define mrb_symbol(o) (o).value.sym #define mrb_object(o) ((struct RBasic *) (o).value.p) #define FIXNUM_P(o) ((o).tt == MRB_TT_FIXNUM) -#define UNDEF_P(o) ((o).tt == MRB_TT_UNDEF) +#define mrb_undef_p(o) ((o).tt == MRB_TT_UNDEF) #include "mruby/object.h" diff --git a/src/kernel.c b/src/kernel.c index 1040dbe05..240c0dcb3 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1038,7 +1038,7 @@ mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "n", &sym); val = mrb_iv_remove(mrb, self, sym); - if (UNDEF_P(val)) { + if (mrb_undef_p(val)) { mrb_name_error(mrb, sym, "instance variable %s not defined", mrb_sym2name(mrb, sym)); } return val; diff --git a/src/parse.y b/src/parse.y index 5a22b3883..40960e313 100644 --- a/src/parse.y +++ b/src/parse.y @@ -4874,7 +4874,7 @@ load_exec(mrb_state *mrb, parser_state *p, mrbc_context *c) if (!p) { mrb_parser_free(p); - return mrb_nil_value(); + return mrb_undef_value(); } if (p->capture_errors && (!p->tree || p->nerr)) { char buf[256]; @@ -4883,13 +4883,13 @@ load_exec(mrb_state *mrb, parser_state *p, mrbc_context *c) p->error_buffer[0].lineno, p->error_buffer[0].message); mrb->exc = (struct RObject*)mrb_object(mrb_exc_new(mrb, E_SYNTAX_ERROR, buf, n)); mrb_parser_free(p); - return mrb_nil_value(); + return mrb_undef_value(); } n = mrb_generate_code(mrb, p->tree); mrb_parser_free(p); if (n < 0) { mrb->exc = (struct RObject*)mrb_object(mrb_exc_new(mrb, E_SCRIPT_ERROR, "codegen error", 13)); - return mrb_nil_value(); + return mrb_undef_value(); } if (c) { if (c->dump_result) codedump_all(mrb, n); diff --git a/src/sprintf.c b/src/sprintf.c index d6104ad48..b597ff343 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -145,7 +145,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base) blen += (l);\ } while (0) -#define GETARG() (!UNDEF_P(nextvalue) ? nextvalue : \ +#define GETARG() (!mrb_undef_p(nextvalue) ? nextvalue : \ posarg == -1 ? \ (mrb_raise(mrb, E_ARGUMENT_ERROR, "unnumbered(%d) mixed with numbered", nextarg), mrb_undef_value()) : \ posarg == -2 ? \ @@ -201,7 +201,7 @@ get_hash(mrb_state *mrb, mrb_value *hash, int argc, const mrb_value *argv) { mrb_value tmp; - if (!UNDEF_P(*hash)) return *hash; + if (!mrb_undef_p(*hash)) return *hash; if (argc != 2) { mrb_raise(mrb, E_ARGUMENT_ERROR, "one hash required"); } @@ -586,7 +586,7 @@ retry: n = 0; GETNUM(n, width); if (*p == '$') { - if (!UNDEF_P(nextvalue)) { + if (!mrb_undef_p(nextvalue)) { mrb_raise(mrb, E_ARGUMENT_ERROR, "value given twice - %d$", n); } nextvalue = GETPOSARG(n); @@ -614,7 +614,7 @@ retry: symname = mrb_str_new(mrb, start + 1, p - start - 1); id = mrb_intern_str(mrb, symname); nextvalue = GETNAMEARG(mrb_symbol_value(id), start, (int)(p - start + 1)); - if (UNDEF_P(nextvalue)) { + if (mrb_undef_p(nextvalue)) { mrb_raise(mrb, E_KEY_ERROR, "key%.*s not found", (int)(p - start + 1), start); } if (term == '}') goto format_s; diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index a70353d63..a121eaa0e 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -179,7 +179,7 @@ main(int argc, char **argv) c->dump_result = 1; c->no_exec = 1; result = mrb_load_file_cxt(mrb, args.rfp, c); - if (mrb_nil_p(result)) { + if (mrb_undef_p(result)) { cleanup(&args); mrb_close(mrb); return -1; -- cgit v1.2.3 From 96366117ea4bd91bccf00110469765ebc1ebaa8c Mon Sep 17 00:00:00 2001 From: Junji Sawada Date: Sat, 14 Jul 2012 11:39:25 +0900 Subject: Remove unnecessary header inclusion --- include/mruby/khash.h | 1 - src/cdump.c | 1 - src/codegen.c | 3 --- src/error.c | 5 ----- src/gc.c | 3 +-- src/hash.c | 1 - src/kernel.c | 5 ----- src/numeric.c | 4 ---- src/proc.c | 1 - src/range.c | 3 --- src/sprintf.c | 1 - src/string.c | 3 +-- src/struct.c | 4 ---- src/symbol.c | 4 ---- src/variable.c | 2 -- 15 files changed, 2 insertions(+), 39 deletions(-) (limited to 'src/sprintf.c') diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 0803521b7..09b23f6af 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -12,7 +12,6 @@ extern "C" { #endif #include -#include #include typedef uint32_t khint_t; diff --git a/src/cdump.c b/src/cdump.c index 16c1dc8ae..a4a2ac5e1 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -10,7 +10,6 @@ #include "mruby/irep.h" #include "mruby/string.h" -#include "re.h" #define MRB_CDUMP_LINE_LEN 128 diff --git a/src/codegen.c b/src/codegen.c index 6db09f310..9166b7144 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -10,15 +10,12 @@ #include "mruby.h" #include "mruby/string.h" #include "mruby/irep.h" -#include "mruby/proc.h" #include "mruby/compile.h" #include "mruby/numeric.h" #include "opcode.h" #include "node.h" #include #include -#include -#include #include typedef mrb_ast_node node; diff --git a/src/error.c b/src/error.c index e46e37cbb..5bfbc4319 100644 --- a/src/error.c +++ b/src/error.c @@ -6,14 +6,9 @@ #include "mruby.h" #include -#include #include #include #include "error.h" -#include "opcode.h" -#include "mruby/irep.h" -#include "mruby/proc.h" -#include "mruby/numeric.h" #include "mruby/variable.h" #include "mruby/string.h" #include "mruby/class.h" diff --git a/src/gc.c b/src/gc.c index ada0bf31f..3c00bb015 100644 --- a/src/gc.c +++ b/src/gc.c @@ -11,12 +11,10 @@ #include "mruby/string.h" #include "mruby/hash.h" #include "mruby/range.h" -#include "mruby/khash.h" #include #include "mruby/struct.h" #include "mruby/proc.h" #include "mruby/data.h" -#include "mruby/numeric.h" #include "mruby/variable.h" /* @@ -101,6 +99,7 @@ typedef struct { } RVALUE; #ifdef GC_PROFILE +#include #include static double program_invoke_time = 0; diff --git a/src/hash.c b/src/hash.c index ed8b70270..dacef4713 100644 --- a/src/hash.c +++ b/src/hash.c @@ -11,7 +11,6 @@ #include "mruby/array.h" #include "mruby/string.h" #include "mruby/variable.h" -#include static inline khint_t mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) diff --git a/src/kernel.c b/src/kernel.c index 240c0dcb3..f5a1f3d53 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -6,14 +6,9 @@ #include "mruby.h" #include "mruby/string.h" -#include -#include #include "mruby/proc.h" -#include "mruby/range.h" #include "mruby/array.h" -#include "mruby/hash.h" #include "mruby/class.h" -#include "mruby/struct.h" #include "mruby/variable.h" #include "error.h" diff --git a/src/numeric.c b/src/numeric.c index 6638cf62c..ec3f97ca6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -8,11 +8,7 @@ #include "mruby/numeric.h" #include "mruby/string.h" #include "mruby/array.h" -#include -#include "mruby/class.h" -#include "mruby/variable.h" -#include #include #include #include diff --git a/src/proc.c b/src/proc.c index 98f753ac6..3e9bf1f67 100644 --- a/src/proc.c +++ b/src/proc.c @@ -6,7 +6,6 @@ #include "mruby.h" #include "mruby/proc.h" -#include "mruby/array.h" #include "mruby/class.h" #include "opcode.h" diff --git a/src/range.c b/src/range.c index 703ad12aa..b05836914 100644 --- a/src/range.c +++ b/src/range.c @@ -7,9 +7,6 @@ #include "mruby.h" #include "mruby/class.h" #include "mruby/range.h" -#include "mruby/variable.h" -#include "error.h" -#include "mruby/numeric.h" #include "mruby/string.h" #include diff --git a/src/sprintf.c b/src/sprintf.c index b597ff343..519e40b4b 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -15,7 +15,6 @@ #include "mruby/hash.h" #include "mruby/numeric.h" #include -#include #include #ifdef HAVE_IEEEFP_H diff --git a/src/string.c b/src/string.c index 14da83c51..e41116ebc 100644 --- a/src/string.c +++ b/src/string.c @@ -10,11 +10,10 @@ #include #include "mruby/string.h" #include -#include "mruby/numeric.h" +#include #include "mruby/range.h" #include "mruby/array.h" #include "mruby/class.h" -#include "mruby/variable.h" #include #ifdef ENABLE_REGEXP #include "re.h" diff --git a/src/struct.c b/src/struct.c index 25cd02d3d..6d8ce057f 100644 --- a/src/struct.c +++ b/src/struct.c @@ -17,13 +17,9 @@ #include "encoding.h" #endif -#include "mruby/numeric.h" -#include "mruby/hash.h" #include "mruby/string.h" #include "mruby/class.h" #include "mruby/variable.h" -#include "mruby/range.h" -#include "error.h" //#include "defines.h" #define mrb_long2int(n) ((int)(n)) diff --git a/src/symbol.c b/src/symbol.c index baab0fb3c..40484d4b5 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -8,12 +8,8 @@ #include "mruby/khash.h" #include -#include -#include #include "mruby/string.h" #include -#include "mruby/class.h" -#include "mruby/variable.h" /* ------------------------------------------------------ */ typedef struct symbol_name { diff --git a/src/variable.c b/src/variable.c index e2f3a7d08..be686bf72 100644 --- a/src/variable.c +++ b/src/variable.c @@ -8,8 +8,6 @@ #include "mruby/class.h" #include "mruby/khash.h" #include "mruby/variable.h" -#include "mruby/string.h" -#include "mruby/range.h" #include "error.h" #include "mruby/array.h" -- cgit v1.2.3