From a405b28e85cc48d2be24cf7baef528f646d3b212 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 13 Oct 2023 19:21:59 +0900 Subject: [PATCH] Delete heredoc line mark references --- node.c | 8 ++++++++ node.h | 1 + parse.y | 1 + ruby_parser.c | 1 + rubyparser.h | 1 + 5 files changed, 12 insertions(+) diff --git a/node.c b/node.c index 975ed9264f..f76e10e69b 100644 --- a/node.c +++ b/node.c @@ -93,6 +93,7 @@ rb_node_buffer_new(void) #define Qtrue ast->node_buffer->config->qtrue #define NIL_P ast->node_buffer->config->nil_p #define rb_hash_aset ast->node_buffer->config->hash_aset +#define rb_hash_delete ast->node_buffer->config->hash_delete #define RB_OBJ_WRITE(old, slot, young) ast->node_buffer->config->obj_write((VALUE)(old), (VALUE *)(slot), (VALUE)(young)) #endif @@ -458,6 +459,13 @@ rb_ast_add_mark_object(rb_ast_t *ast, VALUE obj) rb_hash_aset(ast->node_buffer->mark_hash, obj, Qtrue); } +void +rb_ast_delete_mark_object(rb_ast_t *ast, VALUE obj) +{ + if (NIL_P(ast->node_buffer->mark_hash)) return; + rb_hash_delete(ast->node_buffer->mark_hash, obj); +} + VALUE rb_ast_tokens(rb_ast_t *ast) { diff --git a/node.h b/node.h index a25c4599eb..d8d104975a 100644 --- a/node.h +++ b/node.h @@ -67,6 +67,7 @@ void rb_ast_mark(rb_ast_t*); void rb_ast_update_references(rb_ast_t*); void rb_ast_free(rb_ast_t*); void rb_ast_add_mark_object(rb_ast_t*, VALUE); +void rb_ast_delete_mark_object(rb_ast_t*, VALUE); void rb_ast_set_tokens(rb_ast_t*, VALUE); NODE *rb_ast_newnode(rb_ast_t*, enum node_type type, size_t size, size_t alignment); void rb_ast_delete_node(rb_ast_t*, NODE *n); diff --git a/parse.y b/parse.y index 1c2b11be86..86b24e49d3 100644 --- a/parse.y +++ b/parse.y @@ -8756,6 +8756,7 @@ heredoc_restore(struct parser_params *p, rb_strterm_heredoc_t *here) if (p->eofp) p->lex.nextline = Qnil; p->eofp = 0; xfree(term); + rb_ast_delete_mark_object(p->ast, line); } static int diff --git a/ruby_parser.c b/ruby_parser.c index 4ae92effb4..ba2c1e5d69 100644 --- a/ruby_parser.c +++ b/ruby_parser.c @@ -618,6 +618,7 @@ rb_parser_config_initialize(rb_parser_config_t *config) config->hash_new = rb_hash_new; config->hash_aset = rb_hash_aset; config->hash_lookup = rb_hash_lookup; + config->hash_delete = rb_hash_delete; config->ident_hash_new = rb_ident_hash_new; config->int2fix = int2fix; diff --git a/rubyparser.h b/rubyparser.h index da0be97db7..5805506831 100644 --- a/rubyparser.h +++ b/rubyparser.h @@ -1230,6 +1230,7 @@ typedef struct rb_parser_config_struct { VALUE (*hash_clear)(VALUE hash); VALUE (*hash_new)(void); VALUE (*hash_aset)(VALUE hash, VALUE key, VALUE val); + VALUE (*hash_delete)(VALUE hash, VALUE key); VALUE (*hash_lookup)(VALUE hash, VALUE key); VALUE (*ident_hash_new)(void);