Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Defines | Functions | Variables

# enumerator.c File Reference

`#include "ruby/ruby.h"`
Include dependency graph for enumerator.c:

Go to the source code of this file.

## Data Structures
struct | enumerator
struct | generator
struct | yielder
## Defines
#define | enumerator_free RUBY_TYPED_DEFAULT_FREE
#define | yielder_free RUBY_TYPED_DEFAULT_FREE
#define | generator_free RUBY_TYPED_DEFAULT_FREE
## Functions
static VALUE | generator_allocate (VALUE klass)
static VALUE | generator_init (VALUE obj, VALUE proc)
static void | enumerator_mark (void *p)
static size_t | enumerator_memsize (const void *p)
static struct enumerator * | enumerator_ptr (VALUE obj)
static VALUE | obj_to_enum (int argc, VALUE *argv, VALUE obj)
static VALUE | enumerator_allocate (VALUE klass)
static VALUE | enumerator_init (VALUE enum_obj, VALUE obj, VALUE meth, int argc, VALUE *argv)
static VALUE | enumerator_initialize (int argc, VALUE *argv, VALUE obj)
static VALUE | enumerator_init_copy (VALUE obj, VALUE orig)
VALUE | rb_enumeratorize (VALUE obj, VALUE meth, int argc, VALUE *argv)
static VALUE | enumerator_block_call (VALUE obj, rb_block_call_func *func, VALUE arg)
static VALUE | enumerator_each (VALUE obj)
static VALUE | enumerator_with_index_i (VALUE val, VALUE m, int argc, VALUE *argv)
static VALUE | enumerator_with_index (int argc, VALUE *argv, VALUE obj)
static VALUE | enumerator_each_with_index (VALUE obj)
static VALUE | enumerator_with_object_i (VALUE val, VALUE memo, int argc, VALUE *argv)
static VALUE | enumerator_with_object (VALUE obj, VALUE memo)
static VALUE | next_ii (VALUE i, VALUE obj, int argc, VALUE *argv)
static VALUE | next_i (VALUE curr, VALUE obj)
static void | next_init (VALUE obj, struct enumerator *e)
static VALUE | get_next_values (VALUE obj, struct enumerator *e)
static VALUE | enumerator_next_values (VALUE obj)
static VALUE | ary2sv (VALUE args, int dup)
static VALUE | enumerator_next (VALUE obj)
static VALUE | enumerator_peek_values (VALUE obj)
static VALUE | enumerator_peek_values_m (VALUE obj)
static VALUE | enumerator_peek (VALUE obj)
static VALUE | enumerator_feed (VALUE obj, VALUE v)
static VALUE | enumerator_rewind (VALUE obj)
static VALUE | inspect_enumerator (VALUE obj, VALUE dummy, int recur)
static VALUE | enumerator_inspect (VALUE obj)
static void | yielder_mark (void *p)
static size_t | yielder_memsize (const void *p)
static struct yielder * | yielder_ptr (VALUE obj)
static VALUE | yielder_allocate (VALUE klass)
static VALUE | yielder_init (VALUE obj, VALUE proc)
static VALUE | yielder_initialize (VALUE obj)
static VALUE | yielder_yield (VALUE obj, VALUE args)
static VALUE | yielder_yield_push (VALUE obj, VALUE args)
static VALUE | yielder_yield_i (VALUE obj, VALUE memo, int argc, VALUE *argv)
static VALUE | yielder_new (void)
static void | generator_mark (void *p)
static size_t | generator_memsize (const void *p)
static struct generator * | generator_ptr (VALUE obj)
VALUE | rb_obj_is_proc (VALUE proc)
static VALUE | generator_initialize (int argc, VALUE *argv, VALUE obj)
static VALUE | generator_init_copy (VALUE obj, VALUE orig)
static VALUE | generator_each (VALUE obj)
static VALUE | stop_result (VALUE self)
void | Init_Enumerator (void)
## Variables
VALUE | rb_cEnumerator
static ID | id_rewind
static ID | id_each
static VALUE | sym_each
VALUE | rb_eStopIteration
static VALUE | rb_cGenerator
static VALUE | rb_cYielder
static const rb_data_type_t | enumerator_data_type
static const rb_data_type_t | yielder_data_type
static const rb_data_type_t | generator_data_type

