Project

General

Profile

Feature #10318 ยป convert_tabs_to_spaces.patch

gogotanaka (Kazuki Tanaka), 10/05/2014 10:46 PM

View differences:

enumerator.c
164 164
static const rb_data_type_t enumerator_data_type = {
165 165
    "enumerator",
166 166
    {
167
	enumerator_mark,
168
	enumerator_free,
169
	enumerator_memsize,
167
        enumerator_mark,
168
        enumerator_free,
169
        enumerator_memsize,
170 170
    },
171 171
    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
172 172
};
......
178 178

  
179 179
    TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, ptr);
180 180
    if (!ptr || ptr->obj == Qundef) {
181
	rb_raise(rb_eArgError, "uninitialized enumerator");
181
        rb_raise(rb_eArgError, "uninitialized enumerator");
182 182
    }
183 183
    return ptr;
184 184
}
......
244 244
    VALUE enumerator, meth = sym_each;
245 245

  
246 246
    if (argc > 0) {
247
	--argc;
248
	meth = *argv++;
247
        --argc;
248
        meth = *argv++;
249 249
    }
250 250
    enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
251 251
    if (rb_block_given_p()) {
252
	enumerator_ptr(enumerator)->size = rb_block_proc();
252
        enumerator_ptr(enumerator)->size = rb_block_proc();
253 253
    }
254 254
    return enumerator;
255 255
}
......
275 275
    TypedData_Get_Struct(enum_obj, struct enumerator, &enumerator_data_type, ptr);
276 276

  
277 277
    if (!ptr) {
278
	rb_raise(rb_eArgError, "unallocated enumerator");
278
        rb_raise(rb_eArgError, "unallocated enumerator");
279 279
    }
280 280

  
281 281
    ptr->obj  = obj;
......
337 337
    VALUE size = Qnil;
338 338

  
339 339
    if (rb_block_given_p()) {
340
	rb_check_arity(argc, 0, 1);
341
	recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
342
	if (argc) {
340
        rb_check_arity(argc, 0, 1);
341
        recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
342
        if (argc) {
343 343
            if (NIL_P(argv[0]) || rb_respond_to(argv[0], id_call) ||
344 344
                (RB_TYPE_P(argv[0], T_FLOAT) && RFLOAT_VALUE(argv[0]) == INFINITY)) {
345 345
                size = argv[0];
......
351 351
        }
352 352
    }
353 353
    else {
354
	rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
355
	rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
356
	recv = *argv++;
357
	if (--argc) {
358
	    meth = *argv++;
359
	    --argc;
360
	}
354
        rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
355
        rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
356
        recv = *argv++;
357
        if (--argc) {
358
            meth = *argv++;
359
            --argc;
360
        }
361 361
    }
362 362

  
363 363
    return enumerator_init(obj, recv, meth, argc, argv, 0, size);
......
372 372
    if (!OBJ_INIT_COPY(obj, orig)) return obj;
373 373
    ptr0 = enumerator_ptr(orig);
374 374
    if (ptr0->fib) {
375
	/* Fibers cannot be copied */
376
	rb_raise(rb_eTypeError, "can't copy execution context");
375
        /* Fibers cannot be copied */
376
        rb_raise(rb_eTypeError, "can't copy execution context");
377 377
    }
378 378

  
379 379
    TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, ptr1);
380 380

  
381 381
    if (!ptr1) {
382
	rb_raise(rb_eArgError, "unallocated enumerator");
382
        rb_raise(rb_eArgError, "unallocated enumerator");
383 383
    }
384 384

  
385 385
    ptr1->obj  = ptr0->obj;
......
412 412
    /* Similar effect as calling obj.to_enum, i.e. dispatching to either
413 413
       Kernel#to_enum vs Lazy#to_enum */
414 414
    if (RTEST(rb_obj_is_kind_of(obj, rb_cLazy)))
415
	return lazy_to_enum_i(obj, meth, argc, argv, size_fn);
415
        return lazy_to_enum_i(obj, meth, argc, argv, size_fn);
416 416
    else
417
	return enumerator_init(enumerator_allocate(rb_cEnumerator),
418
			       obj, meth, argc, argv, size_fn, Qnil);
417
        return enumerator_init(enumerator_allocate(rb_cEnumerator),
418
                               obj, meth, argc, argv, size_fn, Qnil);
419 419
}
420 420

  
421 421
static VALUE
......
427 427
    ID meth = e->meth;
428 428

  
429 429
    if (e->args) {
430
	argc = RARRAY_LENINT(e->args);
431
	argv = RARRAY_CONST_PTR(e->args);
430
        argc = RARRAY_LENINT(e->args);
431
        argv = RARRAY_CONST_PTR(e->args);
432 432
    }
