Project

General

Profile

Actions

Bug #20269

open

bignum too big to convert into `long' when running String#byteslice on Windows

Added by simpliandy (Andy Pfister) about 2 months ago. Updated about 2 months ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x64-mingw-ucrt]
[ruby-core:116782]

Description

Running String#byteslice on Ruby 3.3 on Windows results in an error when using any number bigger than 32 bits:

"".byteslice(0, 2547483647)
(irb):1:in `byteslice': bignum too big to convert into `long' (RangeError)
        from (irb):1:in `<main>'
        from <internal:kernel>:187:in `loop'
        from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/irb-1.11.0/exe/irb:9:in `<top (required)>'
        from C:/Ruby33-x64/bin/irb:33:in `load'
        from C:/Ruby33-x64/bin/irb:33:in `<main>'

It works fine on MacOS:

irb(main):001> "".byteslice(0, 2547483647)
=> ""
irb(main):002> exit
Andys-MBP:project apf$ ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin23]

Updated by nobu (Nobuyoshi Nakada) about 2 months ago

On Windows, long is a 32-bit integer.
The error message says the length exceeds that limit.

Updated by simpliandy (Andy Pfister) about 2 months ago

many thanks for your reply.

I found an explanation on Reddit. The reason it works on Linux / Mac is that the compiler expands long to 64-bit if running on a 64-bit system. I was not aware of this.

On Windows, there is a type called longlong which would be 64-bit. not sure if there is a way to say "hey, when compiling Ruby on Windows and on a 64-bit machine, use longlong instead of long". not even sure if this is a smart idea at all.

Actions

Also available in: Atom PDF

Like0
Like0Like0