Ruby: include/ruby/internal/arithmetic/st_data_t.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

st_data_t.h
Go to the documentation of this file.
1#ifndef RBIMPL_ARITHMERIC_ST_DATA_T_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_ARITHMERIC_ST_DATA_T_H
23#include "ruby/internal/arithmetic/fixnum.h"
24#include "ruby/internal/arithmetic/long.h"
25#include "ruby/internal/attr/artificial.h"
26#include "ruby/internal/attr/const.h"
27#include "ruby/internal/attr/constexpr.h"
28#include "ruby/internal/cast.h"
29#include "ruby/internal/value.h"
30#include "ruby/assert.h"
31#include "ruby/st.h"
32
33#define ST2FIX RB_ST2FIX
35#define RB_ST2FIX RB_ST2FIX
38 RBIMPL_ATTR_CONST_UNLESS_DEBUG()
39 RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
40 RBIMPL_ATTR_ARTIFICIAL()
41/* See also [ruby-core:84395] [Bug #14218] [ruby-core:82687] [Bug #13877] */
42static inline VALUE
43 RB_ST2FIX(st_data_t i)
44{
45 SIGNED_VALUE x = i;
46
47 if (x >= 0) {
48 x &= RUBY_FIXNUM_MAX;
49 }
50 else {
51 x |= RUBY_FIXNUM_MIN;
52 }
53
54 RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(x));
55 unsigned long y = RBIMPL_CAST((unsigned long)x);
56 return RB_LONG2FIX(y);
57}
58
59#endif /* RBIMPL_ARITHMERIC_ST_DATA_T_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:43
assert.h
RBIMPL_ASSERT_OR_ASSUME
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition: assert.h:229
cast.h
Defines RBIMPL_CAST.
const.h
Defines RBIMPL_ATTR_CONST.
RBIMPL_ATTR_CONST_UNLESS_DEBUG
#define RBIMPL_ATTR_CONST_UNLESS_DEBUG()
Enables RBIMPL_ATTR_CONST iff.
Definition: const.h:41
constexpr.h
RBIMPL_ATTR_CONSTEXPR.
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG
#define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_)
Enables RBIMPL_ATTR_CONSTEXPR iff.
Definition: constexpr.h:80
fixnum.h
Handling of integers formerly known as Fixnums.
RB_FIXABLE
#define RB_FIXABLE(_)
Definition: fixnum.h:40
RUBY_FIXNUM_MAX
#define RUBY_FIXNUM_MAX
Definition: fixnum.h:41
RUBY_FIXNUM_MIN
#define RUBY_FIXNUM_MIN
Definition: fixnum.h:42
long.h
Arithmetic conversion between C's long and Ruby's.
RB_LONG2FIX
#define RB_LONG2FIX
Definition: long.h:55
RB_ST2FIX
#define RB_ST2FIX(h)
Definition: ruby_missing.h:20
st.h
st_data_t
unsigned long st_data_t
Definition: st.h:22
value.h
Defines VALUE and ID.
VALUE
unsigned long VALUE
Definition: value.h:38
SIGNED_VALUE
#define SIGNED_VALUE
Definition: value.h:40