433 433
    return rb_block_call(e->obj, meth, argc, argv, func, arg);
434 434
}
......
473 473
enumerator_each(int argc, VALUE *argv, VALUE obj)
474 474
{
475 475
    if (argc > 0) {
476
	struct enumerator *e = enumerator_ptr(obj = rb_obj_dup(obj));
477
	VALUE args = e->args;
478
	if (args) {
476
        struct enumerator *e = enumerator_ptr(obj = rb_obj_dup(obj));
477
        VALUE args = e->args;
478
        if (args) {
479 479
#if SIZEOF_INT < SIZEOF_LONG
480
	    /* check int range overflow */
481
	    rb_long2int(RARRAY_LEN(args) + argc);
480
            /* check int range overflow */
481
            rb_long2int(RARRAY_LEN(args) + argc);
482 482
#endif
483
	    args = rb_ary_dup(args);
484
	    rb_ary_cat(args, argv, argc);
485
	}
486
	else {
487
	    args = rb_ary_new4(argc, argv);
488
	}
489
	e->args = args;
483
            args = rb_ary_dup(args);
484
            rb_ary_cat(args, argv, argc);
485
        }
486
        else {
487
            args = rb_ary_new4(argc, argv);
488
        }
489
        e->args = args;
490 490
    }
491 491
    if (!rb_block_given_p()) return obj;
492 492
    return enumerator_block_call(obj, 0, obj);
......
500 500
    memo->u1.value = rb_int_succ(idx);
501 501

  
502 502
    if (argc <= 1)
503
	return rb_yield_values(2, val, idx);
503
        return rb_yield_values(2, val, idx);
504 504

  
505 505
    return rb_yield_values(2, rb_ary_new4(argc, argv), idx);
506 506
}
......
534 534
    rb_scan_args(argc, argv, "01", &memo);
535 535
    RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_enum_size);
536 536
    if (NIL_P(memo))
537
	memo = INT2FIX(0);
537
        memo = INT2FIX(0);
538 538
    else
539
	memo = rb_to_int(memo);
539
        memo = rb_to_int(memo);
540 540
    return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)NEW_MEMO(memo, 0, 0));
541 541
}
542 542

  
......
560 560
enumerator_with_object_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, memo))
561 561
{
562 562
    if (argc <= 1)
563
	return rb_yield_values(2, val, memo);
563
        return rb_yield_values(2, val, memo);
564 564

  
565 565
    return rb_yield_values(2, rb_ary_new4(argc, argv), memo);
566 566
}
......
645 645
    VALUE curr, vs;
646 646

  
647 647
    if (e->stop_exc)
648
	rb_exc_raise(e->stop_exc);
648
        rb_exc_raise(e->stop_exc);
649 649

  
650 650
    curr = rb_fiber_current();
651 651

  
652 652
    if (!e->fib || !rb_fiber_alive_p(e->fib)) {
653
	next_init(obj, e);
653
        next_init(obj, e);
654 654
    }
655 655

  
656 656
    vs = rb_fiber_resume(e->fib, 1, &curr);
657 657
    if (e->stop_exc) {
658
	e->fib = 0;
659
	e->dst = Qnil;
660
	e->lookahead = Qundef;
661
	e->feedvalue = Qundef;
662
	rb_exc_raise(e->stop_exc);
658
        e->fib = 0;
659
        e->dst = Qnil;
660
        e->lookahead = Qundef;
661
        e->feedvalue = Qundef;
662
        rb_exc_raise(e->stop_exc);
663 663
    }
664 664
    return vs;
665 665
}
......
901 901
    struct enumerator *e = enumerator_ptr(obj);
902 902

  
903 903
    if (e->feedvalue != Qundef) {
904
	rb_raise(rb_eTypeError, "feed value already set");
904
        rb_raise(rb_eTypeError, "feed value already set");
905 905
    }
906 906
    e->feedvalue = v;
907 907

  
......
945 945
    cname = rb_obj_class(obj);
946 946

  
947 947
    if (!e || e->obj == Qundef) {
948
	return rb_sprintf("#<%"PRIsVALUE": uninitialized>", rb_class_path(cname));
948
        return rb_sprintf("#<%"PRIsVALUE": uninitialized>", rb_class_path(cname));
949 949
    }
950 950

  
951 951
    if (recur) {
952
	str = rb_sprintf("#<%"PRIsVALUE": ...>", rb_class_path(cname));
953
	OBJ_TAINT(str);
954
	return str;
952
        str = rb_sprintf("#<%"PRIsVALUE": ...>", rb_class_path(cname));
953
        OBJ_TAINT(str);
954
        return str;
955 955
    }
956 956

  
957 957
    eobj = rb_attr_get(obj, id_receiver);
958 958
    if (NIL_P(eobj)) {
959
	eobj = e->obj;
959
        eobj = e->obj;
960 960
    }