## Define Documentation

#define enumerator_free RUBY_TYPED_DEFAULT_FREE

Definition at line 124 of file enumerator.c.

#define generator_free RUBY_TYPED_DEFAULT_FREE

Definition at line 908 of file enumerator.c.

#define yielder_free RUBY_TYPED_DEFAULT_FREE

Definition at line 805 of file enumerator.c.

## Function Documentation

static VALUE ary2sv | ( | VALUE | args,
|  | int | dup
| ) |  | `[static]`

Definition at line 535 of file enumerator.c.

References enumerator::args, Qnil, RARRAY_LEN, RARRAY_PTR, rb_ary_dup(), T_ARRAY, and TYPE.

Referenced by enumerator_next(), and enumerator_peek().

static VALUE enumerator_allocate | ( | VALUE | klass | ) | `[static]`

Definition at line 183 of file enumerator.c.

References enumerator_data_type, enumerator::obj, Qundef, and TypedData_Make_Struct.

Referenced by Init_Enumerator(), and rb_enumeratorize().

static VALUE enumerator_block_call | ( | VALUE | obj,
|  | rb_block_call_func * | func,
|  | VALUE | arg
| ) |  | `[static]`

Definition at line 306 of file enumerator.c.

References argc, enumerator::args, argv, enumerator_ptr(), enumerator::meth, enumerator::obj, RARRAY_LENINT, RARRAY_PTR, and rb_block_call.

Referenced by enumerator_each(), enumerator_with_index(), and enumerator_with_object().

static VALUE enumerator_each | ( | VALUE | obj | ) | `[static]`

Definition at line 329 of file enumerator.c.

References enumerator_block_call(), enumerator::obj, and rb_block_given_p().

Referenced by Init_Enumerator().

static VALUE enumerator_each_with_index | ( | VALUE | obj | ) | `[static]`

Definition at line 380 of file enumerator.c.

References enumerator_with_index(), and NULL.

Referenced by Init_Enumerator().

static VALUE enumerator_feed | ( | VALUE | obj,
|  | VALUE | v
| ) |  | `[static]`

Definition at line 689 of file enumerator.c.

References enumerator_ptr(), enumerator::feedvalue, Qnil, Qundef, rb_eTypeError, and rb_raise().

Referenced by Init_Enumerator().

static VALUE enumerator_init | ( | VALUE | enum_obj,
|  | VALUE | obj,
|  | VALUE | meth,
|  | int | argc,
|  | VALUE * | argv
| ) |  | `[static]`

Definition at line 195 of file enumerator.c.

References enumerator::args, enumerator::dst, enumerator_data_type, enumerator::feedvalue, enumerator::fib, enumerator::lookahead, enumerator::meth, enumerator::obj, Qfalse, Qnil, Qundef, rb_ary_new4(), rb_eArgError, rb_raise(), rb_to_id(), enumerator::stop_exc, and TypedData_Get_Struct.

Referenced by enumerator_initialize(), and rb_enumeratorize().

static VALUE enumerator_init_copy | ( | VALUE | obj,
|  | VALUE | orig
| ) |  | `[static]`

Definition at line 273 of file enumerator.c.

References enumerator::args, enumerator_data_type, enumerator_ptr(), enumerator::feedvalue, enumerator::fib, enumerator::lookahead, enumerator::meth, enumerator::obj, Qundef, rb_eArgError, rb_eTypeError, rb_raise(), and TypedData_Get_Struct.

Referenced by Init_Enumerator().

static VALUE enumerator_initialize | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | obj
| ) |  | `[static]`

