Ruby: enum.c File Reference

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

Data Structures | Macros | Functions | Variables
enum.c File Reference
`#include "id.h"`
`#include "internal.h"`
`#include "internal/compar.h"`
`#include "internal/enum.h"`
`#include "internal/hash.h"`
`#include "internal/imemo.h"`
`#include "internal/numeric.h"`
`#include "internal/object.h"`
`#include "internal/proc.h"`
`#include "internal/rational.h"`
`#include "internal/re.h"`
`#include "ruby/util.h"`
`#include "ruby_assert.h"`
`#include "symbol.h"`

Go to the source code of this file.

## Data Structures
struct | sort_by_data
struct | nmin_data
struct | min_t
struct | max_t
struct | minmax_t
struct | minmax_by_t
struct | chunk_arg
struct | slicebefore_arg
struct | sliceafter_arg
struct | slicewhen_arg
struct | enum_sum_memo

## Macros
#define | id_div idDiv
#define | id_each idEach
#define | id_eqq idEqq
#define | id_cmp idCmp
#define | id_lshift idLTLT
#define | id_call idCall
#define | id_size idSize
#define | ENUM_WANT_SVALUE()
#define | COUNT_BIGNUM IMEMO_FL_USER0
#define | MEMO_V3_SET(m, v) RB_OBJ_WRITE((m), &(m)->u3.value, (v))
#define | SORT_BY_BUFSIZE 16
#define | ENUMFUNC(name) argc ? name##_eqq : rb_block_given_p() ? name##_iter_i : name##_i
#define | MEMO_ENUM_NEW(v1) (rb_check_arity(argc, 0, 1), MEMO_NEW((v1), (argc ? *argv : 0), 0))
#define | DEFINE_ENUMFUNCS(name)
#define | WARN_UNUSED_BLOCK(argc)
#define | rb_cmpint(cmp, a, b) rb_cmpint(cmpint_reenter_check(data, (cmp)), a, b)
#define | GETPTR(i) (beg+(i)*eltsize)
#define | SWAP(i, j)
#define | dont_recycle_block_arg(arity) ((arity) == 1 || (arity) < 0)
#define | UPDATE_MEMO ((void)(memo = MEMO_FOR(struct sliceafter_arg, _memo)))
#define | UPDATE_MEMO ((void)(memo = MEMO_FOR(struct slicewhen_arg, _memo)))

## Functions
VALUE | rb_enum_values_pack (int argc, const VALUE *argv)
| DEFINE_ENUMFUNCS (all)
| DEFINE_ENUMFUNCS (any)
| DEFINE_ENUMFUNCS (one)
VALUE | rb_nmin_run (VALUE obj, VALUE num, int by, int rev, int ary)
| DEFINE_ENUMFUNCS (none)
void | Init_Enumerable (void)

## Variables
VALUE | rb_mEnumerable

## Macro Definition Documentation

## ◆ COUNT_BIGNUM

#define COUNT_BIGNUM IMEMO_FL_USER0

Definition at line 179 of file enum.c.

## ◆ DEFINE_ENUMFUNCS

#define DEFINE_ENUMFUNCS | ( |  | name | ) |

Value:
static VALUE enum_##name##_func(VALUE result, struct MEMO *memo); \
\
static VALUE \
name##_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
{ \
return enum_##name##_func(rb_enum_values_pack(argc, argv), MEMO_CAST(memo)); \
} \
\
static VALUE \
name##_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
{ \
return enum_##name##_func(rb_yield_values2(argc, argv), MEMO_CAST(memo)); \
} \
\
static VALUE \
name##_eqq(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
{ \
ENUM_WANT_SVALUE(); \
return enum_##name##_func(rb_funcallv(MEMO_CAST(memo)->v2, id_eqq, 1, &i), MEMO_CAST(memo)); \
} \
\
static VALUE \
enum_##name##_func(VALUE result, struct MEMO *memo)
id_eqq
#define id_eqq
Definition: enum.c:33
rb_enum_values_pack
VALUE rb_enum_values_pack(int argc, const VALUE *argv)
Definition: enum.c:40
MEMO_CAST
#define MEMO_CAST(m)
Definition: imemo.h:121
rb_funcallv
#define rb_funcallv(...)
Definition: internal.h:77
RB_BLOCK_CALL_FUNC_ARGLIST
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Definition: iterator.h:31
rb_yield_values2
VALUE rb_yield_values2(int n, const VALUE *argv)
Definition: vm_eval.c:1375
name
const char * name
Definition: nkf.c:208
argc
int argc
Definition: ruby.c:240
argv
char ** argv
Definition: ruby.c:241
MEMO
MEMO.
Definition: imemo.h:105
VALUE
unsigned long VALUE
Definition: value.h:38

Definition at line 1313 of file enum.c.

## ◆ dont_recycle_block_arg

#define dont_recycle_block_arg | ( |  | arity | ) | ((arity) == 1 || (arity) < 0)

Definition at line 2538 of file enum.c.

## ◆ ENUM_WANT_SVALUE

#define ENUM_WANT_SVALUE | ( |  | ) |

Value:
do { \
i = rb_enum_values_pack(argc, argv); \
} while (0)

Definition at line 47 of file enum.c.

## ◆ ENUMFUNC

#define ENUMFUNC | ( |  | name | ) | argc ? name##_eqq : rb_block_given_p() ? name##_iter_i : name##_i

Definition at line 1309 of file enum.c.

## ◆ GETPTR

#define GETPTR | ( |  | i | ) | (beg+(i)*eltsize)

## ◆ id_call

#define id_call idCall

