Ruby 4.1.0dev (2026-10-28 revision b62abdae8b2606aaf4a38fa193f2d04ba1749fdc)
value.h
Go to the documentation of this file.
1#ifndef RBIMPL_VALUE_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_VALUE_H
25#include "ruby/backward/2/limits.h"
26
27#if defined(__DOXYGEN__)
28
40typedef uintptr_t VALUE;
41
52typedef uintptr_t ID;
53
63typedef intptr_t SIGNED_VALUE;
64
69#define SIZEOF_VALUE SIZEOF_UINTPTR_T
70
76#define RBIMPL_VALUE_NULL UINTPTR_C(0)
77
83#define RBIMPL_VALUE_ONE UINTPTR_C(1)
84
90#define RBIMPL_VALUE_FULL UINTPTR_MAX
91
92#elif defined HAVE_UINTPTR_T && 0
93typedef uintptr_t VALUE;
94typedef uintptr_t ID;
95# define SIGNED_VALUE intptr_t
96# define SIZEOF_VALUE SIZEOF_UINTPTR_T
97# undef PRI_VALUE_PREFIX
98# define RBIMPL_VALUE_NULL UINTPTR_C(0)
99# define RBIMPL_VALUE_ONE UINTPTR_C(1)
100# define RBIMPL_VALUE_FULL UINTPTR_MAX
101
102#elif SIZEOF_LONG == SIZEOF_VOIDP
103typedef unsigned long VALUE;
104typedef unsigned long ID;
105# define SIGNED_VALUE long
106# define SIZEOF_VALUE SIZEOF_LONG
107# define PRI_VALUE_PREFIX "l"
108# define RBIMPL_VALUE_NULL 0UL
109# define RBIMPL_VALUE_ONE 1UL
110# define RBIMPL_VALUE_FULL ULONG_MAX
111
112#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
113typedef unsigned LONG_LONG VALUE;
114typedef unsigned LONG_LONG ID;
115# define SIGNED_VALUE LONG_LONG
116# define LONG_LONG_VALUE 1
117# define SIZEOF_VALUE SIZEOF_LONG_LONG
118# define PRI_VALUE_PREFIX PRI_LL_PREFIX
119# define RBIMPL_VALUE_NULL 0ULL
120# define RBIMPL_VALUE_ONE 1ULL
121# define RBIMPL_VALUE_FULL ULLONG_MAX
122
123#else
124# error ---->> ruby requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<----
125#endif
126
127#if defined(SIZEOF_RB_LEN_T) && SIZEOF_RB_LEN_T > SIZEOF_LONG
128/* mswin, where long is narrower than a pointer and config.h asks for more. */
129# include <stdint.h>
130typedef int64_t rb_len_t;
131typedef uint64_t rb_ulen_t;
132# define PRI_LEN_PREFIX PRI_64_PREFIX
133# define RB_LEN_MAX INT64_MAX
134# define RB_LEN_MIN INT64_MIN
135# define RB_ULEN_MAX UINT64_MAX
136
137#else
142typedef long rb_len_t;
143
145typedef unsigned long rb_ulen_t;
146
147# ifndef SIZEOF_RB_LEN_T
149# define SIZEOF_RB_LEN_T SIZEOF_LONG
150# endif
151
153# define PRI_LEN_PREFIX "l"
154
156# define RB_LEN_MAX LONG_MAX
157
159# define RB_LEN_MIN LONG_MIN
160
162# define RB_ULEN_MAX ULONG_MAX
163#endif
164
166#define HAVE_RB_LEN_T 1
167
169RBIMPL_STATIC_ASSERT(sizeof_int, SIZEOF_INT == sizeof(int));
170RBIMPL_STATIC_ASSERT(sizeof_long, SIZEOF_LONG == sizeof(long));
171RBIMPL_STATIC_ASSERT(sizeof_long_long, SIZEOF_LONG_LONG == sizeof(LONG_LONG));
172RBIMPL_STATIC_ASSERT(sizeof_voidp, SIZEOF_VOIDP == sizeof(void *));
173RBIMPL_STATIC_ASSERT(sizeof_rb_len_t_macro, SIZEOF_RB_LEN_T == sizeof(rb_len_t));
174RBIMPL_STATIC_ASSERT(sizeof_rb_len_t, sizeof(rb_len_t) <= SIZEOF_VALUE);
175RBIMPL_STATIC_ASSERT(sizeof_rb_ulen_t, sizeof(rb_ulen_t) == sizeof(rb_len_t));
177#endif /* RBIMPL_VALUE_H */
Defines old LONG_LONG.
#define LONG_LONG
Definition long_long.h:38
Defines RBIMPL_STATIC_ASSERT.
#define RBIMPL_STATIC_ASSERT
Wraps (or simulates) static_assert
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
Definition value.h:142
#define SIZEOF_RB_LEN_T
Size of rb_len_t, in bytes.
Definition value.h:149
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
Definition value.h:63
unsigned long rb_ulen_t
An unsigned integer type that has the same width with rb_len_t.
Definition value.h:145
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
#define SIZEOF_VALUE
Identical to sizeof(VALUE), except it is a macro that can also be used inside of preprocessor directi...
Definition value.h:69
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40