Ruby: include/ruby/internal/intern/enumerator.h Source File

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

enumerator.h
Go to the documentation of this file.
1#ifndef RBIMPL_INTERN_ENUMERATOR_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_INTERN_ENUMERATOR_H
23#include "ruby/internal/attr/nonnull.h"
24#include "ruby/internal/dllexport.h"
25#include "ruby/internal/intern/eval.h" /* rb_frame_this_func */
26#include "ruby/internal/iterator.h" /* rb_block_given_p */
27#include "ruby/internal/symbol.h"
28#include "ruby/internal/value.h"
29
30 RBIMPL_SYMBOL_EXPORT_BEGIN()
31
32
45typedef VALUE rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj);
46
53typedef struct {
54 VALUE begin;
55 VALUE end;
56 VALUE step;
57 int exclude_end;
58} rb_arithmetic_sequence_components_t;
59
60/* enumerator.c */
61
73 VALUE rb_enumeratorize(VALUE recv, VALUE meth, int argc, const VALUE *argv);
74
89 VALUE rb_enumeratorize_with_size(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func);
90
110 VALUE rb_enumeratorize_with_size_kw(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func, int kw_splat);
111
112 RBIMPL_ATTR_NONNULL(())
123int rb_arithmetic_sequence_extract(VALUE as, rb_arithmetic_sequence_components_t *buf);
124
125 RBIMPL_ATTR_NONNULL(())
151 VALUE rb_arithmetic_sequence_beg_len_step(VALUE as, long *begp, long *lenp, long *stepp, long len, int err);
152
153 RBIMPL_SYMBOL_EXPORT_END()
154
156#ifndef RUBY_EXPORT
157# define rb_enumeratorize_with_size(obj, id, argc, argv, size_fn) \
158 rb_enumeratorize_with_size(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn))
159# define rb_enumeratorize_with_size_kw(obj, id, argc, argv, size_fn, kw_splat) \
160 rb_enumeratorize_with_size_kw(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn), kw_splat)
161#endif
163
175#define SIZED_ENUMERATOR(obj, argc, argv, size_fn) \
176 rb_enumeratorize_with_size((obj), ID2SYM(rb_frame_this_func()), \
177 (argc), (argv), (size_fn))
178
195#define SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) \
196 rb_enumeratorize_with_size_kw((obj), ID2SYM(rb_frame_this_func()), \
197 (argc), (argv), (size_fn), (kw_splat))
198
208#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) do { \
209 if (!rb_block_given_p()) \
210 return SIZED_ENUMERATOR(obj, argc, argv, size_fn); \
211 } while (0)
212
213
229#define RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) do { \
230 if (!rb_block_given_p()) \
231 return SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat); \
232 } while (0)
233
242#define RETURN_ENUMERATOR(obj, argc, argv) \
243 RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0)
244
260#define RETURN_ENUMERATOR_KW(obj, argc, argv, kw_splat) \
261 RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, 0, kw_splat)
262
263#endif /* RBIMPL_INTERN_ENUMERATOR_H */
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
rb_enumeratorize_with_size
VALUE rb_enumeratorize_with_size(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func)
Identical to rb_enumeratorize(), except you can additionally specify the size function of return valu...
Definition enumerator.c:542
rb_enumeratorize
VALUE rb_enumeratorize(VALUE recv, VALUE meth, int argc, const VALUE *argv)
Constructs an enumerator.
Definition enumerator.c:517
rb_enumeratorize_with_size_kw
VALUE rb_enumeratorize_with_size_kw(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func, int kw_splat)
Identical to rb_enumeratorize_with_func(), except you can specify how to handle the last element of t...
Definition enumerator.c:526
rb_enumerator_size_func
VALUE rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj)
This is the type of functions that rb_enumeratorize_with_size() expects.
Definition enumerator.h:45
eval.h
Pre-1.9 era evaluator APIs (now considered miscellaneous).
symbol.h
Defines rb_intern.
len
int len
Length of the buffer.
Definition io.h:8
iterator.h
Block related APIs.
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull)).
Definition nonnull.h:30
rb_arithmetic_sequence_components_t
Decomposed Enumerator::ArithmeicSequence.
Definition enumerator.h:53
rb_arithmetic_sequence_components_t::exclude_end
int exclude_end
Whether the endpoint is open or closed.
Definition enumerator.h:57
rb_arithmetic_sequence_components_t::end
VALUE end
"Right" or "highest" endpoint of the sequence.
Definition enumerator.h:55
rb_arithmetic_sequence_components_t::step
VALUE step
Step between a sequence.
Definition enumerator.h:56
rb_arithmetic_sequence_components_t::begin
VALUE begin
"Left" or "lowest" endpoint of the sequence.
Definition enumerator.h:54
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40