diff options
author | HASUMI Hitoshi <[email protected]> | 2024-04-26 21:43:35 +0900 |
---|---|---|
committer | Yuichiro Kaneko <[email protected]> | 2024-04-27 12:08:26 +0900 |
commit | 55a402bb759597487905a94d5b1bbff4a672499c (patch) | |
tree | 9a6309c61f0f6871de0d47c135d4270bb270dfc7 /node.c | |
parent | bf1f16ef47966e33401e5b9656a4ae4152dd1e60 (diff) |
Add line_count field to rb_ast_body_t
This patch adds `int line_count` field to `rb_ast_body_t` structure.
Instead, we no longer cast `script_lines` to Fixnum.
## Background
Ref https://github.com/ruby/ruby/pull/10618
In the PR above, we have decoupled IMEMO from `rb_ast_t`.
This means we could lift the five-words-restriction of the structure
that forced us to unionize `rb_ast_t *` and `FIXNUM` in one field.
## Relating refactor
- Remove the second parameter of `rb_ruby_ast_new()` function
## Attention
I will remove a code that assigns -1 to line_count, in `rb_binding_add_dynavars()`
of vm.c, because I don't think it is necessary.
But I will make another PR for this so that we can atomically revert
in case I was wrong (See the comment on the code)
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 15 |
1 files changed, 6 insertions, 9 deletions
@@ -340,6 +340,7 @@ iterate_node_values(rb_ast_t *ast, node_buffer_list_t *nb, node_itr_t * func, vo static void script_lines_free(rb_ast_t *ast, rb_parser_ary_t *script_lines) { + if (!script_lines) return; for (long i = 0; i < script_lines->len; i++) { parser_string_free(ast, (rb_parser_string_t *)script_lines->data[i]); } @@ -358,10 +359,8 @@ rb_ast_free(rb_ast_t *ast) #ifdef UNIVERSAL_PARSER if (ast && ast->node_buffer) { void (*free_func)(void *) = xfree; - if (ast->body.script_lines && !FIXNUM_P((VALUE)ast->body.script_lines)) { - script_lines_free(ast, ast->body.script_lines); - ast->body.script_lines = NULL; - } + script_lines_free(ast, ast->body.script_lines); + ast->body.script_lines = NULL; rb_node_buffer_free(ast, ast->node_buffer); ast->node_buffer = 0; free_func(ast); @@ -418,7 +417,7 @@ rb_ast_memsize(const rb_ast_t *ast) } } - if (script_lines && !FIXNUM_P((VALUE)script_lines)) { + if (script_lines) { size += sizeof(rb_parser_ary_t); for (i = 0; i < script_lines->len; i++) { size += sizeof(rb_parser_string_t); @@ -436,10 +435,8 @@ rb_ast_dispose(rb_ast_t *ast) // noop. See the comment in rb_ast_free(). #else if (ast && ast->node_buffer) { - if (ast->body.script_lines && !FIXNUM_P((VALUE)ast->body.script_lines)) { - script_lines_free(ast, ast->body.script_lines); - ast->body.script_lines = NULL; - } + script_lines_free(ast, ast->body.script_lines); + ast->body.script_lines = NULL; rb_node_buffer_free(ast, ast->node_buffer); ast->node_buffer = 0; } |