Definition at line 250 of file enumerator.c.

References argc, enumerator_init(), generator_allocate(), generator_init(), enumerator::meth, rb_block_given_p(), rb_block_proc(), rb_cGenerator, rb_eArgError, rb_raise(), and sym_each.

Referenced by Init_Enumerator().

static VALUE enumerator_inspect | ( | VALUE | obj | ) | `[static]`

Definition at line 790 of file enumerator.c.

References inspect_enumerator(), and rb_exec_recursive().

Referenced by Init_Enumerator().

static void enumerator_mark | ( | void * | p | ) | `[static]`

Definition at line 112 of file enumerator.c.

References enumerator::args, enumerator::dst, enumerator::feedvalue, enumerator::fib, enumerator::lookahead, enumerator::obj, rb_gc_mark(), and enumerator::stop_exc.

static size_t enumerator_memsize | ( | const void * | p | ) | `[static]`

Definition at line 127 of file enumerator.c.

static VALUE enumerator_next | ( | VALUE | obj | ) | `[static]`

Definition at line 576 of file enumerator.c.

References ary2sv(), and enumerator_next_values().

Referenced by Init_Enumerator().

static VALUE enumerator_next_values | ( | VALUE | obj | ) | `[static]`

Definition at line 520 of file enumerator.c.

References enumerator_ptr(), get_next_values(), enumerator::lookahead, and Qundef.

Referenced by enumerator_next(), and Init_Enumerator().

static VALUE enumerator_peek | ( | VALUE | obj | ) | `[static]`

Definition at line 646 of file enumerator.c.

References ary2sv(), and enumerator_peek_values().

Referenced by Init_Enumerator().

static VALUE enumerator_peek_values | ( | VALUE | obj | ) | `[static]`

Definition at line 583 of file enumerator.c.

References enumerator_ptr(), get_next_values(), enumerator::lookahead, and Qundef.

Referenced by enumerator_peek(), and enumerator_peek_values_m().

static VALUE enumerator_peek_values_m | ( | VALUE | obj | ) | `[static]`

Definition at line 620 of file enumerator.c.

References enumerator_peek_values(), and rb_ary_dup().

Referenced by Init_Enumerator().

static struct enumerator* enumerator_ptr | ( | VALUE | obj | ) | `[static, read]`

Definition at line 140 of file enumerator.c.

References enumerator_data_type, enumerator::obj, Qundef, rb_eArgError, rb_raise(), and TypedData_Get_Struct.

Referenced by enumerator_block_call(), enumerator_feed(), enumerator_init_copy(), enumerator_next_values(), enumerator_peek_values(), enumerator_rewind(), next_i(), and next_ii().

static VALUE enumerator_rewind | ( | VALUE | obj | ) | `[static]`

Definition at line 711 of file enumerator.c.

References enumerator::dst, enumerator_ptr(), enumerator::feedvalue, enumerator::fib, id_rewind, enumerator::lookahead, enumerator::obj, Qfalse, Qnil, Qundef, rb_check_funcall(), and enumerator::stop_exc.

Referenced by Init_Enumerator().

static VALUE enumerator_with_index | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | obj
| ) |  | `[static]`

Definition at line 360 of file enumerator.c.

References enumerator_block_call(), enumerator_with_index_i(), NIL_P, NUM2LONG(), rb_scan_args(), and RETURN_ENUMERATOR.

Referenced by enumerator_each_with_index(), and Init_Enumerator().

static VALUE enumerator_with_index_i | ( | VALUE | val,
|  | VALUE | m,
|  | int | argc,
|  | VALUE * | argv
| ) |  | `[static]`

Definition at line 336 of file enumerator.c.

References INT2FIX, rb_ary_new4(), and rb_yield_values().

Referenced by enumerator_with_index().

static VALUE enumerator_with_object | ( | VALUE | obj,
|  | VALUE | memo
| ) |  | `[static]`

