Ruby  3.4.0dev (2024-11-22 revision 37a72b0150ec36b4ea27175039afc28c62207b0c)
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
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
58 static inline VALUE
59 RB_ST2FIX(st_data_t i)
60 {
61  SIGNED_VALUE x = RBIMPL_CAST((SIGNED_VALUE)i);
62 
63  if (x >= 0) {
64  x &= RUBY_FIXNUM_MAX;
65  }
66  else {
67  x |= RUBY_FIXNUM_MIN;
68  }
69 
71  unsigned long y = RBIMPL_CAST((unsigned long)x);
72  return RB_LONG2FIX(RBIMPL_CAST((long)y));
73 }
74 
75 #endif /* RBIMPL_ARITHMETIC_ST_DATA_T_H */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:41
#define RBIMPL_ASSERT_OR_ASSUME(...)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition: assert.h:311
Defines RBIMPL_ATTR_CONST.
#define RBIMPL_ATTR_CONST_UNLESS_DEBUG()
Enables RBIMPL_ATTR_CONST if and only if.
Definition: const.h:41
RBIMPL_ATTR_CONSTEXPR.
#define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_)
Enables RBIMPL_ATTR_CONSTEXPR if and only if.
Definition: constexpr.h:79
Handling of integers formerly known as Fixnums.
#define RB_FIXABLE(_)
Checks if the passed value is in range of fixnum.
Definition: fixnum.h:52
#define RUBY_FIXNUM_MAX
Maximum possible value that a fixnum can represent.
Definition: fixnum.h:55
#define RUBY_FIXNUM_MIN
Minimum possible value that a fixnum can represent.
Definition: fixnum.h:58
Arithmetic conversion between C's long and Ruby's.
#define RB_LONG2FIX
Just another name of RB_INT2FIX.
Definition: long.h:55
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition: defines.h:88
static VALUE RB_ST2FIX(st_data_t i)
Converts a C's st_data_t into an instance of rb_cInteger.
Definition: st_data_t.h:59
Defines VALUE and ID.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
Definition: value.h:63
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40