1#ifndef RBIMPL_ARITHMETIC_LEN_T_H
2#define RBIMPL_ARITHMETIC_LEN_T_H
23#include "ruby/internal/config.h"
27#include "ruby/internal/cast.h"
30#define FIX2LEN RB_FIX2LEN
31#define FIX2ULEN RB_FIX2ULEN
32#define LEN2FIX RB_LEN2FIX
33#define LEN2NUM RB_LEN2NUM
34#define NUM2LEN RB_NUM2LEN
35#define ULEN2NUM RB_ULEN2NUM
36#define NUM2ULEN RB_NUM2ULEN
37#define rb_len2int rb_len2int_inline
38#define rb_len2long rb_len2long_inline
40#if SIZEOF_RB_LEN_T > SIZEOF_LONG
41# define RB_LEN2NUM RB_LL2NUM
42# define RB_NUM2LEN RB_NUM2LL
43# define RB_ULEN2NUM RB_ULL2NUM
44# define RB_NUM2ULEN RB_NUM2ULL
47# define RB_LEN2NUM RB_LONG2NUM
50# define RB_NUM2LEN RB_NUM2LONG
53# define RB_ULEN2NUM RB_ULONG2NUM
56# define RB_NUM2ULEN RB_NUM2ULONG
59#define RB_FIX2LEN rb_fix2len
60#define RB_FIX2ULEN rb_fix2ulen
116rbimpl_fix2len_by_idiv(
VALUE x)
144rbimpl_fix2len_by_shift(
VALUE x)
167static const bool rbimpl_right_shift_is_arithmetic_p = (-1 >> 1) == -1;
181 if (rbimpl_right_shift_is_arithmetic_p) {
182 return rbimpl_fix2len_by_shift(x);
185 return rbimpl_fix2len_by_idiv(x);
216 int i = RBIMPL_CAST((
int)n);
218 if (
sizeof(
rb_len_t) <=
sizeof(
int)) {
238 long l = RBIMPL_CAST((
long)n);
240 if (
sizeof(
rb_len_t) <=
sizeof(
long)) {
271static inline unsigned long
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#define RBIMPL_ASSERT_OR_ASSUME(...)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
#define RBIMPL_ATTR_CONST_UNLESS_DEBUG()
Enables RBIMPL_ATTR_CONST if and only if.
#define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_)
Enables RBIMPL_ATTR_CONSTEXPR if and only if.
#define RB_FIXABLE(_)
Checks if the passed value is in range of fixnum.
Defines RBIMPL_ASSUME / RBIMPL_UNREACHABLE.
#define RBIMPL_ASSUME(_)
Wraps (or simulates) __builtin_unreachable.
Arithmetic conversion between C's long long and Ruby's.
static VALUE RB_INT2FIX(long i)
Converts a C's long into an instance of rb_cInteger.
static VALUE rb_len2fix(rb_len_t i)
Converts a rb_len_t into an instance of rb_cInteger.
static int rb_len2int_inline(rb_len_t n)
Checks if int can hold the given integer.
static long rb_fix2long(VALUE x)
Converts a Fixnum into C's long.
#define rb_len2long
Just another name of rb_len2long_inline.
static rb_len_t rb_fix2len(VALUE x)
Converts a Fixnum into rb_len_t.
static long rb_len2long_inline(rb_len_t n)
Checks if long can hold the given integer.
static rb_ulen_t rb_fix2ulen(VALUE x)
Converts a Fixnum into rb_ulen_t.
static unsigned long rb_fix2ulong(VALUE x)
Converts a Fixnum into C's unsigned long.
Arithmetic conversion between C's long and Ruby's.
void rb_out_of_int(SIGNED_VALUE num)
This is an utility function to raise an rb_eRangeError.
void rb_out_of_long(SIGNED_VALUE num)
This is an utility function to raise an rb_eRangeError.
static bool RB_FIXNUM_P(VALUE obj)
Checks if the given object is a so-called Fixnum.
@ RUBY_FIXNUM_FLAG
Flag to denote a fixnum.
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
unsigned long rb_ulen_t
An unsigned integer type that has the same width with rb_len_t.
uintptr_t VALUE
Type that represents a Ruby object.