Project

General

Profile

Backport #7671

Unexpected result of the Flip-Flop

Added by phasis68 (Heesob Park) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:51296]

Description

Reported from http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/402825

C:\work>irb
irb(main):001:0> vs = (1..9).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
irb(main):002:0> v1 = vs.select { |n| if n==3..n==6 then 1 end }
=> [3, 4, 5, 6]
irb(main):003:0> v2 = vs.select { |n| if n==2..n==16 then 1 end }
=> [2, 3, 4, 5, 6, 7, 8, 9]
irb(main):004:0> v3 = vs.select { |n| if n==3..n==6 then 1 end }
=> [1, 2, 3, 4, 5, 6]

v1 and v3 use some condition , return value is different.

This bug is due to changeset r38292 and only occurs on the irb session.

Here is a patch:
diff --git a/compile.c b/compile.c.new
index db060e7..e644390 100644
--- a/compile.c
+++ b/compile.c.new
@@ -5057,7 +5057,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)

if (!data) data = iseq->compile_data;
cnt = data->flip_cnt++ + DEFAULT_SPECIAL_VAR_COUNT;
  • key = INT2FIX(cnt);
  • key = LL2NUM(cnt+(VALUE)iseq);

    ADD_INSN2(ret, nd_line(node), getspecial, key, INT2FIX(0));
    ADD_INSNL(ret, nd_line(node), branchif, lend);

Associated revisions

Revision 69b71611
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_core.h: flip_cnt in rb_iseq_t

  • vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data, because it has same life span as enclosing iseq. [Bug #7671] [ruby-core:51296]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 38739
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_core.h: flip_cnt in rb_iseq_t

  • vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data, because it has same life span as enclosing iseq. [Bug #7671] [ruby-core:51296]

Revision 38739
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_core.h: flip_cnt in rb_iseq_t

  • vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data, because it has same life span as enclosing iseq. [Bug #7671] [ruby-core:51296]

Revision 38739
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_core.h: flip_cnt in rb_iseq_t

  • vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data, because it has same life span as enclosing iseq. [Bug #7671] [ruby-core:51296]

Revision 38739
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_core.h: flip_cnt in rb_iseq_t

  • vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data, because it has same life span as enclosing iseq. [Bug #7671] [ruby-core:51296]

Revision 38739
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_core.h: flip_cnt in rb_iseq_t

  • vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data, because it has same life span as enclosing iseq. [Bug #7671] [ruby-core:51296]

Revision 38739
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_core.h: flip_cnt in rb_iseq_t

  • vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data, because it has same life span as enclosing iseq. [Bug #7671] [ruby-core:51296]

Revision 3468cd1e
Added by usa (Usaku NAKAMURA) over 6 years ago

merge revision(s) 38739: [Backport #7671]

    * vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data,
      because it has same life span as enclosing iseq.  [Bug #7671]
      [ruby-core:51296]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@38781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 38781
Added by usa (Usaku NAKAMURA) over 6 years ago

merge revision(s) 38739: [Backport #7671]

* vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data,
  because it has same life span as enclosing iseq.  [Bug #7671]
  [ruby-core:51296]

History

#1

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r38739.
Heesob, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


vm_core.h: flip_cnt in rb_iseq_t

  • vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data, because it has same life span as enclosing iseq. [Bug #7671] [ruby-core:51296]
#2

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport193
  • Status changed from Closed to Assigned
  • Assignee set to usa (Usaku NAKAMURA)
#3

Updated by usa (Usaku NAKAMURA) over 6 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r38781.
Heesob, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 38739: [Backport #7671]

* vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data,
  because it has same life span as enclosing iseq.  [Bug #7671]
  [ruby-core:51296]

Also available in: Atom PDF