Feature #15030
closedHave T_INTEGER constant for checking Integer types in C API
Description
After Integer unification in Ruby 2.4, I think it makes sense to introduce a T_INTEGER
type that helps in directly testing if a Ruby object is an Integer in C API.
For example, currently we need to write RB_TYPE_P(obj, T_FIXNUM)
for this purpose.
However since ruby 2.4 onwards deprecates Fixnum and Bignum, I think it makes sense
to have a T_INTEGER
type so that one can write RB_TYPE_P(obj, T_INTEGER)
directly
to test for both 64-bit and > 64-bit integers.
Updated by Hanmac (Hans Mackowiak) over 5 years ago
hm that is not that easy, while Fixnum
and Bignum
are deprecated on the ruby side,
on the C side they still exist
thats why a single T_INTEGER
check might not work that way you want
Updated by ko1 (Koichi Sasada) over 5 years ago
- Status changed from Open to Rejected
+1 for Hanmac.
C extension writers should check T_FIXNUM
or T_BIGNUM
explicitly.
Updated by Eregon (Benoit Daloze) over 5 years ago
There are certainly cases where a C extension wants to check the argument is an Integer
, and its range doesn't matter, isn't it?
Is there a macro to check for that easily?
Updated by normalperson (Eric Wong) over 5 years ago
eregontp@gmail.com wrote:
There are certainly cases where a C extension wants to check the argument is an Integer, and its range doesn't matter, isn't it?
Is there a macro to check for that easily?
Not currently, just two calls to RB_TYPE_P
but that's a trivial
static inline wrapper (no macros when a static inline will do).
For case, statements, perhaps something like:
#define case_T_INTEGER case T_FIXNUM: case T_BIGNUM
Along the same lines, I've used the following outside of Ruby
for dealing with EAGAIN
/EWOULDBLOCK
:
#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
# define case_EAGAIN case EAGAIN: case EWOULDBLOCK
#else
# define case_EAGAIN case EAGAIN
#endif
switch (errno) {
case_EAGAIN: ...
default: ...
}
Updated by ko1 (Koichi Sasada) over 5 years ago
Eregon (Benoit Daloze) wrote:
There are certainly cases where a C extension wants to check the argument is an Integer, and its range doesn't matter, isn't it?
For example?
Updated by nobu (Nobuyoshi Nakada) over 5 years ago
Use RB_INTEGER_TYPE_P()
.