961 961

  
962 962
    /* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */
......
975 975

  
976 976
    method = rb_attr_get(obj, id_method);
977 977
    if (method != Qfalse) {
978
	if (!NIL_P(method)) {
979
	    Check_Type(method, T_SYMBOL);
980
	    method = rb_sym2str(method);
981
	}
982
	else {
983
	    method = rb_id2str(default_method);
984
	}
985
	rb_str_buf_cat2(str, ":");
986
	rb_str_buf_append(str, method);
978
        if (!NIL_P(method)) {
979
            Check_Type(method, T_SYMBOL);
980
            method = rb_sym2str(method);
981
        }
982
        else {
983
            method = rb_id2str(default_method);
984
        }
985
        rb_str_buf_cat2(str, ":");
986
        rb_str_buf_append(str, method);
987 987
    }
988 988

  
989 989
    eargs = rb_attr_get(obj, id_arguments);
990 990
    if (NIL_P(eargs)) {
991
	eargs = default_args;
991
        eargs = default_args;
992 992
    }
993 993
    if (eargs != Qfalse) {
994
	long   argc = RARRAY_LEN(eargs);
995
	const VALUE *argv = RARRAY_CONST_PTR(eargs); /* WB: no new reference */
994
        long   argc = RARRAY_LEN(eargs);
995
        const VALUE *argv = RARRAY_CONST_PTR(eargs); /* WB: no new reference */
996 996

  
997
	if (argc > 0) {
998
	    rb_str_buf_cat2(str, "(");
997
        if (argc > 0) {
998
            rb_str_buf_cat2(str, "(");
999 999

  
1000
	    while (argc--) {
1001
		VALUE arg = *argv++;
1000
            while (argc--) {
1001
                VALUE arg = *argv++;
1002 1002

  
1003
		rb_str_append(str, rb_inspect(arg));
1004
		rb_str_buf_cat2(str, argc > 0 ? ", " : ")");
1005
		OBJ_INFECT(str, arg);
1006
	    }
1007
	}
1003
                rb_str_append(str, rb_inspect(arg));
1004
                rb_str_buf_cat2(str, argc > 0 ? ", " : ")");
1005
                OBJ_INFECT(str, arg);
1006
            }
1007
        }
1008 1008
    }
1009 1009

  
1010 1010
    return str;
......
1043 1043
    VALUE size;
1044 1044

  
1045 1045
    if (e->size_fn) {
1046
	return (*e->size_fn)(e->obj, e->args, obj);
1046
        return (*e->size_fn)(e->obj, e->args, obj);
1047 1047
    }
1048 1048
    if (e->args) {
1049
	argc = (int)RARRAY_LEN(e->args);
1050
	argv = RARRAY_CONST_PTR(e->args);
1049
        argc = (int)RARRAY_LEN(e->args);
1050
        argv = RARRAY_CONST_PTR(e->args);
1051 1051
    }
1052 1052
    size = rb_check_funcall(e->size, id_call, argc, argv);
1053 1053
    if (size != Qundef) return size;
......
1075 1075
static const rb_data_type_t yielder_data_type = {
1076 1076
    "yielder",
1077 1077
    {
1078
	yielder_mark,
1079
	yielder_free,
1080
	yielder_memsize,
1078
        yielder_mark,
1079
        yielder_free,
1080
        yielder_memsize,
1081 1081
    },
1082 1082
    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
1083 1083
};
......
1089 1089

  
1090 1090
    TypedData_Get_Struct(obj, struct yielder, &yielder_data_type, ptr);
1091 1091
    if (!ptr || ptr->proc == Qundef) {
1092
	rb_raise(rb_eArgError, "uninitialized yielder");
1092
        rb_raise(rb_eArgError, "uninitialized yielder");
1093 1093
    }
1094 1094
    return ptr;
1095 1095
}
......
1115 1115
    TypedData_Get_Struct(obj, struct yielder, &yielder_data_type, ptr);
1116 1116

  
1117 1117
    if (!ptr) {
1118
	rb_raise(rb_eArgError, "unallocated yielder");
1118
        rb_raise(rb_eArgError, "unallocated yielder");
1119 1119
    }
1120 1120

  
1121 1121
    ptr->proc = proc;
......
1182 1182
static const rb_data_type_t generator_data_type = {
1183 1183
    "generator",
1184 1184
    {
1185
	generator_mark,
1186
	generator_free,
1187
	generator_memsize,
1185
        generator_mark,
1186
        generator_free,
1187
        generator_memsize,
1188 1188
    },
1189 1189
    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
1190 1190
};
......
1196 1196

  
1197 1197
    TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr);
