Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple assignment kills mruby when too many placeholder variables are to be assigned #2824

Closed
tsahara opened this issue Jun 3, 2015 · 0 comments

Comments

@tsahara
Copy link
Member

tsahara commented Jun 3, 2015

% ruby -e 'puts "x=(1..128).to_a; *a" + ",_" * 123 + "= x; p a"' 
x=(1..128).to_a; *a,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_= x; p a

% ruby -e 'puts "x=(1..128).to_a; *a" + ",_" * 123 + "= x; p a"' | bin/mruby
[1, 2, 3, 4, 5]

% ruby -e 'puts "x=(1..128).to_a; *a" + ",_" * 124 + "= x; p a"' | bin/mruby
zsh: done                              ruby -e 'puts "x=(1..128).to_a; *a" + ",_" * 124 + "= x; p a"' | 
zsh: segmentation fault (core dumped)  bin/mruby

That's because only a small number of registers are allocated for the irep but OP_APOST assumes there are enough registers on stack to assign the members of the array.

% ruby -e 'puts "x=(1..128).to_a; *a" + ",_" * 124 + "= x; p a"' | bin/mruby -v
...
irep 0x30043246280 nregs=7 nlocals=4 pools=0 syms=2 reps=0
file: -
    1 000 OP_LOADI      R4      1       
    1 001 OP_LOADI      R5      128     
    1 002 OP_RANGE      R4      R4      0
    1 003 OP_SEND       R4      :to_a   0
    1 004 OP_MOVE       R1      R4              ; R1:x
    1 005 OP_APOST      R4      0       124
    1 006 OP_MOVE       R2      R4              ; R2:a
    1 007 OP_MOVE       R3      R5              ; R3:_
    1 008 OP_MOVE       R3      R6              ; R3:_
...
zsh: done                              ruby -e 'puts "x=(1..128).to_a; *a" + ",_" * 124 + "= x; p a"' | 
zsh: segmentation fault (core dumped)  bin/mruby

mruby dies at https://github.com/mruby/mruby/blob/master/src/vm.c#L2139

@matz matz closed this as completed in b34ee9a Aug 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant