mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge branch 'cubicdaiya-issues/scope_new_error_handlings'
This commit is contained in:
+3
-3
@@ -128,7 +128,7 @@ mrb_class_outer_module(mrb_state *mrb, struct RClass *c)
|
||||
mrb_value 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);
|
||||
}
|
||||
|
||||
@@ -1030,7 +1030,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
|
||||
}
|
||||
c = c->super;
|
||||
}
|
||||
return 0; /* no method */
|
||||
return NULL; /* no method */
|
||||
}
|
||||
|
||||
MRB_API struct RProc*
|
||||
@@ -1295,7 +1295,7 @@ MRB_API struct RClass *
|
||||
mrb_class_real(struct RClass* cl)
|
||||
{
|
||||
if (cl == 0)
|
||||
return 0;
|
||||
return NULL;
|
||||
while ((cl->tt == MRB_TT_SCLASS) || (cl->tt == MRB_TT_ICLASS)) {
|
||||
cl = cl->super;
|
||||
}
|
||||
|
||||
+13
-1
@@ -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 codegen(codegen_scope *s, node *tree, int val);
|
||||
static void raise_error(codegen_scope *s, const char *msg);
|
||||
|
||||
static void
|
||||
codegen_error(codegen_scope *s, const char *message)
|
||||
@@ -552,6 +553,10 @@ for_body(codegen_scope *s, node *tree)
|
||||
codegen(s, tree->cdr->car, VAL);
|
||||
/* generate loop-block */
|
||||
s = scope_new(s->mrb, s, NULL);
|
||||
if (s == NULL) {
|
||||
raise_error(prev, "unexpected scope");
|
||||
}
|
||||
|
||||
push(); /* push for a block parameter */
|
||||
|
||||
lp = loop_push(s, LOOP_FOR);
|
||||
@@ -589,6 +594,10 @@ lambda_body(codegen_scope *s, node *tree, int blk)
|
||||
mrb_code c;
|
||||
codegen_scope *parent = s;
|
||||
s = scope_new(s->mrb, s, tree->car);
|
||||
if (s == NULL) {
|
||||
raise_error(parent, "unexpected scope");
|
||||
}
|
||||
|
||||
s->mscope = !blk;
|
||||
|
||||
if (blk) {
|
||||
@@ -674,6 +683,9 @@ static int
|
||||
scope_body(codegen_scope *s, node *tree, int val)
|
||||
{
|
||||
codegen_scope *scope = scope_new(s->mrb, s, tree->car);
|
||||
if (scope == NULL) {
|
||||
raise_error(s, "unexpected scope");
|
||||
}
|
||||
|
||||
codegen(scope, tree->cdr, VAL);
|
||||
if (!s->iseq) {
|
||||
@@ -2470,7 +2482,7 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
|
||||
mrb_pool *pool = mrb_pool_open(mrb);
|
||||
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->mrb = mrb;
|
||||
p->mpool = pool;
|
||||
|
||||
@@ -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);
|
||||
size_t i;
|
||||
|
||||
if (irep == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bin += *len;
|
||||
for (i=0; i<irep->rlen; i++) {
|
||||
size_t rlen;
|
||||
|
||||
irep->reps[i] = read_irep_record(mrb, bin, &rlen, alloc);
|
||||
if (irep->reps[i] == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
bin += rlen;
|
||||
*len += rlen;
|
||||
}
|
||||
|
||||
+4
-4
@@ -5365,9 +5365,9 @@ mrb_parser_new(mrb_state *mrb)
|
||||
static const parser_state parser_state_zero = { 0 };
|
||||
|
||||
pool = mrb_pool_open(mrb);
|
||||
if (!pool) return 0;
|
||||
if (!pool) return NULL;
|
||||
p = (parser_state *)mrb_pool_alloc(pool, sizeof(parser_state));
|
||||
if (!p) return 0;
|
||||
if (!p) return NULL;
|
||||
|
||||
*p = parser_state_zero;
|
||||
p->mrb = mrb;
|
||||
@@ -5483,7 +5483,7 @@ mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c)
|
||||
parser_state *p;
|
||||
|
||||
p = mrb_parser_new(mrb);
|
||||
if (!p) return 0;
|
||||
if (!p) return NULL;
|
||||
p->s = p->send = NULL;
|
||||
p->f = f;
|
||||
|
||||
@@ -5498,7 +5498,7 @@ mrb_parse_nstring(mrb_state *mrb, const char *s, int len, mrbc_context *c)
|
||||
parser_state *p;
|
||||
|
||||
p = mrb_parser_new(mrb);
|
||||
if (!p) return 0;
|
||||
if (!p) return NULL;
|
||||
p->s = s;
|
||||
p->send = s + len;
|
||||
|
||||
|
||||
@@ -166,6 +166,9 @@ mrb_pool_realloc(mrb_pool *pool, void *p, size_t oldlen, size_t newlen)
|
||||
page = page->next;
|
||||
}
|
||||
np = mrb_pool_alloc(pool, newlen);
|
||||
if (np == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(np, p, oldlen);
|
||||
return np;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,10 @@ mrb_open_allocf(mrb_allocf f, void *ud)
|
||||
{
|
||||
mrb_state *mrb = mrb_open_core(f, ud);
|
||||
|
||||
if (mrb == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_GEMS
|
||||
mrb_init_mrbgems(mrb);
|
||||
mrb_gc_arena_restore(mrb, 0);
|
||||
|
||||
@@ -183,6 +183,7 @@ module MRuby
|
||||
|
||||
def print_gem_test_header(f)
|
||||
print_gem_comment(f)
|
||||
f.puts %Q[#include <stdio.h>]
|
||||
f.puts %Q[#include <stdlib.h>]
|
||||
f.puts %Q[#include "mruby.h"]
|
||||
f.puts %Q[#include "mruby/irep.h"]
|
||||
|
||||
@@ -47,6 +47,10 @@ MRuby.each_target do
|
||||
g.test_rbfiles.count.times do |i|
|
||||
f.puts %Q[ ai = mrb_gc_arena_save(mrb);]
|
||||
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|
|
||||
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);]
|
||||
|
||||
@@ -18,6 +18,10 @@ mrb_init_mrbtest(mrb_state *mrb)
|
||||
mrb_load_irep(mrb, mrbtest_assert_irep);
|
||||
|
||||
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_load_irep(core_test, mrbtest_assert_irep);
|
||||
mrb_load_irep(core_test, mrbtest_irep);
|
||||
|
||||
Reference in New Issue
Block a user