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

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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/dllexport.h"
24#include "ruby/internal/intern/eval.h" /* rb_frame_this_func */
25#include "ruby/internal/iterator.h" /* rb_block_given_p */
26#include "ruby/internal/symbol.h"
27#include "ruby/internal/value.h"
28
29 RBIMPL_SYMBOL_EXPORT_BEGIN()
30
31typedef VALUE rb_enumerator_size_func(VALUE, VALUE, VALUE);
32
33typedef struct {
34 VALUE begin;
35 VALUE end;
36 VALUE step;
37 int exclude_end;
38} rb_arithmetic_sequence_components_t;
39
40/* enumerator.c */
41 VALUE rb_enumeratorize(VALUE, VALUE, int, const VALUE *);
42 VALUE rb_enumeratorize_with_size(VALUE, VALUE, int, const VALUE *, rb_enumerator_size_func *);
43 VALUE rb_enumeratorize_with_size_kw(VALUE, VALUE, int, const VALUE *, rb_enumerator_size_func *, int);
44int rb_arithmetic_sequence_extract(VALUE, rb_arithmetic_sequence_components_t *);
45 VALUE rb_arithmetic_sequence_beg_len_step(VALUE, long *begp, long *lenp, long *stepp, long len, int err);
46
47 RBIMPL_SYMBOL_EXPORT_END()
48
49#ifndef RUBY_EXPORT
50# define rb_enumeratorize_with_size(obj, id, argc, argv, size_fn) \
51 rb_enumeratorize_with_size(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn))
52# define rb_enumeratorize_with_size_kw(obj, id, argc, argv, size_fn, kw_splat) \
53 rb_enumeratorize_with_size_kw(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn), kw_splat)
54#endif
55
56#define SIZED_ENUMERATOR(obj, argc, argv, size_fn) \
57 rb_enumeratorize_with_size((obj), ID2SYM(rb_frame_this_func()), \
58 (argc), (argv), (size_fn))
59
60#define SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) \
61 rb_enumeratorize_with_size_kw((obj), ID2SYM(rb_frame_this_func()), \
62 (argc), (argv), (size_fn), (kw_splat))
63
64#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) do { \
65 if (!rb_block_given_p()) \
66 return SIZED_ENUMERATOR(obj, argc, argv, size_fn); \
67 } while (0)
68
69#define RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) do { \
70 if (!rb_block_given_p()) \
71 return SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat); \
72 } while (0)
73
74#define RETURN_ENUMERATOR(obj, argc, argv) \
75 RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0)
76
77#define RETURN_ENUMERATOR_KW(obj, argc, argv, kw_splat) \
78 RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, 0, kw_splat)
79
80#endif /* RBIMPL_INTERN_ENUMERATOR_H */
dllexport.h
Tewaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
len
uint8_t len
Definition: escape.c:17
rb_enumeratorize
VALUE rb_enumeratorize(VALUE, VALUE, int, const VALUE *)
Definition: enumerator.c:511
rb_enumeratorize_with_size
#define rb_enumeratorize_with_size(obj, id, argc, argv, size_fn)
Definition: enumerator.h:50
rb_arithmetic_sequence_beg_len_step
VALUE rb_arithmetic_sequence_beg_len_step(VALUE, long *begp, long *lenp, long *stepp, long len, int err)
Definition: enumerator.c:3411
rb_enumerator_size_func
VALUE rb_enumerator_size_func(VALUE, VALUE, VALUE)
Definition: enumerator.h:31
rb_arithmetic_sequence_extract
int rb_arithmetic_sequence_extract(VALUE, rb_arithmetic_sequence_components_t *)
Definition: enumerator.c:3393
rb_enumeratorize_with_size_kw
#define rb_enumeratorize_with_size_kw(obj, id, argc, argv, size_fn, kw_splat)
Definition: enumerator.h:52
eval.h
Pre-1.9 era evaluator APIs (now considered miscellaneous).
symbol.h
Defines rb_intern.
iterator.h
Block related APIs.
rb_arithmetic_sequence_components_t
Definition: enumerator.h:33
rb_arithmetic_sequence_components_t::exclude_end
int exclude_end
Definition: enumerator.h:37
rb_arithmetic_sequence_components_t::end
VALUE end
Definition: enumerator.h:35
rb_arithmetic_sequence_components_t::step
VALUE step
Definition: enumerator.h:36
rb_arithmetic_sequence_components_t::begin
VALUE begin
Definition: enumerator.h:34
value.h
Defines VALUE and ID.
VALUE
unsigned long VALUE
Definition: value.h:38
err
int err
Definition: win32.c:142