mrubyを超漢字で動作させる
修订版 | d5dd3e94723fc7754aa5d478e0947479569c25dc (tree) |
---|---|
时间 | 2014-07-15 17:17:58 |
作者 | Yukihiro "Matz" Matsumoto <matz@ruby...> |
Commiter | Yukihiro "Matz" Matsumoto |
fiber stack allocation size should be bigger than irep->nregs
@@ -69,6 +69,7 @@ fiber_init(mrb_state *mrb, mrb_value self) | ||
69 | 69 | struct RProc *p; |
70 | 70 | mrb_callinfo *ci; |
71 | 71 | mrb_value blk; |
72 | + size_t slen; | |
72 | 73 | |
73 | 74 | mrb_get_args(mrb, "&", &blk); |
74 | 75 |
@@ -85,14 +86,18 @@ fiber_init(mrb_state *mrb, mrb_value self) | ||
85 | 86 | c = f->cxt; |
86 | 87 | |
87 | 88 | /* initialize VM stack */ |
88 | - c->stbase = (mrb_value *)mrb_malloc(mrb, FIBER_STACK_INIT_SIZE*sizeof(mrb_value)); | |
89 | - c->stend = c->stbase + FIBER_STACK_INIT_SIZE; | |
89 | + slen = FIBER_STACK_INIT_SIZE; | |
90 | + if (p->body.irep->nregs > slen) { | |
91 | + slen += p->body.irep->nregs; | |
92 | + } | |
93 | + c->stbase = (mrb_value *)mrb_malloc(mrb, slen*sizeof(mrb_value)); | |
94 | + c->stend = c->stbase + slen; | |
90 | 95 | c->stack = c->stbase; |
91 | 96 | |
92 | 97 | #ifdef MRB_NAN_BOXING |
93 | 98 | { |
94 | 99 | mrb_value *p = c->stbase; |
95 | - mrb_value *pend = p + FIBER_STACK_INIT_SIZE; | |
100 | + mrb_value *pend = c->stend; | |
96 | 101 | |
97 | 102 | while (p < pend) { |
98 | 103 | SET_NIL_VALUE(*p); |
@@ -100,7 +105,7 @@ fiber_init(mrb_state *mrb, mrb_value self) | ||
100 | 105 | } |
101 | 106 | } |
102 | 107 | #else |
103 | - memset(c->stbase, 0, FIBER_STACK_INIT_SIZE * sizeof(mrb_value)); | |
108 | + memset(c->stbase, 0, slen * sizeof(mrb_value)); | |
104 | 109 | #endif |
105 | 110 | |
106 | 111 | /* copy receiver from a block */ |