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 {
134#if USE_TRANSIENT_HEAP
157enum ruby_rarray_consts {
199#if defined(__clang__) || \
200 !defined(__cplusplus) || \
201 (__cplusplus > 199711L)
235VALUE *rb_ary_ptr_use_start(VALUE ary);
246void rb_ary_ptr_use_end(VALUE a);
248#if USE_TRANSIENT_HEAP
283 VALUE f =
RBASIC(ary)->flags;
284 f &= RARRAY_EMBED_LEN_MASK;
286 return RBIMPL_CAST((
long)f);
306 return RARRAY(a)->as.heap.len;
349#if USE_TRANSIENT_HEAP
366static inline const VALUE *
367rb_array_const_ptr_transient(VALUE a)
372 return FIX_CONST_VALUE_PTR(
RARRAY(a)->as.ary);
375 return FIX_CONST_VALUE_PTR(
RARRAY(a)->as.heap.ptr);
379#if ! USE_TRANSIENT_HEAP
392static inline const VALUE *
393rb_array_const_ptr(VALUE a)
397#if USE_TRANSIENT_HEAP
402 return rb_array_const_ptr_transient(a);
417rb_array_ptr_use_start(VALUE a,
423#if USE_TRANSIENT_HEAP
424 if (!allow_transient) {
431 return rb_ary_ptr_use_start(a);
444rb_array_ptr_use_end(VALUE a,
449 rb_ary_ptr_use_end(a);
458#define RBIMPL_RARRAY_STMT(flag, ary, var, expr) do { \
459 RBIMPL_ASSERT_TYPE((ary), RUBY_T_ARRAY); \
460 const VALUE rbimpl_ary = (ary); \
461 VALUE *var = rb_array_ptr_use_start(rbimpl_ary, (flag)); \
463 rb_array_ptr_use_end(rbimpl_ary, (flag)); \
472#define RARRAY_PTR_USE_START(a) rb_array_ptr_use_start(a, 0)
480#define RARRAY_PTR_USE_END(a) rb_array_ptr_use_end(a, 0)
507#define RARRAY_PTR_USE(ary, ptr_name, expr) \
508 RBIMPL_RARRAY_STMT(0, ary, ptr_name, expr)
516#define RARRAY_PTR_USE_START_TRANSIENT(a) rb_array_ptr_use_start(a, 1)
524#define RARRAY_PTR_USE_END_TRANSIENT(a) rb_array_ptr_use_end(a, 1)
533#define RARRAY_PTR_USE_TRANSIENT(ary, ptr_name, expr) \
534 RBIMPL_RARRAY_STMT(1, ary, ptr_name, expr)
588#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.
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_ANY().
@ RUBY_FL_USER3
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 RARRAY_EMBED_LEN(VALUE ary)
Queries the length of the array.
void rb_ary_detransient(VALUE a)
Destructively converts an array of transient backend into ordinal one.
static long rb_array_len(VALUE a)
Queries the length of the array.
#define RARRAY(obj)
Convenient casting macro.
static bool RARRAY_TRANSIENT_P(VALUE ary)
Queries if the array is a transient array.
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
static void RARRAY_ASET(VALUE ary, long i, VALUE v)
Assigns an object in an array.
static VALUE * RARRAY_PTR(VALUE ary)
Wild use of a C pointer.
@ 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.
struct RBasic basic
Basic part, including flags and class.
const VALUE shared_root
Parent of the array.
const VALUE ary[RARRAY_EMBED_LEN_MAX]
Embedded elements.
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.
Defines enum ruby_value_type.