[ruby-core:88687] Re: [Ruby trunk Feature#15030] Have T_INTEGER constant for checking Integer types in C API

From: Eric Wong <normalperson@...>
Date: 2018-08-27 11:57:29 UTC
List: ruby-core #88687
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: ...
    }
```

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next