[ruby-core:96316] [Ruby master Bug#15551] The behavior of FIX2INT and FIX2UINT differs by platform

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-83228.20191218153817.fcfb3843076db53b@ruby-lang.org>
Issue #15551 has been updated by mame (Yusuke Endoh).

Status changed from Open to Rejected

It is by design.  doc/extension.rdoc says:

```
T_FIXNUM can be converted to a C integer by using the
FIX2INT() macro or FIX2LONG().  Though you have to check that the
data is really FIXNUM before using them, they are faster.
```

So `FIX2INT(nil)` is intentionally designed to be undefined.  

----------------------------------------
Bug #15551: The behavior of FIX2INT and FIX2UINT differs by platform
https://bugs.ruby-lang.org/issues/15551#change-83228

* Author: Eregon (Benoit Daloze)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.5p335 (2018-10-18 revision 65137) [x64-mingw32]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
For instance, when `sizeof(int) < sizeof(long)` (such as on Linux), then
```c
FIX2INT(nil)
```
raises TypeError.
But when `sizeof(int) == sizeof(long)` (such as on Windows), then it returns `4`.

So the behavior changes from a call to `rb_fix2int()` to a raw shift without any checks.
I think it should be consistent between platforms.

Also, the code in ruby.h defining FIX2INT is fairly complicated with conditions like `#if SIZEOF_INT < SIZEOF_LONG`
spanning many lines, which makes it fairly hard to follow.

See https://github.com/ruby/spec/blob/c661c0ba6a602be6e06768a319bd7d87b2a8eda6/optional/capi/fixnum_spec.rb
and https://ci.appveyor.com/project/eregon/spec-x948i/builds/21753809/job/ed8e8k97m8syp4r7 for more differences.

---Files--------------------------------
fix2int-consistent.patch (1017 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.