Ruby 4.1.0dev (2026-10-29 revision d5d40d27490b11b73a68f43e918199b6d386101a)
Macros | Functions
len_t.h File Reference

(d5d40d27490b11b73a68f43e918199b6d386101a)

Arithmetic conversion between rb_len_t and Ruby's. More...

#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/arithmetic/long_long.h"
#include "ruby/internal/assume.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/value.h"
Include dependency graph for len_t.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FIX2LEN   RB_FIX2LEN
 Old name of RB_FIX2LEN.
 
#define FIX2ULEN   RB_FIX2ULEN
 Old name of RB_FIX2ULEN.
 
#define LEN2FIX   RB_LEN2FIX
 Old name of RB_LEN2FIX.
 
#define LEN2NUM   RB_LEN2NUM
 Old name of RB_LEN2NUM.
 
#define NUM2LEN   RB_NUM2LEN
 Old name of RB_NUM2LEN.
 
#define ULEN2NUM   RB_ULEN2NUM
 Old name of RB_ULEN2NUM.
 
#define NUM2ULEN   RB_NUM2ULEN
 Old name of RB_NUM2ULEN.
 
#define rb_len2int   rb_len2int_inline
 Just another name of rb_len2int_inline.
 
#define rb_len2long   rb_len2long_inline
 Just another name of rb_len2long_inline.
 
#define RB_LEN2NUM   RB_LONG2NUM
 Converts a rb_len_t into an instance of rb_cInteger.
 
#define RB_NUM2LEN   RB_NUM2LONG
 Converts an instance of rb_cNumeric into rb_len_t.
 
#define RB_ULEN2NUM   RB_ULONG2NUM
 Converts a rb_ulen_t into an instance of rb_cInteger.
 
#define RB_NUM2ULEN   RB_NUM2ULONG
 Converts an instance of rb_cNumeric into rb_len_t.
 
#define RB_FIX2LEN   rb_fix2len
 
#define RB_FIX2ULEN   rb_fix2ulen
 

Functions

static VALUE rb_len2fix (rb_len_t i)
 Converts a rb_len_t into an instance of rb_cInteger.
 
static VALUE RB_INT2FIX (long i)
 Converts a C's long into an instance of rb_cInteger.
 
static rb_len_t rb_fix2len (VALUE x)
 Converts a Fixnum into rb_len_t.
 
static rb_ulen_t rb_fix2ulen (VALUE x)
 Converts a Fixnum into rb_ulen_t.
 
static int rb_len2int_inline (rb_len_t n)
 Checks if int can hold the given integer.
 
static long rb_len2long_inline (rb_len_t n)
 Checks if long can hold the given integer.
 
static long rb_fix2long (VALUE x)
 Converts a Fixnum into C's long.
 
static unsigned long rb_fix2ulong (VALUE x)
 Converts a Fixnum into C's unsigned long.
 

Detailed Description

Arithmetic conversion between rb_len_t and Ruby's.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either RBIMPL or rbimpl are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __VA_ARGS__ is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file len_t.h.

Macro Definition Documentation

◆ RB_FIX2LEN

#define RB_FIX2LEN   rb_fix2len

Definition at line 59 of file len_t.h.

◆ RB_FIX2ULEN

#define RB_FIX2ULEN   rb_fix2ulen

Definition at line 60 of file len_t.h.

◆ rb_len2int

#define rb_len2int   rb_len2int_inline

Just another name of rb_len2int_inline.

Definition at line 37 of file len_t.h.

◆ rb_len2long

#define rb_len2long   rb_len2long_inline

Just another name of rb_len2long_inline.

Definition at line 38 of file len_t.h.

◆ RB_LEN2NUM

#define RB_LEN2NUM   RB_LONG2NUM

Converts a rb_len_t into an instance of rb_cInteger.

Definition at line 47 of file len_t.h.

◆ RB_NUM2LEN

#define RB_NUM2LEN   RB_NUM2LONG

Converts an instance of rb_cNumeric into rb_len_t.

Definition at line 50 of file len_t.h.

◆ RB_NUM2ULEN

#define RB_NUM2ULEN   RB_NUM2ULONG

Converts an instance of rb_cNumeric into rb_len_t.

Definition at line 56 of file len_t.h.

◆ RB_ULEN2NUM

#define RB_ULEN2NUM   RB_ULONG2NUM

Converts a rb_ulen_t into an instance of rb_cInteger.

Definition at line 53 of file len_t.h.

Function Documentation

◆ rb_fix2len()

static rb_len_t rb_fix2len ( VALUE  x)
inlinestatic

Converts a Fixnum into rb_len_t.

Parameters
[in]xSome Fixnum.
Precondition
Must not pass anything other than a Fixnum.
Returns
The passed value converted into rb_len_t.

Definition at line 179 of file len_t.h.

Referenced by rb_fix2long(), and rb_fix2ulen().

◆ rb_fix2long()

static long rb_fix2long ( VALUE  x)
inlinestatic

Converts a Fixnum into C's long.

Parameters
[in]xSome Fixnum.
Precondition
Must not pass anything other than a Fixnum.
Returns
The passed value converted into C's long.

Definition at line 258 of file len_t.h.

◆ rb_fix2ulen()

static rb_ulen_t rb_fix2ulen ( VALUE  x)
inlinestatic

Converts a Fixnum into rb_ulen_t.

Parameters
[in]xSome Fixnum.
Precondition
Must not pass anything other than a Fixnum.
Returns
The passed value converted into rb_ulen_t.
Note
Negative fixnums will be converted into large rb_ulen_t.

Definition at line 200 of file len_t.h.

Referenced by rb_fix2ulong().

◆ rb_fix2ulong()

static unsigned long rb_fix2ulong ( VALUE  x)
inlinestatic

Converts a Fixnum into C's unsigned long.

Parameters
[in]xSome Fixnum.
Precondition
Must not pass anything other than a Fixnum.
Returns
The passed value converted into C's unsigned long.
Note
Negative fixnums will be converted into large unsigned longs.

Definition at line 272 of file len_t.h.

◆ RB_INT2FIX()

static VALUE RB_INT2FIX ( long  i)
inlinestatic

Converts a C's long into an instance of rb_cInteger.

Parameters
[in]iArbitrary long value.
Returns
An instance of rb_cInteger.

Definition at line 98 of file len_t.h.

Referenced by RB_CHR2FIX(), and rb_int2num_inline().

◆ rb_len2fix()

static VALUE rb_len2fix ( rb_len_t  i)
inlinestatic

Converts a rb_len_t into an instance of rb_cInteger.

Parameters
[in]iFIXABLE rb_len_t value.
Returns
An instance of rb_cInteger.
Note
Higher bit of i can be silently lost if not in Fixable range.

Definition at line 73 of file len_t.h.

Referenced by RB_INT2FIX().

◆ rb_len2int_inline()

static int rb_len2int_inline ( rb_len_t  n)
inlinestatic

Checks if int can hold the given integer.

Parameters
[in]nArbitrary rb_len_t value.
Exceptions
rb_eRangeError`n` is out of range of `int`.
Returns
Identical value of type int

Definition at line 214 of file len_t.h.

◆ rb_len2long_inline()

static long rb_len2long_inline ( rb_len_t  n)
inlinestatic

Checks if long can hold the given integer.

Parameters
[in]nArbitrary rb_len_t value.
Exceptions
rb_eRangeError`n` is out of range of `long`.
Returns
Identical value of type long

Definition at line 236 of file len_t.h.