1 #ifndef INTERNAL_ARRAY_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_ARRAY_H
4 * @author Ruby developers <ruby-core@ruby-lang.org>
5 * @copyright This file is a part of the programming language Ruby.
6 * Permission is hereby granted, to either redistribute and/or
7 * modify this file, provided that the conditions mentioned in the
8 * file COPYING are met. Consult the file for details.
9 * @brief Internal header for Array.
11 #include "ruby/internal/config.h"
12 #include <stddef.h> /* for size_t */
13 #include "internal/static_assert.h" /* for STATIC_ASSERT */
14 #include "ruby/internal/stdbool.h" /* for bool */
15 #include "ruby/ruby.h" /* for RARRAY_LEN */
18 # define ARRAY_DEBUG (0+RUBY_DEBUG)
21 #define RARRAY_PTR_IN_USE_FLAG FL_USER14
24 VALUE
rb_ary_last(int, const VALUE
*, VALUE
);
25 void rb_ary_set_len(VALUE
, long);
26 void rb_ary_delete_same(VALUE
, VALUE
);
27 VALUE
rb_ary_tmp_new_fill(long capa
);
28 VALUE
rb_ary_at(VALUE
, VALUE
);
29 size_t rb_ary_memsize(VALUE
);
30 VALUE
rb_to_array_type(VALUE obj
);
31 VALUE
rb_to_array(VALUE obj
);
32 void rb_ary_cancel_sharing(VALUE ary
);
34 static inline VALUE
rb_ary_entry_internal(VALUE ary
, long offset
);
35 static inline bool ARY_PTR_USING_P(VALUE ary
);
36 static inline void RARY_TRANSIENT_SET(VALUE ary
);
37 static inline void RARY_TRANSIENT_UNSET(VALUE ary
);
39 MJIT_SYMBOL_EXPORT_BEGIN
40 VALUE
rb_ary_tmp_new_from_values(VALUE
, long, const VALUE
*);
41 VALUE
rb_check_to_array(VALUE ary
);
42 VALUE
rb_ary_behead(VALUE
, long);
43 VALUE
rb_ary_aref1(VALUE ary
, VALUE i
);
45 struct rb_execution_context_struct
;
46 VALUE
rb_ec_ary_new_from_values(struct rb_execution_context_struct
*ec
, long n
, const VALUE
*elts
);
47 MJIT_SYMBOL_EXPORT_END
50 rb_ary_entry_internal(VALUE ary
, long offset
)
52 long len
= RARRAY_LEN(ary
);
53 const VALUE
*ptr
= RARRAY_CONST_PTR_TRANSIENT(ary
);
54 if (len
== 0) return Qnil
;
57 if (offset
< 0) return Qnil
;
59 else if (len
<= offset
) {
66 ARY_PTR_USING_P(VALUE ary
)
68 return FL_TEST_RAW(ary
, RARRAY_PTR_IN_USE_FLAG
);
72 RARY_TRANSIENT_SET(VALUE ary
)
74 #if USE_TRANSIENT_HEAP
75 FL_SET_RAW(ary
, RARRAY_TRANSIENT_FLAG
);
80 RARY_TRANSIENT_UNSET(VALUE ary
)
82 #if USE_TRANSIENT_HEAP
83 FL_UNSET_RAW(ary
, RARRAY_TRANSIENT_FLAG
);
87 #undef rb_ary_new_from_args
88 #if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
89 # /* Skip it; clang -pedantic doesn't like the following */
90 #elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
91 #define rb_ary_new_from_args(n, ...) \
93 const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
94 if (__builtin_constant_p(n)) { \
95 STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
97 rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
102 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
103 RBIMPL_ATTR_ARTIFICIAL()
105 RARRAY_AREF(VALUE ary
, long i
)
107 RBIMPL_ASSERT_TYPE(ary
, RUBY_T_ARRAY
);
109 return RARRAY_CONST_PTR_TRANSIENT(ary
)[i
];
112 #endif /* INTERNAL_ARRAY_H */