Remove duplicate declarations
[ruby.git] / internal / array.h
blob97b707f271e074384d409359d7d3a40a1ef6da83
1 #ifndef INTERNAL_ARRAY_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_ARRAY_H
3 /**
4 * @file
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/internal/config.h"
13 #include <stddef.h> /* for size_t */
14 #include "internal/static_assert.h" /* for STATIC_ASSERT */
15 #include "ruby/internal/stdbool.h" /* for bool */
16 #include "ruby/ruby.h" /* for RARRAY_LEN */
18 #ifndef ARRAY_DEBUG
19 # define ARRAY_DEBUG (0+RUBY_DEBUG)
20 #endif
22 #define RARRAY_PTR_IN_USE_FLAG FL_USER14
24 /* array.c */
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 VALUE rb_to_array(VALUE obj);
33 void rb_ary_cancel_sharing(VALUE ary);
35 static inline VALUE rb_ary_entry_internal(VALUE ary, long offset);
36 static inline bool ARY_PTR_USING_P(VALUE ary);
37 static inline void RARY_TRANSIENT_SET(VALUE ary);
38 static inline void RARY_TRANSIENT_UNSET(VALUE ary);
40 RUBY_SYMBOL_EXPORT_BEGIN
41 /* array.c (export) */
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);
50 struct rb_execution_context_struct;
51 VALUE rb_ec_ary_new_from_values(struct rb_execution_context_struct *ec, long n, const VALUE *elts);
52 MJIT_SYMBOL_EXPORT_END
54 static inline VALUE
55 rb_ary_entry_internal(VALUE ary, long offset)
57 long len = RARRAY_LEN(ary);
58 const VALUE *ptr = RARRAY_CONST_PTR_TRANSIENT(ary);
59 if (len == 0) return Qnil;
60 if (offset < 0) {
61 offset += len;
62 if (offset < 0) return Qnil;
64 else if (len <= offset) {
65 return Qnil;
67 return ptr[offset];
70 static inline bool
71 ARY_PTR_USING_P(VALUE ary)
73 return FL_TEST_RAW(ary, RARRAY_PTR_IN_USE_FLAG);
76 static inline void
77 RARY_TRANSIENT_SET(VALUE ary)
79 #if USE_TRANSIENT_HEAP
80 FL_SET_RAW(ary, RARRAY_TRANSIENT_FLAG);
81 #endif
84 static inline void
85 RARY_TRANSIENT_UNSET(VALUE ary)
87 #if USE_TRANSIENT_HEAP
88 FL_UNSET_RAW(ary, RARRAY_TRANSIENT_FLAG);
89 #endif
92 #undef rb_ary_new_from_args
93 #if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
94 # /* Skip it; clang -pedantic doesn't like the following */
95 #elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
96 #define rb_ary_new_from_args(n, ...) \
97 __extension__ ({ \
98 const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
99 if (__builtin_constant_p(n)) { \
100 STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
102 rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
104 #endif
106 #undef RARRAY_AREF
107 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
108 RBIMPL_ATTR_ARTIFICIAL()
109 static inline VALUE
110 RARRAY_AREF(VALUE ary, long i)
112 RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
114 return RARRAY_CONST_PTR_TRANSIENT(ary)[i];
117 #endif /* INTERNAL_ARRAY_H */