The idiom `rb_gc_force_recycle((VALUE)...)` was used heavily.
This change defines `rb_discard_nod(NODE*)` and allows C compiler to
typecheck.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2017-10-24 06:27:58 +00:00
Родитель ac3bad418c
Коммит e1b6f0f529
1 изменённых файлов: 16 добавлений и 10 удалений

26
parse.y
Просмотреть файл

@ -332,6 +332,12 @@ parser_set_line(NODE *n, int l)
nd_set_line(n, l); nd_set_line(n, l);
} }
static inline void
rb_discard_node(NODE *n)
{
rb_gc_force_recycle((VALUE)n);
}
#ifndef RIPPER #ifndef RIPPER
static inline void static inline void
set_line_body(NODE *body, int line) set_line_body(NODE *body, int line)
@ -4565,7 +4571,7 @@ f_arg : f_arg_item
$$ = $1; $$ = $1;
$$->nd_plen++; $$->nd_plen++;
$$->nd_next = block_append($$->nd_next, $3->nd_next, @1.first_column); $$->nd_next = block_append($$->nd_next, $3->nd_next, @1.first_column);
rb_gc_force_recycle((VALUE)$3); rb_discard_node($3);
/*% /*%
$$ = rb_ary_push($1, get_value($3)); $$ = rb_ary_push($1, get_value($3));
%*/ %*/
@ -6441,7 +6447,7 @@ parser_peek_variable_name(struct parser_params *parser)
static inline enum yytokentype static inline enum yytokentype
parser_string_term(struct parser_params *parser, int func) parser_string_term(struct parser_params *parser, int func)
{ {
rb_gc_force_recycle((VALUE)lex_strterm); rb_discard_node(lex_strterm);
lex_strterm = 0; lex_strterm = 0;
if (func & STR_FUNC_REGEXP) { if (func & STR_FUNC_REGEXP) {
set_yylval_num(regx_options()); set_yylval_num(regx_options());
@ -6619,7 +6625,7 @@ parser_heredoc_restore(struct parser_params *parser, NODE *here)
heredoc_end = ruby_sourceline; heredoc_end = ruby_sourceline;
ruby_sourceline = nd_line(here); ruby_sourceline = nd_line(here);
dispose_string(here->nd_lit); dispose_string(here->nd_lit);
rb_gc_force_recycle((VALUE)here); rb_discard_node(here);
token_flush(parser); token_flush(parser);
} }
@ -8979,11 +8985,11 @@ literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail, int col
if (htype == NODE_STR) { if (htype == NODE_STR) {
if (!literal_concat0(parser, lit, tail->nd_lit)) { if (!literal_concat0(parser, lit, tail->nd_lit)) {
error: error:
rb_gc_force_recycle((VALUE)head); rb_discard_node(head);
rb_gc_force_recycle((VALUE)tail); rb_discard_node(tail);
return 0; return 0;
} }
rb_gc_force_recycle((VALUE)tail); rb_discard_node(tail);
} }
else { else {
list_append(head, tail, column); list_append(head, tail, column);
@ -8995,7 +9001,7 @@ literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail, int col
if (!literal_concat0(parser, head->nd_lit, tail->nd_lit)) if (!literal_concat0(parser, head->nd_lit, tail->nd_lit))
goto error; goto error;
tail->nd_lit = head->nd_lit; tail->nd_lit = head->nd_lit;
rb_gc_force_recycle((VALUE)head); rb_discard_node(head);
head = tail; head = tail;
} }
else if (NIL_P(tail->nd_lit)) { else if (NIL_P(tail->nd_lit)) {
@ -9003,7 +9009,7 @@ literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail, int col
head->nd_alen += tail->nd_alen - 1; head->nd_alen += tail->nd_alen - 1;
head->nd_next->nd_end->nd_next = tail->nd_next; head->nd_next->nd_end->nd_next = tail->nd_next;
head->nd_next->nd_end = tail->nd_next->nd_end; head->nd_next->nd_end = tail->nd_next->nd_end;
rb_gc_force_recycle((VALUE)tail); rb_discard_node(tail);
} }
else if (htype == NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) && else if (htype == NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
nd_type(headlast) == NODE_STR) { nd_type(headlast) == NODE_STR) {
@ -9280,8 +9286,8 @@ new_regexp_gen(struct parser_params *parser, NODE *node, int options, int column
} }
rb_str_resize(tail, 0); rb_str_resize(tail, 0);
prev->nd_next = list->nd_next; prev->nd_next = list->nd_next;
rb_gc_force_recycle((VALUE)list->nd_head); rb_discard_node(list->nd_head);
rb_gc_force_recycle((VALUE)list); rb_discard_node(list);
list = prev; list = prev;
} }
else { else {