Commit e73a0913 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge branch 'cubicdaiya-issues/scope_new_error_handlings'

parents c7fda223 05ede522
...@@ -128,7 +128,7 @@ mrb_class_outer_module(mrb_state *mrb, struct RClass *c) ...@@ -128,7 +128,7 @@ mrb_class_outer_module(mrb_state *mrb, struct RClass *c)
mrb_value outer; mrb_value outer;
outer = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__")); outer = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"));
if (mrb_nil_p(outer)) return 0; if (mrb_nil_p(outer)) return NULL;
return mrb_class_ptr(outer); return mrb_class_ptr(outer);
} }
...@@ -1030,7 +1030,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid) ...@@ -1030,7 +1030,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
} }
c = c->super; c = c->super;
} }
return 0; /* no method */ return NULL; /* no method */
} }
MRB_API struct RProc* MRB_API struct RProc*
...@@ -1295,7 +1295,7 @@ MRB_API struct RClass * ...@@ -1295,7 +1295,7 @@ MRB_API struct RClass *
mrb_class_real(struct RClass* cl) mrb_class_real(struct RClass* cl)
{ {
if (cl == 0) if (cl == 0)
return 0; return NULL;
while ((cl->tt == MRB_TT_SCLASS) || (cl->tt == MRB_TT_ICLASS)) { while ((cl->tt == MRB_TT_SCLASS) || (cl->tt == MRB_TT_ICLASS)) {
cl = cl->super; cl = cl->super;
} }
......
...@@ -85,6 +85,7 @@ static void gen_assignment(codegen_scope *s, node *node, int sp, int val); ...@@ -85,6 +85,7 @@ static void gen_assignment(codegen_scope *s, node *node, int sp, int val);
static void gen_vmassignment(codegen_scope *s, node *tree, int rhs, int val); static void gen_vmassignment(codegen_scope *s, node *tree, int rhs, int val);
static void codegen(codegen_scope *s, node *tree, int val); static void codegen(codegen_scope *s, node *tree, int val);
static void raise_error(codegen_scope *s, const char *msg);
static void static void
codegen_error(codegen_scope *s, const char *message) codegen_error(codegen_scope *s, const char *message)
...@@ -552,6 +553,10 @@ for_body(codegen_scope *s, node *tree) ...@@ -552,6 +553,10 @@ for_body(codegen_scope *s, node *tree)
codegen(s, tree->cdr->car, VAL); codegen(s, tree->cdr->car, VAL);
/* generate loop-block */ /* generate loop-block */
s = scope_new(s->mrb, s, NULL); s = scope_new(s->mrb, s, NULL);
if (s == NULL) {
raise_error(prev, "unexpected scope");
}
push(); /* push for a block parameter */ push(); /* push for a block parameter */
lp = loop_push(s, LOOP_FOR); lp = loop_push(s, LOOP_FOR);
...@@ -589,6 +594,10 @@ lambda_body(codegen_scope *s, node *tree, int blk) ...@@ -589,6 +594,10 @@ lambda_body(codegen_scope *s, node *tree, int blk)
mrb_code c; mrb_code c;
codegen_scope *parent = s; codegen_scope *parent = s;
s = scope_new(s->mrb, s, tree->car); s = scope_new(s->mrb, s, tree->car);
if (s == NULL) {
raise_error(parent, "unexpected scope");
}
s->mscope = !blk; s->mscope = !blk;
if (blk) { if (blk) {
...@@ -674,6 +683,9 @@ static int ...@@ -674,6 +683,9 @@ static int
scope_body(codegen_scope *s, node *tree, int val) scope_body(codegen_scope *s, node *tree, int val)
{ {
codegen_scope *scope = scope_new(s->mrb, s, tree->car); codegen_scope *scope = scope_new(s->mrb, s, tree->car);
if (scope == NULL) {
raise_error(s, "unexpected scope");
}
codegen(scope, tree->cdr, VAL); codegen(scope, tree->cdr, VAL);
if (!s->iseq) { if (!s->iseq) {
...@@ -2470,7 +2482,7 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv) ...@@ -2470,7 +2482,7 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
mrb_pool *pool = mrb_pool_open(mrb); mrb_pool *pool = mrb_pool_open(mrb);
codegen_scope *p = (codegen_scope *)mrb_pool_alloc(pool, sizeof(codegen_scope)); codegen_scope *p = (codegen_scope *)mrb_pool_alloc(pool, sizeof(codegen_scope));
if (!p) return 0; if (!p) return NULL;
*p = codegen_scope_zero; *p = codegen_scope_zero;
p->mrb = mrb; p->mrb = mrb;
p->mpool = pool; p->mpool = pool;
......
...@@ -164,11 +164,18 @@ read_irep_record(mrb_state *mrb, const uint8_t *bin, size_t *len, mrb_bool alloc ...@@ -164,11 +164,18 @@ read_irep_record(mrb_state *mrb, const uint8_t *bin, size_t *len, mrb_bool alloc
mrb_irep *irep = read_irep_record_1(mrb, bin, len, alloc); mrb_irep *irep = read_irep_record_1(mrb, bin, len, alloc);
size_t i; size_t i;
if (irep == NULL) {
return NULL;
}
bin += *len; bin += *len;
for (i=0; i<irep->rlen; i++) { for (i=0; i<irep->rlen; i++) {
size_t rlen; size_t rlen;
irep->reps[i] = read_irep_record(mrb, bin, &rlen, alloc); irep->reps[i] = read_irep_record(mrb, bin, &rlen, alloc);
if (irep->reps[i] == NULL) {
return NULL;
}
bin += rlen; bin += rlen;
*len += rlen; *len += rlen;
} }
......
...@@ -5365,9 +5365,9 @@ mrb_parser_new(mrb_state *mrb) ...@@ -5365,9 +5365,9 @@ mrb_parser_new(mrb_state *mrb)
static const parser_state parser_state_zero = { 0 }; static const parser_state parser_state_zero = { 0 };
pool = mrb_pool_open(mrb); pool = mrb_pool_open(mrb);
if (!pool) return 0; if (!pool) return NULL;
p = (parser_state *)mrb_pool_alloc(pool, sizeof(parser_state)); p = (parser_state *)mrb_pool_alloc(pool, sizeof(parser_state));
if (!p) return 0; if (!p) return NULL;
*p = parser_state_zero; *p = parser_state_zero;
p->mrb = mrb; p->mrb = mrb;
...@@ -5483,7 +5483,7 @@ mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c) ...@@ -5483,7 +5483,7 @@ mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c)
parser_state *p; parser_state *p;
p = mrb_parser_new(mrb); p = mrb_parser_new(mrb);
if (!p) return 0; if (!p) return NULL;
p->s = p->send = NULL; p->s = p->send = NULL;
p->f = f; p->f = f;
...@@ -5498,7 +5498,7 @@ mrb_parse_nstring(mrb_state *mrb, const char *s, int len, mrbc_context *c) ...@@ -5498,7 +5498,7 @@ mrb_parse_nstring(mrb_state *mrb, const char *s, int len, mrbc_context *c)
parser_state *p; parser_state *p;
p = mrb_parser_new(mrb); p = mrb_parser_new(mrb);
if (!p) return 0; if (!p) return NULL;
p->s = s; p->s = s;
p->send = s + len; p->send = s + len;
......
...@@ -166,6 +166,9 @@ mrb_pool_realloc(mrb_pool *pool, void *p, size_t oldlen, size_t newlen) ...@@ -166,6 +166,9 @@ mrb_pool_realloc(mrb_pool *pool, void *p, size_t oldlen, size_t newlen)
page = page->next; page = page->next;
} }
np = mrb_pool_alloc(pool, newlen); np = mrb_pool_alloc(pool, newlen);
if (np == NULL) {
return NULL;
}
memcpy(np, p, oldlen); memcpy(np, p, oldlen);
return np; return np;
} }
......
...@@ -110,6 +110,10 @@ mrb_open_allocf(mrb_allocf f, void *ud) ...@@ -110,6 +110,10 @@ mrb_open_allocf(mrb_allocf f, void *ud)
{ {
mrb_state *mrb = mrb_open_core(f, ud); mrb_state *mrb = mrb_open_core(f, ud);
if (mrb == NULL) {
return NULL;
}
#ifndef DISABLE_GEMS #ifndef DISABLE_GEMS
mrb_init_mrbgems(mrb); mrb_init_mrbgems(mrb);
mrb_gc_arena_restore(mrb, 0); mrb_gc_arena_restore(mrb, 0);
......
...@@ -183,6 +183,7 @@ module MRuby ...@@ -183,6 +183,7 @@ module MRuby
def print_gem_test_header(f) def print_gem_test_header(f)
print_gem_comment(f) print_gem_comment(f)
f.puts %Q[#include <stdio.h>]
f.puts %Q[#include <stdlib.h>] f.puts %Q[#include <stdlib.h>]
f.puts %Q[#include "mruby.h"] f.puts %Q[#include "mruby.h"]
f.puts %Q[#include "mruby/irep.h"] f.puts %Q[#include "mruby/irep.h"]
......
...@@ -47,6 +47,10 @@ MRuby.each_target do ...@@ -47,6 +47,10 @@ MRuby.each_target do
g.test_rbfiles.count.times do |i| g.test_rbfiles.count.times do |i|
f.puts %Q[ ai = mrb_gc_arena_save(mrb);] f.puts %Q[ ai = mrb_gc_arena_save(mrb);]
f.puts %Q[ mrb2 = mrb_open_core(mrb_default_allocf, NULL);] f.puts %Q[ mrb2 = mrb_open_core(mrb_default_allocf, NULL);]
f.puts %Q[ if (mrb2 == NULL) {]
f.puts %Q[ fprintf(stderr, "Invalid mrb_state, exiting \%s", __FUNCTION__);]
f.puts %Q[ exit(EXIT_FAILURE);]
f.puts %Q[ }]
dep_list.each do |d| dep_list.each do |d|
f.puts %Q[ GENERATED_TMP_mrb_#{d.funcname}_gem_init(mrb2);] f.puts %Q[ GENERATED_TMP_mrb_#{d.funcname}_gem_init(mrb2);]
f.puts %Q[ mrb_state_atexit(mrb2, GENERATED_TMP_mrb_#{d.funcname}_gem_final);] f.puts %Q[ mrb_state_atexit(mrb2, GENERATED_TMP_mrb_#{d.funcname}_gem_final);]
......
...@@ -18,6 +18,10 @@ mrb_init_mrbtest(mrb_state *mrb) ...@@ -18,6 +18,10 @@ mrb_init_mrbtest(mrb_state *mrb)
mrb_load_irep(mrb, mrbtest_assert_irep); mrb_load_irep(mrb, mrbtest_assert_irep);
core_test = mrb_open_core(mrb_default_allocf, NULL); core_test = mrb_open_core(mrb_default_allocf, NULL);
if (core_test == NULL) {
fprintf(stderr, "Invalid mrb_state, exiting %s", __FUNCTION__);
exit(EXIT_FAILURE);
}
mrb_init_test_driver(core_test, mrb_test(mrb_gv_get(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose")))); mrb_init_test_driver(core_test, mrb_test(mrb_gv_get(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"))));
mrb_load_irep(core_test, mrbtest_assert_irep); mrb_load_irep(core_test, mrbtest_assert_irep);
mrb_load_irep(core_test, mrbtest_irep); mrb_load_irep(core_test, mrbtest_irep);
......
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