28#include "ruby/internal/cast.h"
46#ifndef USE_TRANSIENT_HEAP
47# define USE_TRANSIENT_HEAP 1
56#define RARRAY(obj) RBIMPL_CAST((struct RArray *)(obj))
58#define RARRAY_EMBED_FLAG RARRAY_EMBED_FLAG
59#define RARRAY_EMBED_LEN_MASK RARRAY_EMBED_LEN_MASK
60#define RARRAY_EMBED_LEN_MAX RARRAY_EMBED_LEN_MAX
61#define RARRAY_EMBED_LEN_SHIFT RARRAY_EMBED_LEN_SHIFT
63# define RARRAY_TRANSIENT_FLAG RARRAY_TRANSIENT_FLAG
65# define RARRAY_TRANSIENT_FLAG 0
68#define RARRAY_LEN rb_array_len
69#define RARRAY_CONST_PTR rb_array_const_ptr
70#define RARRAY_CONST_PTR_TRANSIENT rb_array_const_ptr_transient
73#if defined(__fcc__) || defined(__fcc_version) || \
74 defined(__FCC__) || defined(__FCC_VERSION)
76# define FIX_CONST_VALUE_PTR(x) ((const VALUE *)(x))
78# define FIX_CONST_VALUE_PTR(x) (x)
81#define RARRAY_EMBED_LEN RARRAY_EMBED_LEN
82#define RARRAY_LENINT RARRAY_LENINT
83#define RARRAY_TRANSIENT_P RARRAY_TRANSIENT_P
84#define RARRAY_ASET RARRAY_ASET
85#define RARRAY_PTR RARRAY_PTR
101enum ruby_rarray_flags {
140#if USE_TRANSIENT_HEAP
209#if defined(__clang__) || \
210 !defined(__cplusplus) || \
211 (__cplusplus > 199711L)
239 const VALUE ary[RARRAY_EMBED_LEN_MAX];
265void rb_ary_ptr_use_end(
VALUE a);
267#if USE_TRANSIENT_HEAP
275void rb_ary_detransient(
VALUE a);
303 f &= RARRAY_EMBED_LEN_MASK;
305 return RBIMPL_CAST((
long)f);
321 if (RB_FL_ANY_RAW(a, RARRAY_EMBED_FLAG)) {
322 return RARRAY_EMBED_LEN(a);
325 return RARRAY(a)->as.heap.len;
368#if USE_TRANSIENT_HEAP
369 return RB_FL_ANY_RAW(ary, RARRAY_TRANSIENT_FLAG);
385static inline const
VALUE *
386rb_array_const_ptr_transient(
VALUE a)
390 if (RB_FL_ANY_RAW(a, RARRAY_EMBED_FLAG)) {
391 return FIX_CONST_VALUE_PTR(
RARRAY(a)->as.ary);
394 return FIX_CONST_VALUE_PTR(
RARRAY(a)->as.heap.ptr);
398#if ! USE_TRANSIENT_HEAP
411static inline const VALUE *
412rb_array_const_ptr(
VALUE a)
416#if USE_TRANSIENT_HEAP
417 if (RARRAY_TRANSIENT_P(a)) {
418 rb_ary_detransient(a);
421 return rb_array_const_ptr_transient(a);
436rb_array_ptr_use_start(
VALUE a,
442#if USE_TRANSIENT_HEAP
443 if (!allow_transient) {
444 if (RARRAY_TRANSIENT_P(a)) {
445 rb_ary_detransient(a);
450 return rb_ary_ptr_use_start(a);
463rb_array_ptr_use_end(
VALUE a,
468 rb_ary_ptr_use_end(a);
477#define RBIMPL_RARRAY_STMT(flag, ary, var, expr) do { \
478 RBIMPL_ASSERT_TYPE((ary), RUBY_T_ARRAY); \
479 const VALUE rbimpl_ary = (ary); \
480 VALUE *var = rb_array_ptr_use_start(rbimpl_ary, (flag)); \
482 rb_array_ptr_use_end(rbimpl_ary, (flag)); \
491#define RARRAY_PTR_USE_END(a) rb_array_ptr_use_end(a, 0)
518#define RARRAY_PTR_USE(ary, ptr_name, expr) \
519 RBIMPL_RARRAY_STMT(0, ary, ptr_name, expr)
528#define RARRAY_PTR_USE_TRANSIENT(ary, ptr_name, expr) \
529 RBIMPL_RARRAY_STMT(1, ary, ptr_name, expr)
583#define RARRAY_AREF(a, i) RARRAY_CONST_PTR_TRANSIENT(a)[i]
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Defines enum ruby_fl_type.
@ RUBY_FL_USHIFT
Number of bits in ruby_fl_type that are not open to users.
@ RUBY_FL_USER9
User-defined flag.
@ RUBY_FL_USER8
User-defined flag.
@ RUBY_FL_USER5
User-defined flag.
@ RUBY_FL_USER3
User-defined flag.
@ RUBY_FL_USER7
User-defined flag.
@ RUBY_FL_USER6
User-defined flag.
@ RUBY_FL_USER4
User-defined flag.
@ RUBY_FL_USER1
User-defined flag.
@ RUBY_FL_USER13
User-defined flag.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
Arithmetic conversion between C's long and Ruby's.
#define rb_long2int
Just another name of rb_long2int_inline.
Defines RBIMPL_ATTR_MAYBE_UNUSED.
#define RBIMPL_ATTR_MAYBE_UNUSED()
Wraps (or simulates) [[maybe_unused]]
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
#define RARRAY_LEN
Just another name of rb_array_len.
static long rb_array_len(VALUE a)
Queries the length of the array.
#define RARRAY(obj)
Convenient casting macro.
ruby_rarray_consts
This is an enum because GDB wants it (rather than a macro).
@ RARRAY_EMBED_LEN_MAX
Max possible number elements that can be embedded.
@ RARRAY_EMBED_LEN_SHIFT
Where RARRAY_EMBED_LEN_MASK resides.
#define RARRAY_PTR_USE_TRANSIENT(ary, ptr_name, expr)
Identical to RARRAY_PTR_USE, except the pointer can be a transient one.
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define RBASIC(obj)
Convenient casting macro.
RGENGC write-barrier APIs.
#define RB_OBJ_WB_UNPROTECT_FOR(type, obj)
Identical to RB_OBJ_WB_UNPROTECT(), except it can also assert that the given object is of given type.
union RArray::@45 as
Array's specific fields.
struct RBasic basic
Basic part, including flags and class.
const VALUE shared_root
Parent of the array.
long capa
Capacity of *ptr.
long len
Number of elements of the array.
const VALUE * ptr
Pointer to the C array that holds the elements of the array.
Ruby's object's, base components.
uintptr_t VALUE
Type that represents a Ruby object.
Defines enum ruby_value_type.