diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/init.c | 8 | ||||
| -rw-r--r-- | src/kernel.c | 2 | ||||
| -rw-r--r-- | src/parse.y | 17 | ||||
| -rw-r--r-- | src/state.c | 25 | ||||
| -rw-r--r-- | src/string.c | 27 |
5 files changed, 35 insertions, 44 deletions
diff --git a/src/init.c b/src/init.c index c08c4b046..9489cea10 100644 --- a/src/init.c +++ b/src/init.c @@ -54,11 +54,3 @@ mrb_init_core(mrb_state *mrb) mrb_init_mrbgems(mrb); DONE; #endif } - -void -mrb_final_core(mrb_state *mrb) -{ -#ifndef DISABLE_GEMS - mrb_final_mrbgems(mrb); DONE; -#endif -} diff --git a/src/kernel.c b/src/kernel.c index f6f2872ea..0258e5c15 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1118,7 +1118,7 @@ mrb_init_kernel(mrb_state *mrb) mrb_define_class_method(mrb, krn, "iterator?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.2.5 */ mrb_define_class_method(mrb, krn, "local_variables", mrb_local_variables, MRB_ARGS_NONE()); /* 15.3.1.2.7 */ ; /* 15.3.1.2.11 */ - mrb_define_class_method(mrb, krn, "raise", mrb_f_raise, MRB_ARGS_ANY()); /* 15.3.1.2.12 */ + mrb_define_class_method(mrb, krn, "raise", mrb_f_raise, MRB_ARGS_OPT(2)); /* 15.3.1.2.12 */ mrb_define_method(mrb, krn, "singleton_class", mrb_singleton_class, MRB_ARGS_NONE()); diff --git a/src/parse.y b/src/parse.y index 93923aa71..1d4e83cde 100644 --- a/src/parse.y +++ b/src/parse.y @@ -42,11 +42,7 @@ static void yywarning(parser_state *p, const char *s); static void backref_error(parser_state *p, node *n); static void tokadd(parser_state *p, int32_t c); -#ifndef isascii -#define isascii(c) (((c) & ~0x7f) == 0) -#endif - -#define identchar(c) (isalnum(c) || (c) == '_' || !isascii(c)) +#define identchar(c) (ISALNUM(c) || (c) == '_' || !ISASCII(c)) typedef unsigned int stack_type; @@ -3911,7 +3907,8 @@ parse_string(parser_state *p) return tHD_LITERAL_DELIM; } } - } while (ISSPACE(c = nextc(p))); + c = nextc(p); + } while (ISSPACE(c)); pushback(p, c); return tLITERAL_DELIM; } @@ -4205,14 +4202,14 @@ parser_yylex(parser_state *p) static const char end[] = "\n=end"; if (peeks(p, begin)) { c = peekc_n(p, sizeof(begin)-1); - if (c < 0 || isspace(c)) { + if (c < 0 || ISSPACE(c)) { do { if (!skips(p, end)) { yyerror(p, "embedded document meets end of file"); return 0; } c = nextc(p); - } while (!(c < 0 || isspace(c))); + } while (!(c < 0 || ISSPACE(c))); if (c != '\n') skip(p, '\n'); p->lineno++; p->column = 0; @@ -4337,7 +4334,7 @@ parser_yylex(parser_state *p) yyerror(p, "incomplete character syntax"); return 0; } - if (isspace(c)) { + if (ISSPACE(c)) { if (!IS_ARG()) { int c2; switch (c) { @@ -5190,7 +5187,7 @@ parser_yylex(parser_state *p) pushback(p, c); } } - if (result == 0 && isupper((int)(unsigned char)tok(p)[0])) { + if (result == 0 && ISUPPER(tok(p)[0])) { result = tCONSTANT; } else { diff --git a/src/state.c b/src/state.c index 9dd798f92..ac9f88088 100644 --- a/src/state.c +++ b/src/state.c @@ -14,7 +14,6 @@ void mrb_init_heap(mrb_state*); void mrb_init_core(mrb_state*); -void mrb_final_core(mrb_state*); static mrb_value inspect_main(mrb_state *mrb, mrb_value mod) @@ -40,6 +39,7 @@ mrb_open_allocf(mrb_allocf f, void *ud) mrb->ud = ud; mrb->allocf = f; mrb->current_white_part = MRB_GC_WHITE_A; + mrb->atexit_stack_len = 0; #ifndef MRB_GC_FIXED_ARENA mrb->arena = (struct RBasic**)mrb_malloc(mrb, sizeof(struct RBasic*)*MRB_GC_ARENA_SIZE); @@ -221,7 +221,13 @@ mrb_free_context(mrb_state *mrb, struct mrb_context *c) void mrb_close(mrb_state *mrb) { - mrb_final_core(mrb); + if (mrb->atexit_stack_len > 0) { + mrb_int i; + for (i = mrb->atexit_stack_len; i > 0; --i) { + mrb->atexit_stack[i - 1](mrb); + } + mrb_free(mrb, mrb->atexit_stack); + } /* free */ mrb_gc_free_gv(mrb); @@ -258,3 +264,18 @@ mrb_top_self(mrb_state *mrb) } return mrb_obj_value(mrb->top_self); } + +void +mrb_atexit(mrb_state *mrb, mrb_atexit_func f) +{ + size_t stack_size; + + stack_size = sizeof(mrb_atexit_func) * (mrb->atexit_stack_len + 1); + if (mrb->atexit_stack_len == 0) { + mrb->atexit_stack = (mrb_atexit_func*)mrb_malloc(mrb, stack_size); + } else { + mrb->atexit_stack = (mrb_atexit_func*)mrb_realloc(mrb, mrb->atexit_stack, stack_size); + } + + mrb->atexit_stack[mrb->atexit_stack_len++] = f; +} diff --git a/src/string.c b/src/string.c index 1572cab14..842e83d76 100644 --- a/src/string.c +++ b/src/string.c @@ -1728,27 +1728,6 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) return mrb_nil_value(); } -static const char isspacetable[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -#define ascii_isspace(c) isspacetable[(unsigned char)(c)] - /* 15.2.10.5.35 */ /* @@ -1844,7 +1823,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) int ai = mrb_gc_arena_save(mrb); c = (unsigned char)*ptr++; if (skip) { - if (ascii_isspace(c)) { + if (ISSPACE(c)) { beg = ptr - bptr; } else { @@ -1853,7 +1832,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) if (lim_p && lim <= i) break; } } - else if (ascii_isspace(c)) { + else if (ISSPACE(c)) { mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, beg, end-beg)); mrb_gc_arena_restore(mrb, ai); skip = TRUE; @@ -2308,6 +2287,8 @@ mrb_str_upcase(mrb_state *mrb, mrb_value self) return str; } +#define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{')) + /* * call-seq: * str.dump -> new_str |
