ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91192] [Ruby trunk Bug#15551] The behavior of FIX2INT and FIX2UINT differs by platform
       [not found] <redmine.issue-15551.20190120143825@ruby-lang.org>
@ 2019-01-20 14:38 ` eregontp
  2019-01-20 21:21 ` [ruby-core:91196] " eregontp
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: eregontp @ 2019-01-20 14:38 UTC (permalink / raw)
  To: ruby-core

Issue #15551 has been reported by Eregon (Benoit Daloze).

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

* Author: Eregon (Benoit Daloze)
* Status: Open
* 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.



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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:91196] [Ruby trunk Bug#15551] The behavior of FIX2INT and FIX2UINT differs by platform
       [not found] <redmine.issue-15551.20190120143825@ruby-lang.org>
  2019-01-20 14:38 ` [ruby-core:91192] [Ruby trunk Bug#15551] The behavior of FIX2INT and FIX2UINT differs by platform eregontp
@ 2019-01-20 21:21 ` eregontp
  2019-07-30 20:55 ` [ruby-core:94061] [Ruby master " merch-redmine
  2019-12-18 15:38 ` [ruby-core:96316] " mame
  3 siblings, 0 replies; 4+ messages in thread
From: eregontp @ 2019-01-20 21:21 UTC (permalink / raw)
  To: ruby-core

Issue #15551 has been updated by Eregon (Benoit Daloze).


FWIW, `sizeof(int) == sizeof(long)` is also the case on i686 Linux:
https://travis-ci.org/ruby/ruby/jobs/482143545

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

* Author: Eregon (Benoit Daloze)
* Status: Open
* 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.



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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:94061] [Ruby master Bug#15551] The behavior of FIX2INT and FIX2UINT differs by platform
       [not found] <redmine.issue-15551.20190120143825@ruby-lang.org>
  2019-01-20 14:38 ` [ruby-core:91192] [Ruby trunk Bug#15551] The behavior of FIX2INT and FIX2UINT differs by platform eregontp
  2019-01-20 21:21 ` [ruby-core:91196] " eregontp
@ 2019-07-30 20:55 ` merch-redmine
  2019-12-18 15:38 ` [ruby-core:96316] " mame
  3 siblings, 0 replies; 4+ messages in thread
From: merch-redmine @ 2019-07-30 20:55 UTC (permalink / raw)
  To: ruby-core

Issue #15551 has been updated by jeremyevans0 (Jeremy Evans).

File fix2int-consistent.patch added

I consider this an implementation detail and not a bug. I'm guessing the reason for this behavior is if `sizeof(int) == sizeof(long)`, then all Fixnums are convertible to int (since all Fixnums are convertible to long).  This is different than the `sizeof(int) < sizeof(long)` case, where not all Fixnums are convertible to int.  It is possible to add checks that a Fixnum value is passed, but doing so would hurt performance.

Note that `FIX2LONG` is always a pure shift, so `FIX2LONG(Qnil)` never raises.  By attempting to make the `FIX2INT` behavior consistent across platforms, you make `FIX2LONG` inconsistent with `FIX2INT` in both of the cases instead of just one.

If we still feel like this is a good idea, we could try the attached patch.  I did some basic testing of this on OpenBSD-i386, where `sizeof(int) == sizeof(long)`.  However, I recommend we keep things as they are.

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

* Author: Eregon (Benoit Daloze)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:96316] [Ruby master Bug#15551] The behavior of FIX2INT and FIX2UINT differs by platform
       [not found] <redmine.issue-15551.20190120143825@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-07-30 20:55 ` [ruby-core:94061] [Ruby master " merch-redmine
@ 2019-12-18 15:38 ` mame
  3 siblings, 0 replies; 4+ messages in thread
From: mame @ 2019-12-18 15:38 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-18 15:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15551.20190120143825@ruby-lang.org>
2019-01-20 14:38 ` [ruby-core:91192] [Ruby trunk Bug#15551] The behavior of FIX2INT and FIX2UINT differs by platform eregontp
2019-01-20 21:21 ` [ruby-core:91196] " eregontp
2019-07-30 20:55 ` [ruby-core:94061] [Ruby master " merch-redmine
2019-12-18 15:38 ` [ruby-core:96316] " mame

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).