Definition at line 406 of file enumerator.c.

References enumerator_block_call(), enumerator_with_object_i(), and RETURN_ENUMERATOR.

Referenced by Init_Enumerator().

static VALUE enumerator_with_object_i | ( | VALUE | val,
|  | VALUE | memo,
|  | int | argc,
|  | VALUE * | argv
| ) |  | `[static]`

Definition at line 386 of file enumerator.c.

References rb_ary_new4(), and rb_yield_values().

Referenced by enumerator_with_object().

static VALUE generator_allocate | ( | VALUE | klass | ) | `[static]`

Definition at line 937 of file enumerator.c.

References generator_data_type, generator::proc, Qundef, and TypedData_Make_Struct.

Referenced by enumerator_initialize(), and Init_Enumerator().

static VALUE generator_each | ( | VALUE | obj | ) | `[static]`

Definition at line 1013 of file enumerator.c.

References generator_ptr(), generator::proc, rb_ary_new3(), rb_proc_call(), and yielder_new().

Referenced by Init_Enumerator().

static VALUE generator_init | ( | VALUE | obj,
|  | VALUE | proc
| ) |  | `[static]`

Definition at line 949 of file enumerator.c.

References generator_data_type, generator::proc, rb_eArgError, rb_raise(), and TypedData_Get_Struct.

Referenced by enumerator_initialize(), and generator_initialize().

static VALUE generator_init_copy | ( | VALUE | obj,
|  | VALUE | orig
| ) |  | `[static]`

Definition at line 994 of file enumerator.c.

References generator_data_type, generator_ptr(), generator::proc, rb_eArgError, rb_raise(), and TypedData_Get_Struct.

Referenced by Init_Enumerator().

static VALUE generator_initialize | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | obj
| ) |  | `[static]`

Definition at line 968 of file enumerator.c.

References generator_init(), generator::proc, rb_block_given_p(), rb_block_proc(), rb_eTypeError, rb_need_block(), rb_obj_classname(), rb_obj_is_proc(), rb_raise(), rb_scan_args(), and rb_warn().

Referenced by Init_Enumerator().

static void generator_mark | ( | void * | p | ) | `[static]`

Definition at line 902 of file enumerator.c.

References generator::proc, and rb_gc_mark().

static size_t generator_memsize | ( | const void * | p | ) | `[static]`

Definition at line 911 of file enumerator.c.

static struct generator* generator_ptr | ( | VALUE | obj | ) | `[static, read]`

Definition at line 924 of file enumerator.c.

References generator_data_type, generator::proc, Qundef, rb_eArgError, rb_raise(), and TypedData_Get_Struct.

Referenced by generator_each(), and generator_init_copy().

static VALUE get_next_values | ( | VALUE | obj,
|  | struct enumerator * | e
| ) |  | `[static]`

Definition at line 451 of file enumerator.c.

References enumerator::dst, enumerator::feedvalue, enumerator::fib, enumerator::lookahead, next_init(), Qnil, Qundef, rb_exc_raise(), rb_fiber_alive_p(), rb_fiber_current(), rb_fiber_resume(), and enumerator::stop_exc.

Referenced by enumerator_next_values(), and enumerator_peek_values().

void Init_Enumerator | ( | void |  | ) |

Definition at line 1073 of file enumerator.c.

References enumerator_allocate(), enumerator_each(), enumerator_each_with_index(), enumerator_feed(), enumerator_init_copy(), enumerator_initialize(), enumerator_inspect(), enumerator_next(), enumerator_next_values(), enumerator_peek(), enumerator_peek_values_m(), enumerator_rewind(), enumerator_with_index(), enumerator_with_object(), generator_allocate(), generator_each(), generator_init_copy(), generator_initialize(), ID2SYM, id_each, id_rewind, obj_to_enum(), rb_cEnumerator, rb_cGenerator, rb_cObject, rb_cYielder, rb_define_alloc_func(), rb_define_class(), rb_define_class_under(), rb_define_method(), rb_eIndexError, rb_eStopIteration, rb_include_module(), rb_intern, rb_mEnumerable, rb_mKernel, rb_provide(), stop_result(), sym_each, yielder_allocate(), yielder_initialize(), yielder_yield(), and yielder_yield_push().