1198 1198
    if (!ptr || ptr->proc == Qundef) {
1199
	rb_raise(rb_eArgError, "uninitialized generator");
1199
        rb_raise(rb_eArgError, "uninitialized generator");
1200 1200
    }
1201 1201
    return ptr;
1202 1202
}
......
1223 1223
    TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr);
1224 1224

  
1225 1225
    if (!ptr) {
1226
	rb_raise(rb_eArgError, "unallocated generator");
1226
        rb_raise(rb_eArgError, "unallocated generator");
1227 1227
    }
1228 1228

  
1229 1229
    ptr->proc = proc;
......
1238 1238
    VALUE proc;
1239 1239

  
1240 1240
    if (argc == 0) {
1241
	rb_need_block();
1241
        rb_need_block();
1242 1242

  
1243
	proc = rb_block_proc();
1243
        proc = rb_block_proc();
1244 1244
    }
1245 1245
    else {
1246
	rb_scan_args(argc, argv, "1", &proc);
1246
        rb_scan_args(argc, argv, "1", &proc);
1247 1247

  
1248
	if (!rb_obj_is_proc(proc))
1249
	    rb_raise(rb_eTypeError,
1250
		     "wrong argument type %s (expected Proc)",
1251
		     rb_obj_classname(proc));
1248
        if (!rb_obj_is_proc(proc))
1249
            rb_raise(rb_eTypeError,
1250
                     "wrong argument type %s (expected Proc)",
1251
                     rb_obj_classname(proc));
1252 1252

  
1253
	if (rb_block_given_p()) {
1254
	    rb_warn("given block not used");
1255
	}
1253
        if (rb_block_given_p()) {
1254
            rb_warn("given block not used");
1255
        }
1256 1256
    }
1257 1257

  
1258 1258
    return generator_init(obj, proc);
......
1271 1271
    TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr1);
1272 1272

  
1273 1273
    if (!ptr1) {
1274
	rb_raise(rb_eArgError, "unallocated generator");
1274
        rb_raise(rb_eArgError, "unallocated generator");
1275 1275
    }
1276 1276

  
1277 1277
    ptr1->proc = ptr0->proc;
......
1288 1288

  
1289 1289
    rb_ary_push(args, yielder_new());
1290 1290
    if (argc > 0) {
1291
	rb_ary_cat(args, argv, argc);
1291
        rb_ary_cat(args, argv, argc);
1292 1292
    }
1293 1293

  
1294 1294
    return rb_proc_call(ptr->proc, args);
