Ruby 4.0.0dev (2025-12-23 revision ed1aac5486ce340d39d0266b570aa0d0243dc114)
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
25#include "ruby/internal/intern/eval.h" /* rb_frame_this_func */
26#include "ruby/internal/iterator.h" /* rb_block_given_p */
28#include "ruby/internal/value.h"
29
31
32
45typedef VALUE rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj);
46
59
60/* enumerator.c */
61
73VALUE rb_enumeratorize(VALUE recv, VALUE meth, int argc, const VALUE *argv);
74
89VALUE rb_enumeratorize_with_size(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func);
90
110VALUE rb_enumeratorize_with_size_kw(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func, int kw_splat);
111
124
151VALUE rb_arithmetic_sequence_beg_len_step(VALUE as, long *begp, long *lenp, long *stepp, long len, int err);
152
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
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 */
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
VALUE rb_arithmetic_sequence_beg_len_step(VALUE as, long *begp, long *lenp, long *stepp, long len, int err)
Identical to rb_range_beg_len(), except it takes an instance of Enumerator::ArithmericSequence.
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:541
VALUE rb_enumeratorize(VALUE recv, VALUE meth, int argc, const VALUE *argv)
Constructs an enumerator.
Definition enumerator.c:516
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:525
int rb_arithmetic_sequence_extract(VALUE as, rb_arithmetic_sequence_components_t *buf)
Extracts components of the passed arithmetic sequence.
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
Pre-1.9 era evaluator APIs (now considered miscellaneous).
Defines rb_intern.
int len
Length of the buffer.
Definition io.h:8
Block related APIs.
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30
Decomposed Enumerator::ArithmeicSequence.
Definition enumerator.h:53
int exclude_end
Whether the endpoint is open or closed.
Definition enumerator.h:57
VALUE end
"Right" or "highest" endpoint of the sequence.
Definition enumerator.h:55
VALUE step
Step between a sequence.
Definition enumerator.h:56
VALUE begin
"Left" or "lowest" endpoint of the sequence.
Definition enumerator.h:54
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40