Ruby 4.1.0dev (2026-10-09 revision 334b4ffa7fa75c5e347799a7609c252abe68df30)
len_t.h
Go to the documentation of this file.
1#ifndef RBIMPL_ARITHMETIC_LEN_T_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_ARITHMETIC_LEN_T_H
23#include "ruby/internal/config.h"
26#include "ruby/internal/cast.h"
27#include "ruby/internal/value.h"
28
29#define LEN2NUM RB_LEN2NUM
30#define NUM2LEN RB_NUM2LEN
31#define ULEN2NUM RB_ULEN2NUM
32#define rb_len2int rb_len2int_inline
35#define RB_LEN2NUM RB_LONG2NUM
36
38#define RB_NUM2LEN RB_NUM2LONG
39
41#define RB_ULEN2NUM RB_ULONG2NUM
42
50static inline int
52{
53 int i = RBIMPL_CAST((int)n);
54
55 if /* constexpr */ (sizeof(rb_len_t) <= sizeof(int)) {
56 RBIMPL_ASSUME(i == n);
57 }
58
59 if (i != n)
61
62 return i;
63}
64
65#endif /* RBIMPL_ARITHMETIC_LEN_T_H */
Defines RBIMPL_ASSUME / RBIMPL_UNREACHABLE.
#define RBIMPL_ASSUME(_)
Wraps (or simulates) __builtin_unreachable.
Definition assume.h:76
static int rb_len2int_inline(rb_len_t n)
Checks if int can hold the given integer.
Definition len_t.h:51
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.
Definition numeric.c:3191
Defines VALUE and ID.
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
Definition value.h:131