Definition at line 36 of file enum.c.

## ◆ id_cmp

#define id_cmp idCmp

Definition at line 34 of file enum.c.

## ◆ id_div

#define id_div idDiv

Definition at line 31 of file enum.c.

## ◆ id_each

#define id_each idEach

Definition at line 32 of file enum.c.

## ◆ id_eqq

#define id_eqq idEqq

Definition at line 33 of file enum.c.

## ◆ id_lshift

#define id_lshift idLTLT

Definition at line 35 of file enum.c.

## ◆ id_size

#define id_size idSize

Definition at line 37 of file enum.c.

## ◆ MEMO_ENUM_NEW

#define MEMO_ENUM_NEW | ( |  | v1 | ) | (rb_check_arity(argc, 0, 1), MEMO_NEW((v1), (argc ? *argv : 0), 0))

Definition at line 1311 of file enum.c.

## ◆ MEMO_V3_SET

#define MEMO_V3_SET | ( |  | m,
|  |  | v
| ) |  | RB_OBJ_WRITE((m), &(m)->u3.value, (v))

Definition at line 180 of file enum.c.

## ◆ rb_cmpint

#define rb_cmpint | ( |  | cmp,
|  |  | a,
|  |  | b
| ) |  | rb_cmpint(cmpint_reenter_check(data, (cmp)), a, b)

## ◆ SORT_BY_BUFSIZE

#define SORT_BY_BUFSIZE 16

Definition at line 1130 of file enum.c.

## ◆ SWAP

#define SWAP | ( |  | i,
|  |  | j
| ) |  |

Value:
do { \
VALUE tmp[2]; \
memcpy(tmp, GETPTR(i), sizeof(VALUE)*eltsize); \
memcpy(GETPTR(i), GETPTR(j), sizeof(VALUE)*eltsize); \
memcpy(GETPTR(j), tmp, sizeof(VALUE)*eltsize); \
} while (0)
GETPTR
#define GETPTR(i)

## ◆ UPDATE_MEMO [1/2]

#define UPDATE_MEMO ((void)(memo = MEMO_FOR(struct sliceafter_arg, _memo)))

## ◆ UPDATE_MEMO [2/2]

#define UPDATE_MEMO ((void)(memo = MEMO_FOR(struct slicewhen_arg, _memo)))

## ◆ WARN_UNUSED_BLOCK

#define WARN_UNUSED_BLOCK | ( |  | argc | ) |

Value:
do { \
if ((argc) > 0 && rb_block_given_p()) { \
rb_warn("given block not used"); \
} \
} while (0)
rb_block_given_p
int rb_block_given_p(void)
Determines if the current method is given a block.
Definition: eval.c:935

Definition at line 1338 of file enum.c.

## Function Documentation

## ◆ DEFINE_ENUMFUNCS() [1/4]

DEFINE_ENUMFUNCS | ( | all |  | ) |

Definition at line 1344 of file enum.c.

References Qfalse, Qnil, rb_iter_break(), and RTEST.

## ◆ DEFINE_ENUMFUNCS() [2/4]

DEFINE_ENUMFUNCS | ( | any |  | ) |

Definition at line 1386 of file enum.c.

References Qnil, Qtrue, rb_iter_break(), and RTEST.

## ◆ DEFINE_ENUMFUNCS() [3/4]

DEFINE_ENUMFUNCS | ( | none |  | ) |

Definition at line 1701 of file enum.c.

References Qfalse, Qnil, rb_iter_break(), and RTEST.

## ◆ DEFINE_ENUMFUNCS() [4/4]

DEFINE_ENUMFUNCS | ( | one |  | ) |

Definition at line 1428 of file enum.c.

References Qfalse, Qnil, Qtrue, Qundef, rb_iter_break(), RTEST, and MEMO::v1.

## ◆ Init_Enumerable()

void Init_Enumerable | ( | void |  | ) |

Definition at line 4192 of file enum.c.

References rb_define_method, rb_define_module(), and rb_mEnumerable.

## ◆ rb_enum_values_pack()

VALUE rb_enum_values_pack | ( | int | argc,
|  | const VALUE * | argv
| ) |  |

Definition at line 40 of file enum.c.

References argc, argv, Qnil, and rb_ary_new4.

## ◆ rb_nmin_run()

VALUE rb_nmin_run | ( | VALUE | obj,
|  | VALUE | num,
|  | int | by,
|  | int | rev,
|  | int | ary
| ) |  |

Definition at line 1603 of file enum.c.

References nmin_data::buf, nmin_data::bufmax, nmin_data::by, nmin_data::cmpfunc, nmin_data::curlen, id_each, nmin_data::limit, LONG_MAX, nmin_data::n, num, NUM2LONG, ptr, Qundef, RARRAY_AREF, RARRAY_LEN, RARRAY_PTR_USE, rb_ary_new2, rb_ary_resize(), rb_ary_reverse(), rb_ary_tmp_new(), ruby::backward::cxxanyargs::rb_block_call(), rb_block_given_p(), rb_cArray, rb_eArgError, rb_raise(), nmin_data::rev, and ruby_qsort().

## Variable Documentation

## ◆ rb_mEnumerable

VALUE rb_mEnumerable

Definition at line 27 of file enum.c.

Referenced by Init_Array(), Init_dbm(), Init_Dir(), Init_Enumerable(), Init_etc(), Init_GC(), Init_gdbm(), Init_Hash(), Init_IO(), Init_ossl_asn1(), Init_Range(), Init_readline(), Init_stringio(), Init_zlib(), InitVM_Enumerator(), and InitVM_Struct().