static VALUE inspect_enumerator | ( | VALUE | obj,
|  | VALUE | dummy,
|  | int | recur
| ) |  | `[static]`

Definition at line 726 of file enumerator.c.

References argc, enumerator::args, argv, enumerator_data_type, enumerator::meth, enumerator::obj, OBJ_TAINT, OBJ_TAINTED, OBJ_UNTRUST, OBJ_UNTRUSTED, Qundef, RARRAY_LEN, RARRAY_PTR, rb_id2name(), rb_inspect(), rb_obj_classname(), rb_sprintf(), rb_str_buf_cat2(), rb_str_concat(), TRUE, and TypedData_Get_Struct.

Referenced by enumerator_inspect().

static VALUE next_i | ( | VALUE | curr,
|  | VALUE | obj
| ) |  | `[static]`

Definition at line 429 of file enumerator.c.

References enumerator_ptr(), id_each, next_ii(), Qnil, rb_block_call, rb_eStopIteration, rb_exc_new2(), rb_fiber_yield(), rb_intern, rb_ivar_set(), result, and enumerator::stop_exc.

Referenced by next_init().

static VALUE next_ii | ( | VALUE | i,
|  | VALUE | obj,
|  | int | argc,
|  | VALUE * | argv
| ) |  | `[static]`

Definition at line 415 of file enumerator.c.

References enumerator::args, enumerator_ptr(), enumerator::feedvalue, Qnil, Qundef, rb_ary_new4(), and rb_fiber_yield().

Referenced by next_i().

static void next_init | ( | VALUE | obj,
|  | struct enumerator * | e
| ) |  | `[static]`

Definition at line 442 of file enumerator.c.

References enumerator::dst, enumerator::fib, enumerator::lookahead, next_i(), Qundef, rb_fiber_current(), and rb_fiber_new().

Referenced by get_next_values().

static VALUE obj_to_enum | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | obj
| ) |  | `[static]`

Definition at line 171 of file enumerator.c.

References argc, enumerator::meth, rb_enumeratorize(), and sym_each.

Referenced by Init_Enumerator().

VALUE rb_enumeratorize | ( | VALUE | obj,
|  | VALUE | meth,
|  | int | argc,
|  | VALUE * | argv
| ) |  |

Definition at line 300 of file enumerator.c.

References enumerator_allocate(), enumerator_init(), and rb_cEnumerator.

Referenced by obj_to_enum().

VALUE rb_obj_is_proc | ( | VALUE | proc | ) |

Definition at line 87 of file proc.c.

Referenced by caller_setup_args(), generator_initialize(), iseq_s_disasm(), proc_eq(), rb_hash_set_default_proc(), rb_mod_define_method(), set_trace_func(), and thread_add_trace_func().

static VALUE stop_result | ( | VALUE | self | ) | `[static]`

Definition at line 1067 of file enumerator.c.

References rb_attr_get(), and rb_intern.

Referenced by Init_Enumerator().

static VALUE yielder_allocate | ( | VALUE | klass | ) | `[static]`

Definition at line 834 of file enumerator.c.

References yielder::proc, Qundef, TypedData_Make_Struct, and yielder_data_type.

Referenced by Init_Enumerator(), and yielder_new().

static VALUE yielder_init | ( | VALUE | obj,
|  | VALUE | proc
| ) |  | `[static]`

Definition at line 846 of file enumerator.c.

References yielder::proc, rb_eArgError, rb_raise(), TypedData_Get_Struct, and yielder_data_type.

Referenced by yielder_initialize(), and yielder_new().

