From 1dcf59b3729c19430c472ce9d298248d41c63efb Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 26 Sep 2025 22:32:36 +0900 Subject: [PATCH] mruby-compiler: migrate NODE_ENSURE dump to variable-sized nodes Replace direct cons-list access (tree->car, tree->cdr->cdr) with proper accessor macros (ENSURE_NODE_BODY, ENSURE_NODE_ENSURE_CLAUSE) to support variable-sized node structures. Adds null checks for improved safety and follows the same pattern as other migrated nodes. Co-authored-by: Claude --- mrbgems/mruby-compiler/core/parse.y | 16 ++++++++++------ mrbgems/mruby-compiler/core/y.tab.c | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 7419f01f3..4567ba679 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -7962,12 +7962,16 @@ dump_node(mrb_state *mrb, node *tree, int offset) case NODE_ENSURE: printf("NODE_ENSURE:\n"); - dump_prefix(offset+1, lineno); - printf("body:\n"); - dump_node(mrb, tree->car, offset+2); - dump_prefix(offset+1, lineno); - printf("ensure:\n"); - dump_node(mrb, tree->cdr->cdr, offset+2); + if (ENSURE_NODE_BODY(tree)) { + dump_prefix(offset+1, lineno); + printf("body:\n"); + dump_node(mrb, ENSURE_NODE_BODY(tree), offset+2); + } + if (ENSURE_NODE_ENSURE_CLAUSE(tree)) { + dump_prefix(offset+1, lineno); + printf("ensure:\n"); + dump_node(mrb, ENSURE_NODE_ENSURE_CLAUSE(tree), offset+2); + } break; case NODE_LAMBDA: diff --git a/mrbgems/mruby-compiler/core/y.tab.c b/mrbgems/mruby-compiler/core/y.tab.c index 4a034b016..96421696e 100644 --- a/mrbgems/mruby-compiler/core/y.tab.c +++ b/mrbgems/mruby-compiler/core/y.tab.c @@ -14791,12 +14791,16 @@ dump_node(mrb_state *mrb, node *tree, int offset) case NODE_ENSURE: printf("NODE_ENSURE:\n"); - dump_prefix(offset+1, lineno); - printf("body:\n"); - dump_node(mrb, tree->car, offset+2); - dump_prefix(offset+1, lineno); - printf("ensure:\n"); - dump_node(mrb, tree->cdr->cdr, offset+2); + if (ENSURE_NODE_BODY(tree)) { + dump_prefix(offset+1, lineno); + printf("body:\n"); + dump_node(mrb, ENSURE_NODE_BODY(tree), offset+2); + } + if (ENSURE_NODE_ENSURE_CLAUSE(tree)) { + dump_prefix(offset+1, lineno); + printf("ensure:\n"); + dump_node(mrb, ENSURE_NODE_ENSURE_CLAUSE(tree), offset+2); + } break; case NODE_LAMBDA: