Forum: Ruby-core [CommonRuby - Feature #8568][Open] Introduce RbConfig value for native word size, to avoid Fixnum#si

F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-06-24 23:14
(Received via mailing list)
Issue #8568 has been reported by headius (Charles Nutter).

----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-06-25 04:02
(Received via mailing list)
Issue #8568 has been updated by nobu (Nobuyoshi Nakada).


In current CRuby, Fixnum is always limited as long, so Fixnum#size
represents sizeof(long), not word size.
But it depends on what you define "word" as, of course.
If you mean SIZEOF_VALUE by "word size", it's simply a bug to use
Fixnum#size for that purpose.

A way to achieve size of a pointer is `[""].pack("p").size` currently.
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-40125

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-06-25 05:51
(Received via mailing list)
Issue #8568 has been updated by headius (Charles Nutter).


Size of a pointer is probably what I'm looking for, since that's usually
what people will be using it for. However, implementations that can't
give out real pointers can't support pack("p"), so that's not a portable
option either.

So... RbConfig::CONFIG['pointer_size'] and some constant?
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-40126

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-06-25 07:06
(Received via mailing list)
Issue #8568 has been updated by nobu (Nobuyoshi Nakada).


'pointer' or 'value'?

I'm curious for what purpose people use that size.
Pointers are not used usually in ruby, I think.

----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-40127

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
9361878d459f1709feec780518946ee5?d=identicon&s=25 naruse (Yui NARUSE) (Guest)
on 2013-06-25 12:48
(Received via mailing list)
Issue #8568 has been updated by naruse (Yui NARUSE).


The place where word size info should be seems RbConfig, if it is
needed.

nobu (Nobuyoshi Nakada) wrote:
> 'pointer' or 'value'?
>
> I'm curious for what purpose people use that size.
> Pointers are not used usually in ruby, I think.

See #8553
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-40131

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 Tanaka Akira (Guest)
on 2013-06-25 13:17
(Received via mailing list)
2013/6/25 headius (Charles Nutter) <headius@headius.com>:
> Issue #8568 has been reported by headius (Charles Nutter).

> I propose two additions to Ruby:
>
> 1. RbConfig value "word_size" for native word size. This could reflect bit size
(32, 64) or byte size (4, 8).
>
> 2. A constant, somewhere in Ruby, to provide access to this value more directly.
I'm not sure where this should go. ObjectSpace::WORD_SIZE?

Although "word" is ambiguous, providing sizeof(long), sizeof(char*),
etc. via RbConfig
with clear names seems good feature:
RbConfig["sizeof(long)"], RbConfig["sieof(char*)"],
RbConfig["sizeof(time_t)"], ...
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-07-03 09:57
(Received via mailing list)
Issue #8568 has been updated by nobu (Nobuyoshi Nakada).

File sizeof.diff added

akr (Akira Tanaka) wrote:
>  Although "word" is ambiguous, providing sizeof(long), sizeof(char*),
>  etc. via RbConfig
>  with clear names seems good feature:
>  RbConfig["sizeof(long)"], RbConfig["sieof(char*)"],
>  RbConfig["sizeof(time_t)"], ...

RbConfig is a module, so `RbConfig.[]` doesn't seem good.
What about `RbConfig::SIZEOF` instead?
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-40268

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-07-03 10:05
(Received via mailing list)
Issue #8568 has been updated by nobu (Nobuyoshi Nakada).


naruse (Yui NARUSE) wrote:
> > I'm curious for what purpose people use that size.
> > Pointers are not used usually in ruby, I think.
>
> See #8553

I can't see any needs in ruby level there.
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-40269

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 Tanaka Akira (Guest)
on 2013-07-03 11:47
(Received via mailing list)
2013/7/3 nobu (Nobuyoshi Nakada) <nobu@ruby-lang.org>:

> RbConfig is a module, so `RbConfig.[]` doesn't seem good.
> What about `RbConfig::SIZEOF` instead?

No problem.

They would be useful for ioctl and socket option.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-09-27 12:46
(Received via mailing list)
Issue #8568 has been updated by headius (Charles Nutter).


In for 2.1?
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42032

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-01 02:40
(Received via mailing list)
Issue #8568 has been updated by headius (Charles Nutter).

Target version set to Ruby 2.1.0


----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42123

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: Ruby 2.1.0


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-10-01 03:00
(Received via mailing list)
Issue #8568 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Closed

r42685
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42128

Author: headius (Charles Nutter)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version: Ruby 2.1.0


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-01 20:16
(Received via mailing list)
Issue #8568 has been updated by headius (Charles Nutter).


nobu (Nobuyoshi Nakada) wrote:
> r42685

Thanks! I do have one question, though.. are the names of the types
(acquired via #type in sizes.c) guaranteed to be consistent across
platforms/compilers?
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42174

Author: headius (Charles Nutter)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version: Ruby 2.1.0


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-10-02 02:53
(Received via mailing list)
Issue #8568 has been updated by nobu (Nobuyoshi Nakada).


They are extracted from configure.in script automatically.
And ANSI/ISO C standard requires stringize operator to turn the argument
into a string literal *before* expanding it.
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42187

Author: headius (Charles Nutter)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version: Ruby 2.1.0


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-02 07:33
(Received via mailing list)
Issue #8568 has been updated by headius (Charles Nutter).


nobu (Nobuyoshi Nakada) wrote:
> =begin
> They are extracted from ((%configure.in%)) script automatically.
> And ANSI/ISO C standard requires stringize operator to turn the argument into a
string literal ((*before*)) expanding it.
> =end

I interpret this to mean that the names of the types should be ANSI/ISO
C standard names. If that's the case, I'm satisfied.

My concern is if the type names vary across platforms; they would be
*much* less useful if one platform reports "void*" and another platform
reports "void *".
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42202

Author: headius (Charles Nutter)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version: Ruby 2.1.0


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-10-02 19:06
(Received via mailing list)
Issue #8568 has been updated by nobu (Nobuyoshi Nakada).


Sorry that it's unclear.

It means that type names come from a distributed file, configure.in, so
they are invariant on all platforms.
As for C standard, all names will become strings as-is, even if a type
is defined by macro.
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42219

Author: headius (Charles Nutter)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version: Ruby 2.1.0


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-02 20:38
(Received via mailing list)
Issue #8568 has been updated by headius (Charles Nutter).


Ok...so hopefully we have tests for those names and we can consider them
"spec".

BTW, I'm asking because we'll want to provide the same SIZEOF hash in
JRuby, and I need to know the names will be consistent and not change in
the future.

Thanks!
----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42228

Author: headius (Charles Nutter)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version: Ruby 2.1.0


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-10-02 20:54
(Received via mailing list)
Issue #8568 has been updated by nobu (Nobuyoshi Nakada).


Almost of those names are defined by C standard or POSIX, so they won't
change.
I think what names are included is *not* a spec, however.
New names may be added or existing names may be deleted, without any
notice.

I think all I can guarantee is, in a same CRuby revision, same names are
defined on all platforms where they are supported.

----------------------------------------
Feature #8568: Introduce RbConfig value for native word size, to avoid
Fixnum#size use
https://bugs.ruby-lang.org/issues/8568#change-42229

Author: headius (Charles Nutter)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version: Ruby 2.1.0


Fixnum#size is not really useful to represent native word size across
all platforms and implementations. On JRuby, for example, our Fixnum is
always represented as a 64-bit Java "long" value, regardless of the
underlying native platform. There may be other implementations that fix
Fixnum's size to a specific bit width as well. Therefore, using
Fixnum#size to determine the size of a word on the underlying native
platform is not reliable.

I propose two additions to Ruby:

1. RbConfig value "word_size" for native word size. This could reflect
bit size (32, 64) or byte size (4, 8).

2. A constant, somewhere in Ruby, to provide access to this value more
directly. I'm not sure where this should go. ObjectSpace::WORD_SIZE?
This topic is locked and can not be replied to.