Project

General

Profile

Bug #14805

Enumerator#count is silently limited to int32

Added by amadan (Goran Topic) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin17]
[ruby-core:87340]

Description

One takes for granted that integers will be promoted into bigints in Ruby when needed.
Not so with Enumerator#count:

2147483647.times.count
# => 2147483647 
2147483648.times.count
# => -2147483648

(notice the minus!)

Associated revisions

Revision 9b6175b2
Added by naruse (Yui NARUSE) over 1 year ago

memo->u3.cnt is long not int [Bug #14805]

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

Revision 63549
Added by naruse (Yui NARUSE) over 1 year ago

memo->u3.cnt is long not int [Bug #14805]

Revision 63549
Added by naruse (Yui NARUSE) over 1 year ago

memo->u3.cnt is long not int [Bug #14805]

Revision 6bb70c11
Added by nobu (Nobuyoshi Nakada) over 1 year ago

enum.c: mitigate overflows

  • enum.c (enum_count): convert counters to Integer as unsigned
    long, instead of long, to mitigate overflows.
    [ruby-core:87348] [Bug #14805]

  • enum.c (ary_inject_op): ditto.

  • enum.c (each_with_index_i): ditto, instead of int.

  • enum.c (find_index_i, find_index_iter_i): ditto, instead of
    unsigned int.

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

Revision 63551
Added by nobu (Nobuyoshi Nakada) over 1 year ago

enum.c: mitigate overflows

  • enum.c (enum_count): convert counters to Integer as unsigned
    long, instead of long, to mitigate overflows.
    [ruby-core:87348] [Bug #14805]

  • enum.c (ary_inject_op): ditto.

  • enum.c (each_with_index_i): ditto, instead of int.

  • enum.c (find_index_i, find_index_iter_i): ditto, instead of
    unsigned int.

Revision 63551
Added by nobu (Nobuyoshi Nakada) over 1 year ago

enum.c: mitigate overflows

  • enum.c (enum_count): convert counters to Integer as unsigned
    long, instead of long, to mitigate overflows.
    [ruby-core:87348] [Bug #14805]

  • enum.c (ary_inject_op): ditto.

  • enum.c (each_with_index_i): ditto, instead of int.

  • enum.c (find_index_i, find_index_iter_i): ditto, instead of
    unsigned int.

Revision 7495b2d2
Added by nobu (Nobuyoshi Nakada) over 1 year ago

enum.c: bignum counter

  • enum.c (imemo_count_up, imemo_count_value): promote the counter value to a bignum on overflow. [Bug #14805]

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

Revision 63554
Added by nobu (Nobuyoshi Nakada) over 1 year ago

enum.c: bignum counter

  • enum.c (imemo_count_up, imemo_count_value): promote the counter value to a bignum on overflow. [Bug #14805]

Revision 63554
Added by nobu (Nobuyoshi Nakada) over 1 year ago

enum.c: bignum counter

  • enum.c (imemo_count_up, imemo_count_value): promote the counter value to a bignum on overflow. [Bug #14805]

Revision 7367d5db
Added by usa (Usaku NAKAMURA) over 1 year ago

merge revision(s) 63549,63551,63554: [Backport #14805]

    memo->u3.cnt is long not int [Bug #14805]

    enum.c: mitigate overflows

    * enum.c (enum_count): convert counters to Integer as unsigned
      long, instead of long, to mitigate overflows.
      [ruby-core:87348] [Bug #14805]

    * enum.c (ary_inject_op): ditto.

    * enum.c (each_with_index_i): ditto, instead of int.

    * enum.c (find_index_i, find_index_iter_i): ditto, instead of
      unsigned int.

    enum.c: bignum counter

    * enum.c (imemo_count_up, imemo_count_value): promote the counter
      value to a bignum on overflow.  [Bug #14805]

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

Revision 64125
Added by usa (Usaku NAKAMURA) over 1 year ago

merge revision(s) 63549,63551,63554: [Backport #14805]

memo->u3.cnt is long not int [Bug #14805]

enum.c: mitigate overflows

* enum.c (enum_count): convert counters to Integer as unsigned
  long, instead of long, to mitigate overflows.
  [ruby-core:87348] [Bug #14805]

* enum.c (ary_inject_op): ditto.

* enum.c (each_with_index_i): ditto, instead of int.

* enum.c (find_index_i, find_index_iter_i): ditto, instead of
  unsigned int.

enum.c: bignum counter

* enum.c (imemo_count_up, imemo_count_value): promote the counter
  value to a bignum on overflow.  [Bug #14805]

Revision f5a90a2d
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 63549,63551,63554: [Backport #14805]

    memo->u3.cnt is long not int [Bug #14805]

    enum.c: mitigate overflows

    * enum.c (enum_count): convert counters to Integer as unsigned
      long, instead of long, to mitigate overflows.
      [ruby-core:87348] [Bug #14805]

    * enum.c (ary_inject_op): ditto.

    * enum.c (each_with_index_i): ditto, instead of int.

    * enum.c (find_index_i, find_index_iter_i): ditto, instead of
      unsigned int.

    enum.c: bignum counter

    * enum.c (imemo_count_up, imemo_count_value): promote the counter
      value to a bignum on overflow.  [Bug #14805]

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

Revision 64432
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 63549,63551,63554: [Backport #14805]

memo->u3.cnt is long not int [Bug #14805]

enum.c: mitigate overflows

* enum.c (enum_count): convert counters to Integer as unsigned
  long, instead of long, to mitigate overflows.
  [ruby-core:87348] [Bug #14805]

* enum.c (ary_inject_op): ditto.

* enum.c (each_with_index_i): ditto, instead of int.

* enum.c (find_index_i, find_index_iter_i): ditto, instead of
  unsigned int.

enum.c: bignum counter

* enum.c (imemo_count_up, imemo_count_value): promote the counter
  value to a bignum on overflow.  [Bug #14805]

History

Updated by duerst (Martin Dürst) over 1 year ago

Confirmed on trunk.

Updated by shan (Shannon Skipper) over 1 year ago

It's interestingly also negative on JRuby. Headius noted in the #ruby IRC channel that this patch would fix the issue for JRuby.

It's positive in TruffleRuby.

It's also positive in Rubinius, but takes about half and hour to calculate and uses ~5GB of RAM. :-O Not sure what's going on there.

On the non-Ruby front, it's negative in Crystal-lang too!

2147483648.times.count { |n| n } #=> -2147483648 : Int32
#3

Updated by naruse (Yui NARUSE) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63549.


memo->u3.cnt is long not int [Bug #14805]

#4

Updated by naruse (Yui NARUSE) over 1 year ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: REQUIRED, 2.4: REQUIRED, 2.5: REQUIRED

Updated by usa (Usaku NAKAMURA) over 1 year ago

  • Backport changed from 2.3: REQUIRED, 2.4: REQUIRED, 2.5: REQUIRED to 2.3: REQUIRED, 2.4: DONE, 2.5: REQUIRED

ruby_2_4 r64125 merged revision(s) 63549,63551,63554.

Updated by nagachika (Tomoyuki Chikanaga) over 1 year ago

  • Backport changed from 2.3: REQUIRED, 2.4: DONE, 2.5: REQUIRED to 2.3: REQUIRED, 2.4: DONE, 2.5: DONE

ruby_2_5 r64432 merged revision(s) 63549,63551,63554.

Also available in: Atom PDF