Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions imemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,7 @@ rb_imemo_free(VALUE obj)
case imemo_callinfo:{
const struct rb_callinfo *ci = ((const struct rb_callinfo *)obj);

if (ci->kwarg) {
if (RUBY_ATOMIC_FETCH_SUB(((struct rb_callinfo_kwarg *)ci->kwarg)->references, 1) == 1) {
ruby_xfree_sized((void *)ci->kwarg, rb_callinfo_kwarg_bytes(ci->kwarg->keyword_len));
}
}
rb_callinfo_kwarg_release((struct rb_callinfo_kwarg *)ci->kwarg);
RB_DEBUG_COUNTER_INC(obj_imemo_callinfo);

break;
Expand Down
9 changes: 8 additions & 1 deletion prism/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -15290,6 +15290,12 @@ parse_block(pm_parser_t *parser, uint16_t depth) {
statements = UP(parse_statements(parser, PM_CONTEXT_BLOCK_BRACES, (uint16_t) (depth + 1)));
}

/* Pop before consuming the closing `}` so the following token (e.g. a
* `do`) is lexed in the enclosing context rather than as a block
* belonging to this block's interior. Otherwise a `do` block would
* wrongly bind to a command whose argument ends in a brace block, as in
* `foo(m a { } do end)`. */
pm_accepts_block_stack_pop(parser);
expect1_opening(parser, PM_TOKEN_BRACE_RIGHT, PM_ERR_BLOCK_TERM_BRACE, &opening);
} else {
if (!match1(parser, PM_TOKEN_KEYWORD_END)) {
Expand All @@ -15305,6 +15311,8 @@ parse_block(pm_parser_t *parser, uint16_t depth) {
}
}

/* As with the brace case above, pop before consuming `end`. */
pm_accepts_block_stack_pop(parser);
expect1_opening(parser, PM_TOKEN_KEYWORD_END, PM_ERR_BLOCK_TERM_END, &opening);
}

Expand All @@ -15313,7 +15321,6 @@ parse_block(pm_parser_t *parser, uint16_t depth) {
pm_node_t *parameters = parse_blocklike_parameters(parser, UP(block_parameters), &opening, &parser->previous);

pm_parser_scope_pop(parser);
pm_accepts_block_stack_pop(parser);

return pm_block_node_create(parser, &locals, &opening, parameters, statements, &parser->previous);
}
Expand Down
4 changes: 4 additions & 0 deletions prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3887,6 +3887,8 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c
ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.line, location.node_id, BIN(putnil), 0)->link);
}

rb_callinfo_kwarg_retain(kw_arg);

// Jump unless the receiver uses the "basic" implementation of "new"
VALUE ci;
if (flags & VM_CALL_FORWARDING) {
Expand All @@ -3909,6 +3911,8 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c

PUSH_LABEL(ret, not_basic_new_finish);
PUSH_INSN(ret, location, pop);

rb_callinfo_kwarg_release(kw_arg);
}
else {
PUSH_SEND_R(ret, location, method_id, INT2FIX(orig_argc), block_iseq, INT2FIX(flags), kw_arg);
Expand Down
14 changes: 14 additions & 0 deletions test/prism/errors/do_block_after_command_block.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
foo(m a { } do end)
^~ unexpected 'do'; expected a `)` to close the arguments
^~ unexpected 'do', expecting end-of-input
^~ unexpected 'do', ignoring it
^~~ unexpected 'end', ignoring it
^ unexpected ')', ignoring it

foo(m a.b { } do end)
^~ unexpected 'do'; expected a `)` to close the arguments
^~ unexpected 'do', expecting end-of-input
^~ unexpected 'do', ignoring it
^~~ unexpected 'end', ignoring it
^ unexpected ')', ignoring it

14 changes: 14 additions & 0 deletions vm_callinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ rb_callinfo_kwarg_bytes(int keyword_len)
rb_eRuntimeError);
}

static inline void
rb_callinfo_kwarg_retain(struct rb_callinfo_kwarg *kwarg)
{
if (kwarg) RUBY_ATOMIC_INC(kwarg->references);
}

static inline void
rb_callinfo_kwarg_release(struct rb_callinfo_kwarg *kwarg)
{
if (kwarg && RUBY_ATOMIC_FETCH_SUB(kwarg->references, 1) == 1) {
ruby_xfree_sized(kwarg, rb_callinfo_kwarg_bytes(kwarg->keyword_len));
}
}

// imemo_callinfo
struct rb_callinfo {
VALUE flags;
Expand Down