[ruby-core:116782] [Ruby master Bug#20269] bignum too big to convert into `long' when running String#byteslice on Windows

Issue #20269 has been reported by simpliandy (Andy Pfister). ---------------------------------------- Bug #20269: bignum too big to convert into `long' when running String#byteslice on Windows https://bugs.ruby-lang.org/issues/20269 * Author: simpliandy (Andy Pfister) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x64-mingw-ucrt] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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] ``` -- https://bugs.ruby-lang.org/

Issue #20269 has been updated by nobu (Nobuyoshi Nakada). On Windows, `long` is a 32-bit integer. The error message says the length exceeds that limit. ---------------------------------------- Bug #20269: bignum too big to convert into `long' when running String#byteslice on Windows https://bugs.ruby-lang.org/issues/20269#change-106817 * Author: simpliandy (Andy Pfister) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x64-mingw-ucrt] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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] ``` -- https://bugs.ruby-lang.org/

Issue #20269 has been updated by simpliandy (Andy Pfister). many thanks for your reply. I found an explanation on [Reddit](https://www.reddit.com/r/C_Programming/comments/4kjd0c/comment/d3fd0vp/). 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](https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types) 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. ---------------------------------------- Bug #20269: bignum too big to convert into `long' when running String#byteslice on Windows https://bugs.ruby-lang.org/issues/20269#change-106818 * Author: simpliandy (Andy Pfister) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x64-mingw-ucrt] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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] ``` -- https://bugs.ruby-lang.org/
participants (2)
-
nobu (Nobuyoshi Nakada)
-
simpliandy (Andy Pfister)