Bugs item #10527, was opened at 2007-05-03 04:42
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=10527&group_id=426

Category: Core
Group: 1.9.x
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Paul Brannan (cout)
>Assigned to: Nobuyoshi Nakada  (nobu)
Summary: segfault printing instruction sequence for iterator

Initial Comment:
The following program segfaults:

i = VM::InstructionSequence.compile('for a in b; end')
p i.to_a

This appears to be the culprit:

                | keyword_for for_var keyword_in
                  {COND_PUSH(1);}
                  expr_value do
                  {COND_POP();}
                  compstmt
                  keyword_end
                    {
                    /*%%%*/
                        ID id = internal_id();
                        ID *tbl = ALLOC_N(ID, 2);
                        NODE *args = NEW_ARGS(1 /* m */, 0 /* o */);
                        NODE *init;
                        NODE *scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
                        tbl[0] = 1; tbl[1] = id;

                        init = node_assign($2, NEW_DVAR(id));
                        args->nd_next = NEW_ARGS_AUX(0, 0);
                        args->nd_next->nd_next = NEW_ARGS_AUX(0, 0);
                        args->nd_next->nd_next->nd_next = init;

                        $$ = NEW_FOR(0, $5, scope);
                        fixpos($$, $2);

The internal id gets added to the node, then later passed on to the instruction sequence.  When ruby tries to print out the internal id, it can't, because there is no associated string with an internal id.

This indicates to me two problems:
  - I think this is a problem with the internal_id() function in general; internal IDs don't behave like other IDs
  - the rb_id2name function can return 0 on failure or in the case that the given id is an internal id.  There are a number of places in the code where the return value isn't being checked, which could potentially cause a crash.

I do not know YARV well enough to provide a patch.


----------------------------------------------------------------------

Comment By: Nobuyoshi Nakada  (nobu)
Date: 2007-05-11 15:34

Message:
This bug is fixed in the repository.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=10527&group_id=426