1#ifndef INTERNAL_ARRAY_H
2#define INTERNAL_ARRAY_H
11#include "ruby/internal/config.h"
13#include "internal/static_assert.h"
18# define ARRAY_DEBUG (0+RUBY_DEBUG)
21#define RARRAY_SHARED_FLAG ELTS_SHARED
22#define RARRAY_SHARED_ROOT_FLAG FL_USER12
23#define RARRAY_PTR_IN_USE_FLAG FL_USER14
24#define RARRAY_FAKEARY FL_USER19
29void rb_ary_set_len(
VALUE,
long);
33size_t rb_ary_memsize(
VALUE);
36void rb_ary_cancel_sharing(
VALUE ary);
37size_t rb_ary_size_as_embedded(
VALUE ary);
38void rb_ary_make_embedded(
VALUE ary);
39bool rb_ary_embeddable_p(
VALUE ary);
40bool rb_ary_embedded_shared_root_p(
VALUE ary);
43VALUE rb_ary_modify_expand(
VALUE ary,
long expand);
46static inline VALUE rb_ary_entry_internal(
VALUE ary,
long offset);
47static inline bool ARY_PTR_USING_P(
VALUE ary);
59rb_ary_entry_internal(
VALUE ary,
long offset)
66 if (offset < 0)
return Qnil;
68 else if (
len <= offset) {
75ARY_PTR_USING_P(
VALUE ary)
82ary_should_not_be_shared_and_embedded(
VALUE ary)
84 return !
FL_ALL_RAW(ary, RARRAY_SHARED_FLAG|RARRAY_EMBED_FLAG);
88ARY_SHARED_P(
VALUE ary)
91 assert(ary_should_not_be_shared_and_embedded(ary));
99 assert(ary_should_not_be_shared_and_embedded(ary));
104ARY_SHARED_ROOT(
VALUE ary)
106 assert(ARY_SHARED_P(ary));
107 return RARRAY(ary)->as.heap.aux.shared_root;
111ARY_SHARED_ROOT_P(
VALUE ary)
118ARY_SHARED_ROOT_REFCNT(
VALUE ary)
120 assert(ARY_SHARED_ROOT_P(ary));
121 return RARRAY(ary)->as.heap.aux.capa;
124#undef rb_ary_new_from_args
125#if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
127#elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
128#define rb_ary_new_from_args(n, ...) \
130 const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
131 if (__builtin_constant_p(n)) { \
132 STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
134 rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
150#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 13
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define RUBY_EXTERN
Declaration of externally visible global variables.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define Qnil
Old name of RUBY_Qnil.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define FL_ALL_RAW
Old name of RB_FL_ALL_RAW.
int capa
Designed capacity of the buffer.
int len
Length of the buffer.
#define RBIMPL_ATTR_MAYBE_UNUSED()
Wraps (or simulates) [[maybe_unused]]
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY(obj)
Convenient casting macro.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
#define RBIMPL_WARNING_IGNORED(flag)
Suppresses a warning.
#define RBIMPL_WARNING_PUSH()
Pushes compiler warning state.
#define RBIMPL_WARNING_POP()
Pops compiler warning state.