1 #ifndef INTERNAL_ARRAY_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_ARRAY_H
5 * @author Ruby developers <ruby-core@ruby-lang.org>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @brief Internal header for Array.
12 #include "ruby/impl/config.h"
13 #include <stddef.h> /* for size_t */
14 #include "internal/static_assert.h" /* for STATIC_ASSERT */
15 #include "ruby/impl/stdbool.h" /* for bool */
16 #include "ruby/ruby.h" /* for RARRAY_LEN */
19 # define ARRAY_DEBUG (0+RUBY_DEBUG)
22 #define RARRAY_PTR_IN_USE_FLAG FL_USER14
25 VALUE
rb_ary_last(int, const VALUE
*, VALUE
);
26 void rb_ary_set_len(VALUE
, long);
27 void rb_ary_delete_same(VALUE
, VALUE
);
28 VALUE
rb_ary_tmp_new_fill(long capa
);
29 VALUE
rb_ary_at(VALUE
, VALUE
);
30 size_t rb_ary_memsize(VALUE
);
31 VALUE
rb_to_array_type(VALUE obj
);
32 static inline VALUE
rb_ary_entry_internal(VALUE ary
, long offset
);
33 static inline bool ARY_PTR_USING_P(VALUE ary
);
34 static inline void RARY_TRANSIENT_SET(VALUE ary
);
35 static inline void RARY_TRANSIENT_UNSET(VALUE ary
);
37 RUBY_SYMBOL_EXPORT_BEGIN
38 /* array.c (export) */
39 void rb_ary_detransient(VALUE a
);
40 VALUE
*rb_ary_ptr_use_start(VALUE ary
);
41 void rb_ary_ptr_use_end(VALUE ary
);
42 RUBY_SYMBOL_EXPORT_END
44 MJIT_SYMBOL_EXPORT_BEGIN
45 VALUE
rb_ary_tmp_new_from_values(VALUE
, long, const VALUE
*);
46 VALUE
rb_check_to_array(VALUE ary
);
47 VALUE
rb_ary_behead(VALUE
, long);
48 VALUE
rb_ary_aref1(VALUE ary
, VALUE i
);
49 MJIT_SYMBOL_EXPORT_END
52 rb_ary_entry_internal(VALUE ary
, long offset
)
54 long len
= RARRAY_LEN(ary
);
55 const VALUE
*ptr
= RARRAY_CONST_PTR_TRANSIENT(ary
);
56 if (len
== 0) return Qnil
;
59 if (offset
< 0) return Qnil
;
61 else if (len
<= offset
) {
68 ARY_PTR_USING_P(VALUE ary
)
70 return FL_TEST_RAW(ary
, RARRAY_PTR_IN_USE_FLAG
);
74 RARY_TRANSIENT_SET(VALUE ary
)
76 #if USE_TRANSIENT_HEAP
77 FL_SET_RAW(ary
, RARRAY_TRANSIENT_FLAG
);
82 RARY_TRANSIENT_UNSET(VALUE ary
)
84 #if USE_TRANSIENT_HEAP
85 FL_UNSET_RAW(ary
, RARRAY_TRANSIENT_FLAG
);
89 #undef rb_ary_new_from_args
90 #if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
91 # /* Skip it; clang -pedantic doesn't like the following */
92 #elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
93 #define rb_ary_new_from_args(n, ...) \
95 const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
96 if (__builtin_constant_p(n)) { \
97 STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
99 rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
103 #endif /* INTERNAL_ARRAY_H */