......
1325 1325
{
1326 1326
    VALUE result;
1327 1327
    if (argc == 1) {
1328
	VALUE args[2];
1329
	args[0] = m;
1330
	args[1] = val;
1331
	result = rb_yield_values2(2, args);
1328
        VALUE args[2];
1329
        args[0] = m;
1330
        args[1] = val;
1331
        result = rb_yield_values2(2, args);
1332 1332
    }
1333 1333
    else {
1334
	VALUE args;
1335
	int len = rb_long2int((long)argc + 1);
1334
        VALUE args;
1335
        int len = rb_long2int((long)argc + 1);
1336 1336

  
1337
	args = rb_ary_tmp_new(len);
1338
	rb_ary_push(args, m);
1339
	if (argc > 0) {
1340
	    rb_ary_cat(args, argv, argc);
1341
	}
1342
	result = rb_yield_values2(len, RARRAY_CONST_PTR(args));
1343
	RB_GC_GUARD(args);
1337
        args = rb_ary_tmp_new(len);
1338
        rb_ary_push(args, m);
1339
        if (argc > 0) {
1340
            rb_ary_cat(args, argv, argc);
1341
        }
1342
        result = rb_yield_values2(len, RARRAY_CONST_PTR(args));
1343
        RB_GC_GUARD(args);
1344 1344
    }
1345 1345
    if (result == Qundef) rb_iter_break();
1346 1346
    return Qnil;
......
1389 1389

  
1390 1390
    rb_check_arity(argc, 1, 2);
1391 1391
    if (!rb_block_given_p()) {
1392
	rb_raise(rb_eArgError, "tried to call lazy new without a block");
1392
        rb_raise(rb_eArgError, "tried to call lazy new without a block");
1393 1393
    }
1394 1394
    obj = argv[0];
1395 1395
    if (argc > 1) {
1396
	size = argv[1];
1396
        size = argv[1];
1397 1397
    }
1398 1398
    generator = generator_allocate(rb_cGenerator);
1399 1399
    rb_block_call(generator, id_initialize, 0, 0, lazy_init_block_i, obj);
......
1410 1410
    struct enumerator *e = enumerator_ptr(lazy);
1411 1411
    rb_ivar_set(lazy, id_method, ID2SYM(id));
1412 1412
    if (NIL_P(args)) {
1413
	/* Qfalse indicates that the arguments are empty */
1414
	rb_ivar_set(lazy, id_arguments, Qfalse);
1413
        /* Qfalse indicates that the arguments are empty */
1414
        rb_ivar_set(lazy, id_arguments, Qfalse);
1415 1415
    }
1416 1416
    else {
1417
	rb_ivar_set(lazy, id_arguments, args);
1417
        rb_ivar_set(lazy, id_arguments, args);
1418 1418
    }
1419 1419
    e->size_fn = size_fn;
1420 1420
    return lazy;
......
1464 1464
lazy_to_enum_i(VALUE obj, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *size_fn)
1465 1465
{
1466 1466
    return enumerator_init(enumerator_allocate(rb_cLazy),
1467
			   obj, meth, argc, argv, size_fn, Qnil);
1467
                           obj, meth, argc, argv, size_fn, Qnil);
1468 1468
}
1469 1469

  
1470 1470
/*
......
1496 1496
    VALUE lazy, meth = sym_each;
1497 1497

  
1498 1498
    if (argc > 0) {
1499
	--argc;
1500
	meth = *argv++;
1499
        --argc;
1500
        meth = *argv++;
1501 1501
    }
1502 1502
    lazy = lazy_to_enum_i(self, meth, argc, argv, 0);
1503 1503
    if (rb_block_given_p()) {
1504
	enumerator_ptr(lazy)->size = rb_block_proc();
1504
        enumerator_ptr(lazy)->size = rb_block_proc();
1505 1505
    }
1506 1506
    return lazy;
1507 1507
}
......
1519 1519
lazy_map(VALUE obj)
1520 1520
{
1521 1521
    if (!rb_block_given_p()) {
1522
	rb_raise(rb_eArgError, "tried to call lazy map without a block");
1522
        rb_raise(rb_eArgError, "tried to call lazy map without a block");
1523 1523
    }
1524 1524

  
1525 1525
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1526
					 lazy_map_func, 0),
1527
			   Qnil, lazy_receiver_size);
1526
                                         lazy_map_func, 0),
1527
                           Qnil, lazy_receiver_size);
1528 1528
}
1529 1529

  
1530 1530
static VALUE
......
1545 1545
{
1546 1546
    VALUE ary = rb_check_array_type(obj);
1547 1547
    if (NIL_P(ary)) {
1548
	rb_funcall(yielder, id_yield, 1, obj);
1548
        rb_funcall(yielder, id_yield, 1, obj);
1549 1549
    }
1550 1550
    else {
1551
	long i;
1552
	for (i = 0; i < RARRAY_LEN(ary); i++) {
1553
	    rb_funcall(yielder, id_yield, 1, RARRAY_AREF(ary, i));
1554
	}
1551
        long i;
1552
        for (i = 0; i < RARRAY_LEN(ary); i++) {
1553
            rb_funcall(yielder, id_yield, 1, RARRAY_AREF(ary, i));
1554
        }
1555 1555
    }
1556 1556
    return Qnil;
1557 1557
}
......
1561 1561
{
1562 1562
    VALUE result = rb_yield_values2(argc - 1, &argv[1]);
1563 1563
    if (RB_TYPE_P(result, T_ARRAY)) {
1564
	long i;
1565
	for (i = 0; i < RARRAY_LEN(result); i++) {
1566
	    rb_funcall(argv[0], id_yield, 1, RARRAY_AREF(result, i));
1567
	}
1564
        long i;
1565
        for (i = 0; i < RARRAY_LEN(result); i++) {
1566
            rb_funcall(argv[0], id_yield, 1, RARRAY_AREF(result, i));
1567
        }
1568 1568
    }
1569 1569
    else {
1570
	if (rb_respond_to(result, id_force) && rb_respond_to(result, id_each)) {
1571
	    lazy_flat_map_each(result, argv[0]);
1572
	}
1573
	else {
1574
	    lazy_flat_map_to_ary(result, argv[0]);
1575
	}
1570
        if (rb_respond_to(result, id_force) && rb_respond_to(result, id_each)) {
1571
            lazy_flat_map_each(result, argv[0]);
1572
        }
1573
        else {
1574
            lazy_flat_map_to_ary(result, argv[0]);
1575
        }
1576 1576
    }
1577 1577
    return Qnil;
1578 1578
}
......
1604 1604
lazy_flat_map(VALUE obj)
1605 1605
{
1606 1606
    if (!rb_block_given_p()) {
1607
	rb_raise(rb_eArgError, "tried to call lazy flat_map without a block");
1607
        rb_raise(rb_eArgError, "tried to call lazy flat_map without a block");
1608 1608
    }
1609 1609

  
1610 1610
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1611
					 lazy_flat_map_func, 0),
1612
			   Qnil, 0);
1611
                                         lazy_flat_map_func, 0),
1612
                           Qnil, 0);
1613 1613
}
1614 1614

  
1615 1615
static VALUE
......
1618 1618
    VALUE element = rb_enum_values_pack(argc - 1, argv + 1);
1619 1619

  
1620 1620
    if (RTEST(rb_yield(element))) {
1621
	return rb_funcall(argv[0], id_yield, 1, element);
1621
        return rb_funcall(argv[0], id_yield, 1, element);
1622 1622
    }
1623 1623
    return Qnil;
1624 1624
}
......
1627 1627
lazy_select(VALUE obj)
1628 1628
{
1629 1629
    if (!rb_block_given_p()) {
1630
	rb_raise(rb_eArgError, "tried to call lazy select without a block");
1630
        rb_raise(rb_eArgError, "tried to call lazy select without a block");
1631 1631
    }
1632 1632

  
1633 1633
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1634
					 lazy_select_func, 0),
1635
			   Qnil, 0);
1634
                                         lazy_select_func, 0),
1635
                           Qnil, 0);
1636 1636
}
1637 1637

  
1638 1638
static VALUE
......
1641 1641
    VALUE element = rb_enum_values_pack(argc - 1, argv + 1);
1642 1642

  
1643 1643
    if (!RTEST(rb_yield(element))) {
1644
	return rb_funcall(argv[0], id_yield, 1, element);
1644
        return rb_funcall(argv[0], id_yield, 1, element);
1645 1645
    }
1646 1646
    return Qnil;
1647 1647
}
......
1650 1650
lazy_reject(VALUE obj)
1651 1651
{
1652 1652
    if (!rb_block_given_p()) {
1653
	rb_raise(rb_eArgError, "tried to call lazy reject without a block");
1653
        rb_raise(rb_eArgError, "tried to call lazy reject without a block");
1654 1654
    }
1655 1655

  
1656 1656
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1657
					 lazy_reject_func, 0),
1658
			   Qnil, 0);
1657
                                         lazy_reject_func, 0),
1658
                           Qnil, 0);
1659 1659
}
1660 1660

  
1661 1661
static VALUE
......
1665 1665
    VALUE result = rb_funcall(m, id_eqq, 1, i);
1666 1666

  
1667 1667
    if (RTEST(result)) {
1668
	rb_funcall(argv[0], id_yield, 1, i);
1668
        rb_funcall(argv[0], id_yield, 1, i);
1669 1669
    }
1670 1670
    return Qnil;
1671 1671
}
......
1677 1677
    VALUE result = rb_funcall(m, id_eqq, 1, i);
1678 1678

  
1679 1679
    if (RTEST(result)) {
1680
	rb_funcall(argv[0], id_yield, 1, rb_yield(i));
1680
        rb_funcall(argv[0], id_yield, 1, rb_yield(i));
1681 1681
    }
1682 1682
    return Qnil;
1683 1683
}
......
1686 1686
lazy_grep(VALUE obj, VALUE pattern)
1687 1687
{
1688 1688
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1689
					 rb_block_given_p() ?
1690
					 lazy_grep_iter : lazy_grep_func,
1691
					 pattern),
1692
			   rb_ary_new3(1, pattern), 0);
1689
                                         rb_block_given_p() ?
1690
                                         lazy_grep_iter : lazy_grep_func,
1691
                                         pattern),
1692
                           rb_ary_new3(1, pattern), 0);
1693 1693
}
1694 1694

  
1695 1695
static VALUE
......
1717 1717
    ary = rb_ary_new2(RARRAY_LEN(arrays) + 1);
1718 1718
    rb_ary_push(ary, argv[1]);
1719 1719
    for (i = 0; i < RARRAY_LEN(arrays); i++) {
1720
	rb_ary_push(ary, rb_ary_entry(RARRAY_AREF(arrays, i), count));
1720
        rb_ary_push(ary, rb_ary_entry(RARRAY_AREF(arrays, i), count));
1721 1721
    }
1722 1722
    rb_funcall(yielder, id_yield, 1, ary);
1723 1723
    rb_ivar_set(yielder, id_memo, LONG2NUM(++count));
......
1733 1733
    yielder = argv[0];
1734 1734
    arg = rb_attr_get(yielder, id_memo);
1735 1735
    if (NIL_P(arg)) {
1736
	arg = rb_ary_new2(RARRAY_LEN(zip_args));
1737
	for (i = 0; i < RARRAY_LEN(zip_args); i++) {
1738
	    rb_ary_push(arg, rb_funcall(RARRAY_AREF(zip_args, i), id_to_enum, 0));
1739
	}
1740
	rb_ivar_set(yielder, id_memo, arg);
1736
        arg = rb_ary_new2(RARRAY_LEN(zip_args));
1737
        for (i = 0; i < RARRAY_LEN(zip_args); i++) {
1738
            rb_ary_push(arg, rb_funcall(RARRAY_AREF(zip_args, i), id_to_enum, 0));
1739
        }
1740
        rb_ivar_set(yielder, id_memo, arg);
1741 1741
    }
1742 1742

  
1743 1743
    ary = rb_ary_new2(RARRAY_LEN(arg) + 1);
1744 1744
    v = Qnil;
1745 1745
    if (--argc > 0) {
1746
	++argv;
1747
	v = argc > 1 ? rb_ary_new_from_values(argc, argv) : *argv;
1746
        ++argv;
1747
        v = argc > 1 ? rb_ary_new_from_values(argc, argv) : *argv;
1748 1748
    }
1749 1749
    rb_ary_push(ary, v);
1750 1750
    for (i = 0; i < RARRAY_LEN(arg); i++) {
1751
	v = rb_rescue2(call_next, RARRAY_AREF(arg, i), next_stopped, 0,
1752
		       rb_eStopIteration, (VALUE)0);
1753
	rb_ary_push(ary, v);
1751
        v = rb_rescue2(call_next, RARRAY_AREF(arg, i), next_stopped, 0,
1752
                       rb_eStopIteration, (VALUE)0);
1753
        rb_ary_push(ary, v);
1754 1754
    }
1755 1755
    rb_funcall(yielder, id_yield, 1, ary);
1756 1756
    return Qnil;
......
1764 1764
    rb_block_call_func *func = lazy_zip_arrays_func;
1765 1765

  
1766 1766
    if (rb_block_given_p()) {
1767
	return rb_call_super(argc, argv);
1767
        return rb_call_super(argc, argv);
1768 1768
    }
1769 1769

  
1770 1770
    ary = rb_ary_new2(argc);
1771 1771
    for (i = 0; i < argc; i++) {
1772
	v = rb_check_array_type(argv[i]);
1773
	if (NIL_P(v)) {
1774
	    for (; i < argc; i++) {
1775
		if (!rb_respond_to(argv[i], id_each)) {
1776
		    rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)",
1777
			rb_obj_classname(argv[i]));
1778
		}
1779
	    }
1780
	    ary = rb_ary_new4(argc, argv);
1781
	    func = lazy_zip_func;
1782
	    break;
1783
	}
1784
	rb_ary_push(ary, v);
1772
        v = rb_check_array_type(argv[i]);
1773
        if (NIL_P(v)) {
1774
            for (; i < argc; i++) {
1775
                if (!rb_respond_to(argv[i], id_each)) {
1776
                    rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)",
1777
                        rb_obj_classname(argv[i]));
1778
                }
1779
            }
1780
            ary = rb_ary_new4(argc, argv);
1781
            func = lazy_zip_func;
1782
            break;
1783
        }
1784
        rb_ary_push(ary, v);
1785 1785
    }
1786 1786

  
1787 1787
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1788
					 func, ary),
1789
			   ary, lazy_receiver_size);
1788
                                         func, ary),
1789
                           ary, lazy_receiver_size);
1790 1790
}
1791 1791

  
1792 1792
static VALUE
......
1795 1795
    long remain;
1796 1796
    VALUE memo = rb_attr_get(argv[0], id_memo);
1797 1797
    if (NIL_P(memo)) {
1798
	memo = args;
1798
        memo = args;
1799 1799
    }
1800 1800

  
1801 1801
    rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
1802 1802
    if ((remain = NUM2LONG(memo)-1) == 0) {
1803
	return Qundef;
1803
        return Qundef;
1804 1804
    }
1805 1805
    else {
1806
	rb_ivar_set(argv[0], id_memo, LONG2NUM(remain));
1807
	return Qnil;
1806
        rb_ivar_set(argv[0], id_memo, LONG2NUM(remain));
1807
        return Qnil;
1808 1808
    }
1809 1809
}
1810 1810

  
......
1814 1814
    VALUE receiver = lazy_size(lazy);
1815 1815
    long len = NUM2LONG(RARRAY_AREF(rb_ivar_get(lazy, id_arguments), 0));
1816 1816
    if (NIL_P(receiver) || (FIXNUM_P(receiver) && FIX2LONG(receiver) < len))
1817
	return receiver;
1817
        return receiver;
1818 1818
    return LONG2NUM(len);
1819 1819
}
1820 1820

  
......
1825 1825
    VALUE lazy;
1826 1826

  
1827 1827
    if (len < 0) {
1828
	rb_raise(rb_eArgError, "attempt to take negative size");
1828
        rb_raise(rb_eArgError, "attempt to take negative size");
1829 1829
    }
1830 1830
    if (len == 0) {
1831
	VALUE len = INT2FIX(0);
1832
	lazy = lazy_to_enum_i(obj, sym_cycle, 1, &len, 0);
1831
        VALUE len = INT2FIX(0);
1832
        lazy = lazy_to_enum_i(obj, sym_cycle, 1, &len, 0);
1833 1833
    }
1834 1834
    else {
1835
	lazy = rb_block_call(rb_cLazy, id_new, 1, &obj,
1836
					 lazy_take_func, n);
1835
        lazy = rb_block_call(rb_cLazy, id_new, 1, &obj,
1836
                                         lazy_take_func, n);
1837 1837
    }
1838 1838
    return lazy_set_method(lazy, rb_ary_new3(1, n), lazy_take_size);
1839 1839
}
......
1851 1851
lazy_take_while(VALUE obj)
1852 1852
{
1853 1853
    if (!rb_block_given_p()) {
1854
	rb_raise(rb_eArgError, "tried to call lazy take_while without a block");
1854
        rb_raise(rb_eArgError, "tried to call lazy take_while without a block");
1855 1855
    }
1856 1856
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1857
					 lazy_take_while_func, 0),
1858
			   Qnil, 0);
1857
                                         lazy_take_while_func, 0),
1858
                           Qnil, 0);
1859 1859
}
1860 1860

  
1861 1861
static VALUE
......
1864 1864
    long len = NUM2LONG(RARRAY_AREF(rb_ivar_get(lazy, id_arguments), 0));
1865 1865
    VALUE receiver = lazy_size(lazy);
1866 1866
    if (NIL_P(receiver))
1867
	return receiver;
1867
        return receiver;
1868 1868
    if (FIXNUM_P(receiver)) {
1869
	len = FIX2LONG(receiver) - len;
1870
	return LONG2FIX(len < 0 ? 0 : len);
1869
        len = FIX2LONG(receiver) - len;
1870
        return LONG2FIX(len < 0 ? 0 : len);
1871 1871
    }
1872 1872
    return rb_funcall(receiver, '-', 1, LONG2NUM(len));
1873 1873
}
......
1878 1878
    long remain;
1879 1879
    VALUE memo = rb_attr_get(argv[0], id_memo);
1880 1880
    if (NIL_P(memo)) {
1881
	memo = args;
1881
        memo = args;
1882 1882
    }
1883 1883
    if ((remain = NUM2LONG(memo)) == 0) {
1884
	rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
1884
        rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
1885 1885
    }
1886 1886
    else {
1887
	rb_ivar_set(argv[0], id_memo, LONG2NUM(--remain));
1887
        rb_ivar_set(argv[0], id_memo, LONG2NUM(--remain));
1888 1888
    }
1889 1889
    return Qnil;
1890 1890
}
......
1895 1895
    long len = NUM2LONG(n);
1896 1896

  
1897 1897
    if (len < 0) {
1898
	rb_raise(rb_eArgError, "attempt to drop negative size");
1898
        rb_raise(rb_eArgError, "attempt to drop negative size");
1899 1899
    }
1900 1900
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1901
					 lazy_drop_func, n),
1902
			   rb_ary_new3(1, n), lazy_drop_size);
1901
                                         lazy_drop_func, n),
1902
                           rb_ary_new3(1, n), lazy_drop_size);
1903 1903
}
1904 1904

  
1905 1905
static VALUE
......
1907 1907
{
1908 1908
    VALUE memo = rb_attr_get(argv[0], id_memo);
1909 1909
    if (NIL_P(memo) && !RTEST(rb_yield_values2(argc - 1, &argv[1]))) {
1910
	rb_ivar_set(argv[0], id_memo, memo = Qtrue);
1910
        rb_ivar_set(argv[0], id_memo, memo = Qtrue);
1911 1911
    }
1912 1912
    if (memo == Qtrue) {
1913
	rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
1913
        rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
1914 1914
    }
1915 1915
    return Qnil;
1916 1916
}
......
1919 1919
lazy_drop_while(VALUE obj)
1920 1920
{
1921 1921
    if (!rb_block_given_p()) {
1922
	rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
1922
        rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
1923 1923
    }
1924 1924
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
1925
					 lazy_drop_while_func, 0),
1926
			   Qnil, 0);
1925
                                         lazy_drop_while_func, 0),
1926
                           Qnil, 0);
1927 1927
}
1928 1928

  
1929 1929
static VALUE
......
2062 2062
    rb_define_method(rb_cYielder, "yield", yielder_yield, -2);
2063 2063
    rb_define_method(rb_cYielder, "<<", yielder_yield_push, -2);
2064 2064

  
2065
    rb_provide("enumerator.so");	/* for backward compatibility */
2065
    rb_provide("enumerator.so");        /* for backward compatibility */
2066 2066
}
2067 2067

  
2068 2068
#undef rb_intern
2069
-