static VALUE yielder_initialize | ( | VALUE | obj | ) | `[static]`

Definition at line 863 of file enumerator.c.

References rb_block_proc(), rb_need_block(), and yielder_init().

Referenced by Init_Enumerator().

static void yielder_mark | ( | void * | p | ) | `[static]`

Definition at line 799 of file enumerator.c.

References yielder::proc, and rb_gc_mark().

static size_t yielder_memsize | ( | const void * | p | ) | `[static]`

Definition at line 808 of file enumerator.c.

static VALUE yielder_new | ( | void |  | ) | `[static]`

Definition at line 893 of file enumerator.c.

References rb_cYielder, rb_proc_new(), yielder_allocate(), yielder_init(), and yielder_yield_i().

Referenced by generator_each().

static struct yielder* yielder_ptr | ( | VALUE | obj | ) | `[static, read]`

Definition at line 821 of file enumerator.c.

References yielder::proc, Qundef, rb_eArgError, rb_raise(), TypedData_Get_Struct, and yielder_data_type.

Referenced by yielder_yield().

static VALUE yielder_yield | ( | VALUE | obj,
|  | VALUE | args
| ) |  | `[static]`

Definition at line 872 of file enumerator.c.

References yielder::proc, rb_proc_call(), and yielder_ptr().

Referenced by Init_Enumerator(), and yielder_yield_push().

static VALUE yielder_yield_i | ( | VALUE | obj,
|  | VALUE | memo,
|  | int | argc,
|  | VALUE * | argv
| ) |  | `[static]`

Definition at line 887 of file enumerator.c.

References rb_yield_values2().

Referenced by yielder_new().

static VALUE yielder_yield_push | ( | VALUE | obj,
|  | VALUE | args
| ) |  | `[static]`

Definition at line 880 of file enumerator.c.

References yielder_yield().

Referenced by Init_Enumerator().

## Variable Documentation

const rb_data_type_t enumerator_data_type`[static]`

Initial value:

     {
        "enumerator",
        enumerator_mark,
        enumerator_free,
        enumerator_memsize,
    }

Definition at line 132 of file enumerator.c.

Referenced by enumerator_allocate(), enumerator_init(), enumerator_init_copy(), enumerator_ptr(), and inspect_enumerator().

const rb_data_type_t generator_data_type`[static]`

Initial value:

     {
        "generator",
        generator_mark,
        generator_free,
        generator_memsize,
    }

Definition at line 916 of file enumerator.c.

Referenced by generator_allocate(), generator_init(), generator_init_copy(), and generator_ptr().

ID id_each

Definition at line 79 of file enumerator.c.

Referenced by Init_Enumerator(), and next_i().

ID id_rewind`[static]`

Definition at line 79 of file enumerator.c.

Referenced by enumerator_rewind(), and Init_Enumerator().

VALUE rb_cEnumerator

Definition at line 78 of file enumerator.c.

Referenced by enum_chunk(), enum_slice_before(), Init_Enumerator(), and rb_enumeratorize().

VALUE rb_cGenerator`[static]`

Definition at line 95 of file enumerator.c.

Referenced by enumerator_initialize(), and Init_Enumerator().

VALUE rb_cYielder

Definition at line 95 of file enumerator.c.

Referenced by Init_Enumerator(), and yielder_new().

VALUE rb_eStopIteration

Definition at line 82 of file enumerator.c.

Referenced by Init_Enumerator(), next_i(), rb_f_loop(), and zip_i().

VALUE sym_each`[static]`

Definition at line 80 of file enumerator.c.

Referenced by enumerator_initialize(), Init_Enumerator(), and obj_to_enum().

const rb_data_type_t yielder_data_type`[static]`

Initial value:

     {
        "yielder",
        yielder_mark,
        yielder_free,
        yielder_memsize,
    }

Definition at line 813 of file enumerator.c.

Referenced by yielder_allocate(), yielder_init(), and yielder_ptr().