Debian Codegraph @

include/ruby/internal/intern/array.h

raw
1 #ifndef RBIMPL_INTERN_ARRAY_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_INTERN_ARRAY_H
3 /**
4 * @file
5 * @author Ruby developers <[email protected]>
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 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11 * implementation details. Don't take them as canon. They could
12 * rapidly appear then vanish. The name (path) of this header file
13 * is also an implementation detail. Do not expect it to persist
14 * at the place it is now. Developers are free to move it anywhere
15 * anytime at will.
16 * @note To ruby-core: remember that this header can be possibly
17 * recursively included from extension libraries written in C++.
18 * Do not expect for instance `__VA_ARGS__` is always available.
19 * We assume C99 for ruby itself but we don't assume languages of
20 * extension libraries. They could be written in C++98.
21 * @brief Public APIs related to ::rb_cArray.
22 */
23 #include "ruby/internal/attr/noalias.h"
24 #include "ruby/internal/attr/noexcept.h"
25 #include "ruby/internal/attr/nonnull.h"
26 #include "ruby/internal/attr/pure.h"
27 #include "ruby/internal/dllexport.h"
28 #include "ruby/internal/value.h"
29
30 RBIMPL_SYMBOL_EXPORT_BEGIN()
31
32 /* array.c */
33
34 RBIMPL_ATTR_NONNULL(())
35 RBIMPL_ATTR_NOALIAS()
36 /**
37 * Fills the memory region with a series of ::RUBY_Qnil.
38 *
39 * @param[out] buf Buffer to squash.
40 * @param[in] len Number of objects of `buf`.
41 * @post `buf` is filled with ::RUBY_Qnil.
42 */
43 void rb_mem_clear(VALUE *buf, long len)
44 RBIMPL_ATTR_NOEXCEPT(true)
45 ;
46
47 /**
48 * Identical to rb_ary_new_from_values(), except it expects exactly two
49 * parameters.
50 *
51 * @param[in] car Arbitrary ruby object.
52 * @param[in] cdr Arbitrary ruby object.
53 * @return An allocated new array, of length 2, whose contents are the
54 * passed objects.
55 */
56 VALUE rb_assoc_new(VALUE car, VALUE cdr);
57
58 /**
59 * Try converting an object to its array representation using its `to_ary`
60 * method, if any. If there is no such thing, returns ::RUBY_Qnil.
61 *
62 * @param[in] obj Arbitrary ruby object to convert.
63 * @exception rb_eTypeError `obj.to_ary` returned something non-Array.
64 * @retval RUBY_Qnil No conversion from `obj` to array defined.
65 * @retval otherwise Converted array representation of `obj`.
66 * @see rb_io_check_io
67 * @see rb_check_string_type
68 * @see rb_check_hash_type
69 */
70 VALUE rb_check_array_type(VALUE obj);
71
72 /**
73 * Allocates a new, empty array.
74 *
75 * @return An allocated new array, whose length is 0.
76 */
77 VALUE rb_ary_new(void);
78
79 /**
80 * Identical to rb_ary_new(), except it additionally specifies how many rooms
81 * of objects it should allocate. This way you can create an array whose
82 * capacity is bigger than the length of it. If you can say that an array
83 * grows to a specific amount, this could be effective than resizing an array
84 * over and over again and again.
85 *
86 * @param[in] capa Designed capacity of the generating array.
87 * @return An empty array, whose capacity is `capa`.
88 */
89 VALUE rb_ary_new_capa(long capa);
90
91 /**
92 * Constructs an array from the passed objects.
93 *
94 * @param[in] n Number of passed objects.
95 * @param[in] ... Arbitrary ruby objects, filled into the returning array.
96 * @return An array of size `n`, whose contents are the passed objects.
97 */
98 VALUE rb_ary_new_from_args(long n, ...);
99
100 /**
101 * Identical to rb_ary_new_from_args(), except how objects are passed.
102 *
103 * @param[in] n Number of objects of `elts`.
104 * @param[in] elts Arbitrary ruby objects, filled into the returning array.
105 * @return An array of size `n`, whose contents are the passed objects.
106 */
107 VALUE rb_ary_new_from_values(long n, const VALUE *elts);
108
109 /**
110 * Allocates a hidden (no class) empty array.
111 *
112 * @param[in] capa Designed capacity of the array.
113 * @return A hidden, empty array.
114 * @see rb_obj_hide()
115 */
116 VALUE rb_ary_hidden_new(long capa);
117 #define rb_ary_tmp_new rb_ary_hidden_new
118
119 /**
120 * Destroys the given array for no reason.
121 *
122 * @warning DO NOT USE IT.
123 * @warning Leave this task to our GC.
124 * @warning It was a wrong indea at the first place to let you know about it.
125 *
126 * @param[out] ary The array to be executed.
127 * @post The given array no longer exists.
128 * @note Maybe `Array#clear` could be what you want.
129 *
130 * @internal
131 *
132 * Should have moved this to `internal/array.h`.
133 */
134 void rb_ary_free(VALUE ary);
135
136 /**
137 * Declares that the array is about to be modified. This for instance let the
138 * array have a dedicated backend storage.
139 *
140 * @param[out] ary Array about to be modified.
141 * @exception rb_eFrozenError `ary` is frozen.
142 * @post Upon successful return the passed array is eligible to be
143 * modified.
144 */
145 void rb_ary_modify(VALUE ary);
146
147 /** @alias{rb_obj_freeze} */
148 VALUE rb_ary_freeze(VALUE obj);
149
150 RBIMPL_ATTR_PURE()
151 /**
152 * Queries if the passed two arrays share the same backend storage. A use-case
153 * for knowing such property is to take a snapshot of an array (using
154 * e.g. rb_ary_replace()), then check later if that snapshot still shares the
155 * storage with the original. Taking a snapshot is ultra-cheap. If nothing
156 * happens the impact shall be minimal. But if someone modifies the original,
157 * that entity shall pay the cost of copy-on-write. You can detect that using
158 * this API.
159 *
160 * @param[in] lhs Comparison LHS.
161 * @param[in] rhs Comparison RHS.
162 * @retval RUBY_Qtrue They share the same backend storage.
163 * @retval RUBY_Qfalse They are distinct.
164 * @pre Both arguments must be of ::RUBY_T_ARRAY.
165 */
166 VALUE rb_ary_shared_with_p(VALUE lhs, VALUE rhs);
167
168 /**
169 * Queries element(s) of an array. This is complicated! Refer `Array#slice`
170 * document for the complete description of how it behaves.
171 *
172 * @param[in] argc Number of objects of `argv`.
173 * @param[in] argv Up to 2 objects.
174 * @param[in] ary Target array.
175 * @exception rb_eTypeError `argv` (or its part) includes non-Integer.
176 * @exception rb_eRangeError rb_cArithSeq is passed, and is OOB.
177 * @return An element (if requested), or an array of elements (if
178 * requested), or ::RUBY_Qnil (if index OOB).
179 *
180 * @internal
181 *
182 * ```rbs
183 * # "int" is ::Integer or `#to_int`, defined in builtin.rbs
184 *
185 * class ::Array[unchecked out T]
186 * def slice
187 * : (int i) -> T?
188 * | (int beg, int len) -> ::Array[T]?
189 * | (Range[int] r) -> ::Array[T]?
190 * | (ArithmeticSequence as) -> ::Array[T]? # This also raises RangeError.
191 * end
192 * ```
193 */
194 VALUE rb_ary_aref(int argc, const VALUE *argv, VALUE ary);
195
196 /**
197 * Obtains a part of the passed array.
198 *
199 * @param[in] ary Target array.
200 * @param[in] beg Subpart index.
201 * @param[in] len Requested length of returning array.
202 * @retval RUBY_Qnil Requested range out of bounds of `ary`.
203 * @retval otherwise An allocated new array whose contents are `ary`'s
204 * `beg` to `len`.
205 * @note Return array can be shorter than `len` when for instance
206 * `[0, 1, 2, 3]`'s 4th to 1,000,000,000th is requested.
207 */
208 VALUE rb_ary_subseq(VALUE ary, long beg, long len);
209
210 /**
211 * Destructively stores the passed value to the passed array's passed index.
212 * It also resizes the array's backend storage so that the requested index is
213 * not out of bounds.
214 *
215 * @param[out] ary Target array to modify.
216 * @param[in] key Where to store `val`.
217 * @param[in] val What to store at `key`.
218 * @exception rb_eFrozenError `ary` is frozen.
219 * @exception rb_eIndexError `key` is negative.
220 * @post `ary`'s `key`th position is occupied with `val`.
221 * @post Depending on `key` and previous length of `ary` this operation
222 * can also create a series of "hole" positions inside of the
223 * backend storage. They are filled with ::RUBY_Qnil.
224 */
225 void rb_ary_store(VALUE ary, long key, VALUE val);
226
227 /**
228 * Duplicates an array.
229 *
230 * @param[in] ary Target to duplicate.
231 * @return An allocated new array whose contents are identical to `ary`.
232 *
233 * @internal
234 *
235 * Not sure why this has to be something different from `ary_make_shared_copy`,
236 * which seems much efficient.
237 */
238 VALUE rb_ary_dup(VALUE ary);
239
240 /**
241 * I guess there is no use case of this function in extension libraries, but
242 * this is a routine identical to rb_ary_dup(). This makes the most sense when
243 * the passed array is formerly hidden by rb_obj_hide().
244 *
245 * @param[in] ary An array, possibly hidden.
246 * @return A duplicated new instance of ::rb_cArray.
247 */
248 VALUE rb_ary_resurrect(VALUE ary);
249
250 /**
251 * Force converts an object to an array. It first tries its `#to_ary` method.
252 * Takes the result if any. Otherwise creates an array of size 1 whose sole
253 * element is the passed object.
254 *
255 * @param[in] obj Arbitrary ruby object.
256 * @return An array representation of `obj`.
257 * @note Unlike rb_str_to_str() which is a variant of
258 * rb_check_string_type(), rb_ary_to_ary() is not a variant of
259 * rb_check_array_type().
260 */
261 VALUE rb_ary_to_ary(VALUE obj);
262
263 /**
264 * Converts an array into a human-readable string. Historically its behaviour
265 * changed over time. Currently it is identical to calling `inspect` method.
266 * This behaviour is from that of python (!!) circa 2006.
267 *
268 * @param[in] ary Array to inspect.
269 * @return Recursively inspected representation of `ary`.
270 * @see `[ruby-dev:29520]`
271 */
272 VALUE rb_ary_to_s(VALUE ary);
273
274 /**
275 * Destructively appends multiple elements at the end of the array.
276 *
277 * @param[out] ary Where to push `train`.
278 * @param[in] train Arbitrary ruby objects to push to `ary`.
279 * @param[in] len Number of objects of `train`.
280 * @exception rb_eIndexError `len` too large.
281 * @exception rb_eFrozenError `ary` is frozen.
282 * @return The passed `ary`.
283 * @post `ary` has contents from `train` appended at its end.
284 */
285 VALUE rb_ary_cat(VALUE ary, const VALUE *train, long len);
286
287 /**
288 * Special case of rb_ary_cat() that it adds only one element.
289 *
290 * @param[out] ary Where to push `elem`.
291 * @param[in] elem Arbitrary ruby object to push.
292 * @exception rb_eFrozenError `ary` is frozen.
293 * @return The passed `ary`.
294 * @post `ary` has `elem` appended at its end.
295 */
296 VALUE rb_ary_push(VALUE ary, VALUE elem);
297
298 /**
299 * Destructively deletes an element from the end of the passed array and
300 * returns what was deleted.
301 *
302 * @param[out] ary Target array to modify.
303 * @exception rb_eFrozenError `ary` is frozen.
304 * @return What was at the end of `ary`, or ::RUBY_Qnil if there is
305 * nothing to remove.
306 * @post `ary`'s last element, if any, is removed.
307 * @note There is no way to distinguish whether `ary` was an 1-element
308 * array whose content was ::RUBY_Qnil, or was empty.
309 */
310 VALUE rb_ary_pop(VALUE ary);
311
312 /**
313 * Destructively deletes an element from the beginning of the passed array and
314 * returns what was deleted. It can also be seen as a routine identical to
315 * rb_ary_pop(), except which side of the array to scrub.
316 *
317 * @param[out] ary Target array to modify.
318 * @exception rb_eFrozenError `ary` is frozen.
319 * @return What was at the beginning of `ary`, or ::RUBY_Qnil if there is
320 * nothing to remove.
321 * @post `ary`'s first element, if any, is removed. As the name implies
322 * everything else remaining in `ary` gets moved towards `ary`'s
323 * beginning.
324 * @note There is no way to distinguish whether `ary` was an 1-element
325 * array whose content was ::RUBY_Qnil, or was empty.
326 */
327 VALUE rb_ary_shift(VALUE ary);
328
329 /**
330 * Destructively prepends the passed item at the beginning of the passed array.
331 * It can also be seen as a routine identical to rb_ary_push(), except which
332 * side of the array to modify.
333 *
334 * @param[out] ary Target array to modify.
335 * @param[in] elem Arbitrary ruby object to unshift.
336 * @exception rb_eFrozenError `ary` is frozen.
337 * @return The passed `ary`.
338 * @post `ary` has `elem` prepended at this beginning.
339 */
340 VALUE rb_ary_unshift(VALUE ary, VALUE elem);
341
342 RBIMPL_ATTR_PURE()
343 /**
344 * Queries an element of an array. When passed offset is negative it counts
345 * backwards.
346 *
347 * @param[in] ary An array to look into.
348 * @param[in] off Offset (can be negative).
349 * @return ::RUBY_Qnil when `off` is out of bounds of `ary`. Otherwise
350 * what is stored at `off`-th position of `ary`.
351 * @note `ary`'s `off`-th element can happen to be ::RUBY_Qnil.
352 */
353 VALUE rb_ary_entry(VALUE ary, long off);
354
355 /**
356 * Iteratively yields each element of the passed array to the implicitly passed
357 * block if any. In case there is no block given, an enumerator that does the
358 * thing is generated instead.
359 *
360 * @param[in] ary Array to iterate over.
361 * @retval ary Passed block was evaluated.
362 * @retval otherwise An instance of ::rb_cEnumerator for `Array#each`.
363 */
364 VALUE rb_ary_each(VALUE ary);
365
366 /**
367 * Recursively stringises the elements of the passed array, flattens that
368 * result, then joins the sequence using the passed separator.
369 *
370 * @param[in] ary Target array to convert.
371 * @param[in] sep Separator. Either a string, or ::RUBY_Qnil
372 * if you want no separator.
373 * @exception rb_eArgError Infinite recursion in `ary`.
374 * @exception rb_eTypeError `sep` is not a string.
375 * @exception rb_eEncCompatError Strings do not agree with their encodings.
376 * @return An instance of ::rb_cString which concatenates stringised
377 * contents of `ary`, using `sep` as separator.
378 */
379 VALUE rb_ary_join(VALUE ary, VALUE sep);
380
381 /**
382 * _Destructively_ reverses the passed array in-place.
383 *
384 * @warning This is `Array#reverse!`, not `Array#reverse`.
385 * @param[out] ary Target array to modify.
386 * @exception rb_eFrozenError `ary` is frozen.
387 * @return Passed `ary`.
388 * @post `ary` is reversed.
389 */
390 VALUE rb_ary_reverse(VALUE ary);
391
392 /**
393 * _Destructively_ rotates the passed array in-place to towards its end. The
394 * amount can be negative. Would rotate to the opposite direction then.
395 *
396 * @warning This is `Array#rotate!`, not `Array#rotate`.
397 * @param[out] ary Target array to modify.
398 * @param[in] rot Amount of rotation.
399 * @exception rb_eFrozenError `ary` is frozen.
400 * @retval RUBY_Qnil Not rotated.
401 * @retval ary Rotated.
402 * @post `ary` is rotated.
403 */
404 VALUE rb_ary_rotate(VALUE ary, long rot);
405
406 /**
407 * Creates a copy of the passed array, whose elements are sorted according to
408 * their `<=>` result.
409 *
410 * @param[in] ary Array to sort.
411 * @exception rb_eArgError Comparison not defined among elements.
412 * @exception rb_eRuntimeError Infinite recursion in `<=>`.
413 * @return A copy of `ary`, sorted.
414 * @note As of writing this function uses `qsort` as backend algorithm,
415 * which means the result is unstable (in terms of sort stability).
416 */
417 VALUE rb_ary_sort(VALUE ary);
418
419 /**
420 * Destructively sorts the passed array in-place, according to each elements'
421 * `<=>` result.
422 *
423 * @param[in] ary Target array to modify.
424 * @exception rb_eArgError Comparison not defined among elements.
425 * @exception rb_eRuntimeError Infinite recursion in `<=>`.
426 * @return Passed `ary`.
427 * @post `ary` is sorted.
428 * @note As of writing this function uses `qsort` as backend algorithm,
429 * which means the result is unstable (in terms of sort stability).
430 */
431 VALUE rb_ary_sort_bang(VALUE ary);
432
433 /**
434 * Destructively removes elements from the passed array, so that there would be
435 * no elements inside that satisfy `==` relationship with the passed object.
436 * Returns the last deleted element if any. But in case there was nothing to
437 * delete it gets complicated. It checks for the implicitly passed block. If
438 * there is a block the return value would be what the block evaluates to.
439 * Otherwise it resorts to ::RUBY_Qnil.
440 *
441 * @param[out] ary Target array to modify.
442 * @param[in] elem Template object to match against each element.
443 * @exception rb_eFrozenError `ary` is frozen.
444 * @return What was deleted, or what was the block returned, or
445 * ::RUBY_Qnil (see above).
446 * @post All elements that have `==` relationship with `elem` are purged
447 * from `ary`. Elements shift their positions so that `ary` gets
448 * compact.
449 *
450 * @internal
451 *
452 * Internally there also is `rb_ary_delete_same`, which compares by identity.
453 */
454 VALUE rb_ary_delete(VALUE ary, VALUE elem);
455
456 /**
457 * Destructively removes an element which resides at the specific index of the
458 * passed array. Unlike rb_ary_stre() the index can be negative, which means
459 * the index counts backwards from the array's tail.
460 *
461 * @param[out] ary Target array to modify.
462 * @param[in] pos Position (can be negative).
463 * @exception rb_eFrozenError `ary` is frozen.
464 * @return What was deleted, or ::RUBY_Qnil in case of OOB.
465 * @post `ary`'s `pos`-th element is deleted if any.
466 * @note There is no way to distinguish whether `pos` is out of bound,
467 * or `pos` did exist but stored ::RUBY_Qnil as an ordinal value.
468 */
469 VALUE rb_ary_delete_at(VALUE ary, long pos);
470
471 /**
472 * Destructively removes everything form an array.
473 *
474 * @param[out] ary Target array to modify.
475 * @exception rb_eFrozenError `ary` is frozen.
476 * @return The passed `ary`.
477 * @post `ary` is an empty array.
478 */
479 VALUE rb_ary_clear(VALUE ary);
480
481 /**
482 * Creates a new array, concatenating the former to the latter.
483 *
484 * @param[in] lhs Source array #1.
485 * @param[in] rhs Source array #2.
486 * @exception rb_eIndexError Result array too big.
487 * @return A new array containing `rhs` concatenated to `lhs`.
488 * @note This operation doesn't commute. Don't get confused by the
489 * "plus" terminology. For historical reasons there are some
490 * noncommutative `+`s in Ruby. This is one of such things. There
491 * has been a long discussion around `+`s in programming languages.
492 *
493 * @internal
494 *
495 * rb_ary_concat() is not a destructive version of rb_ary_plus(). They raise
496 * different exceptions. Don't know why though.
497 */
498 VALUE rb_ary_plus(VALUE lhs, VALUE rhs);
499
500 /**
501 * Destructively appends the contents of latter into the end of former.
502 *
503 * @param[out] lhs Destination array.
504 * @param[in] rhs Source array.
505 * @exception rb_eFrozenError `lhs` is frozen.
506 * @exception rb_eIndexError Result array too big.
507 * @exception rb_eTypeError `rhs` doesn't respond to `#to_ary`.
508 * @return The passed `lhs`.
509 * @post `lhs` has contents of `rhs` appended to its end.
510 */
511 VALUE rb_ary_concat(VALUE lhs, VALUE rhs);
512
513 /**
514 * Looks up the passed key, assuming the passed array is an alist. An "alist"
515 * here is a list of "association"s, much like that of Emacs. Emacs has
516 * `assoc` function that behaves exactly the same as this one.
517 *
518 * ```ruby
519 * # This is an example of aliist.
520 * auto_mode_alist = [
521 * [ /\.[ch]\z/, :"c-mode" ],
522 * [ /\.[ch]pp\z/, :"c++-mode" ],
523 * [ /\.awk\z/, :"awk-mode" ],
524 * [ /\.cs\z/, :"csharp-mode" ],
525 * [ /\.go\z/, :"go-mode" ],
526 * [ /\.java\z/, :"java-mode" ],
527 * [ /\.pas\z/, :"pascal-mode" ],
528 * [ /\.rs\z/, :"rust-mode" ],
529 * [ /\.txt\z/, :"text-mode" ],
530 * ]
531 * ```
532 *
533 * This function scans the passed array looking for an element, which itself is
534 * an array, whose first element is the passed key. If no such element is
535 * found, returns ::RUBY_Qnil.
536 *
537 * Although this function expects the passed array be an array of arrays, it
538 * can happily accept non-array elements; it just ignores such things.
539 *
540 * @param[in] alist An array of arrays.
541 * @param[in] key Needle.
542 * @retval RUBY_Qnil Nothing was found.
543 * @retval otherwise An element in `alist` whose first element is in `==`
544 * relationship with `key`.
545 */
546 VALUE rb_ary_assoc(VALUE alist, VALUE key);
547
548 /**
549 * Identical to rb_ary_assoc(), except it scans the passed array from the
550 * opposite direction.
551 *
552 * @param[in] alist An array of arrays.
553 * @param[in] key Needle.
554 * @retval RUBY_Qnil Nothing was found.
555 * @retval otherwise An element in `alist` whose first element is in `==`
556 * relationship with `key`.
557 */
558 VALUE rb_ary_rassoc(VALUE alist, VALUE key);
559
560 /**
561 * Queries if the passed array has the passed entry.
562 *
563 * @param[in] ary Target array to scan.
564 * @param[in] elem Target array to find.
565 * @retval RUBY_Qfalse No element in `ary` is in `==` relationship with
566 * `elem`.
567 * @retval RUBY_Qtrue There is at least one element in `ary` which is in
568 * `==` relationship with `elem`.
569 *
570 * @internal
571 *
572 * This is the only function in the entire C API that is named using third
573 * person singular form of a verb (except #ISASCII etc., which are not our
574 * naming). The counterpart Ruby API of this function is `Array#include?`.
575 */
576 VALUE rb_ary_includes(VALUE ary, VALUE elem);
577
578 /**
579 * Recursively compares each elements of the two arrays one-by-one using `<=>`.
580 *
581 * @param[in] lhs Comparison LHS.
582 * @param[in] rhs Comparison RHS.
583 * @retval RUBY_Qnil `lhs` and `rhs` are not comparable.
584 * @retval -1 `lhs` is less than `rhs`.
585 * @retval 0 They are equal.
586 * @retval 1 `rhs` is less then `lhs`.
587 */
588 VALUE rb_ary_cmp(VALUE lhs, VALUE rhs);
589
590 /**
591 * Replaces the contents of the former object with the contents of the latter.
592 *
593 * @param[out] copy Destination object.
594 * @param[in] orig Source object.
595 * @exception rb_eTypeError `orig` has no implicit conversion to Array.
596 * @exception rb_eFrozenError `copy` is frozen.
597 * @return The passed `copy`.
598 * @post `copy`'s former components are abandoned. It now has the
599 * identical length and contents to `orig`.
600 */
601 VALUE rb_ary_replace(VALUE copy, VALUE orig);
602
603 /**
604 * This _was_ a generalisation of `Array#values_at`, `Struct#values_at`, and
605 * `MatchData#values_at`. It begun its life as a refactoring effort. However
606 * as Ruby evolves over time, as of writing none of aforementioned methods
607 * share their implementations at all. This function is not deprecated; still
608 * works as it has been. But it is now kind of like a rudimentum.
609 *
610 * This function takes an object, which is a receiver, and a series of
611 * "indices", which are either integers, or ranges of integers. Calls the
612 * passed callback for each of those indices, along with the receiver. This
613 * callback is expected to do something like rb_ary_aref(), rb_struct_aref(),
614 * etc. In case of a range index rb_range_beg_len() expands the range.
615 * Finally return values of the callback are gathered as an array, then
616 * returned.
617 *
618 * @param[in] obj Arbitrary ruby object.
619 * @param[in] olen "Length" of `obj`.
620 * @param[in] argc Number of objects of `argv`.
621 * @param[in] argv List of "indices", described above.
622 * @param[in] func Callback function.
623 * @return A new instance of ::rb_cArray gathering `func`outputs.
624 *
625 * @internal
626 *
627 * `Array#values_at` no longer uses this function. There is no reason apart
628 * from historical ones to list this function here.
629 */
630 VALUE rb_get_values_at(VALUE obj, long olen, int argc, const VALUE *argv, VALUE (*func)(VALUE obj, long oidx));
631
632 /**
633 * Expands or shrinks the passed array to the passed length.
634 *
635 * @param[out] ary An array to modify.
636 * @param[in] len Desired length of `ary`.
637 * @exception rb_eFrozenError `ary` is frozen.
638 * @exception rb_eIndexError `len` too long.
639 * @return The passed `ary`.
640 * @post `ary`'s length is `len`.
641 * @post Depending on `len` and previous length of `ary` this operation
642 * can also create a series of "hole" positions inside of the
643 * backend storage. They are filled with ::RUBY_Qnil.
644 *
645 * @internal
646 *
647 * `len` is signed. Intentional or...?
648 */
649 VALUE rb_ary_resize(VALUE ary, long len);
650
651 #define rb_ary_new2 rb_ary_new_capa /**< @old{rb_ary_new_capa} */
652 #define rb_ary_new3 rb_ary_new_from_args /**< @old{rb_ary_new_from_args} */
653 #define rb_ary_new4 rb_ary_new_from_values /**< @old{rb_ary_new_from_values} */
654
655 RBIMPL_SYMBOL_EXPORT_END()
656
657 #endif /* RBIMPL_INTERN_ARRAY_H */