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
28void rb_ary_set_len(
VALUE,
long);
32size_t rb_ary_memsize(
VALUE);
35void rb_ary_cancel_sharing(
VALUE ary);
36size_t rb_ary_size_as_embedded(
VALUE ary);
37void rb_ary_make_embedded(
VALUE ary);
38bool rb_ary_embeddable_p(
VALUE ary);
41static inline VALUE rb_ary_entry_internal(
VALUE ary,
long offset);
42static inline bool ARY_PTR_USING_P(
VALUE ary);
54rb_ary_entry_internal(
VALUE ary,
long offset)
61 if (offset < 0)
return Qnil;
63 else if (
len <= offset) {
70ARY_PTR_USING_P(
VALUE ary)
77ary_should_not_be_shared_and_embedded(
VALUE ary)
79 return !
FL_ALL_RAW(ary, RARRAY_SHARED_FLAG|RARRAY_EMBED_FLAG);
83ARY_SHARED_P(
VALUE ary)
85 assert(RB_TYPE_P(ary,
T_ARRAY));
86 assert(ary_should_not_be_shared_and_embedded(ary));
93 assert(RB_TYPE_P(ary,
T_ARRAY));
94 assert(ary_should_not_be_shared_and_embedded(ary));
99ARY_SHARED_ROOT(
VALUE ary)
101 assert(ARY_SHARED_P(ary));
102 return RARRAY(ary)->as.heap.aux.shared_root;
106ARY_SHARED_ROOT_P(
VALUE ary)
108 assert(RB_TYPE_P(ary,
T_ARRAY));
113ARY_SHARED_ROOT_REFCNT(
VALUE ary)
115 assert(ARY_SHARED_ROOT_P(ary));
116 return RARRAY(ary)->as.heap.aux.capa;
119#undef rb_ary_new_from_args
120#if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
122#elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
123#define rb_ary_new_from_args(n, ...) \
125 const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
126 if (__builtin_constant_p(n)) { \
127 STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
129 rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
143#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 13
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#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 inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
#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.
#define RBIMPL_WARNING_IGNORED(flag)
Suppresses a warning.
#define RBIMPL_WARNING_PUSH()
Pushes compiler warning state.
#define RBIMPL_WARNING_POP()
Pops compiler warning state.