Граф коммитов

286 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans 80e679ef2d Fix keyword argument separation warnings for enumerators
This makes objects created via #to_enum and related methods pass
keyword arguments as keywords.

To implement this, add a kw_splat member of struct enumerator and
struct iter_method_arg, and add rb_block_call_kw, which is the
same as rb_block_call_kw with a flag for whether the last argument
is keyword options.
2019-09-06 19:41:23 -07:00
Akinori MUSHA f6da4a5447
Describe #eager in the Enumerator::Lazy section 2019-09-04 16:16:47 +09:00
Akinori MUSHA 1d4bd229b8
Implement Enumerator::Lazy#eager [Feature #15901] 2019-09-04 16:16:46 +09:00
Jeremy Evans a7d7a0df91 Fix Enumerator::Lazy#{to_enum,enum_for} where method is defined in Lazy
Previously, passing to_enum/enum_for a method that was defined in
Lazy itself returned wrong results:

  [1,2,3].to_enum(:map).to_a
  # => [1, 2, 3]
  [1,2,3].lazy.to_enum(:map).to_a
  # => []

I'm not sure why methods that are designed to be lazy do not work
with to_enum/enum_for.  However, one possible way to work around
this bug is to have to_enum/enum_for use the implementation found
in Enumerable/Enumerator, which is what this commit does.

While this commit works around the problem, it is a band-aid, not a
real fix.  It doesn't handle aliases of Enumerable::Lazy methods,
for instance.  A better fix would be appreciated.
2019-09-03 11:30:49 -07:00
Jeremy Evans e94ac03eb0 Make Enumerator::Lazy#with_index be lazy
Previously, Enumerator::Lazy#with_index was not defined, so it
picked up the default implementation from Enumerator, which was
not lazy.

Based on earlier patch from nobu.

Fixes [Bug #7877]
2019-09-03 11:30:49 -07:00
Jeremy Evans 6724b1f83d Revert "Make Enumerator::Lazy#with_index be lazy"
This reverts commit 83498854eb.

This didn't pass rubyspec.
2019-09-01 22:35:38 -07:00
Jeremy Evans 83498854eb Make Enumerator::Lazy#with_index be lazy
Previously, Enumerator::Lazy#with_index was not defined, so it
picked up the default implementation from Enumerator, which was
not lazy.

Based on earlier patch from nobu.

Fixes [Bug #7877]
2019-09-01 22:20:05 -07:00
卜部昌平 bc3e7924bc rb_proc_new / rb_fiber_new now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_proc_new / rb_fiber_new, and applies RB_BLOCK_CALL_FUNC_ARGLIST
wherever necessary.
2019-08-27 15:52:26 +09:00
卜部昌平 5c7c2d9951 rb_rescue / rb_rescue2 now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_rescue / rb_rescue2, which revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平 7329b3339a #define RB_BLOCK_CALL_FUNC_STRICT 1
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  Let's start from making
rb_block_call_func_t strict, and apply RB_BLOCK_CALL_FUNC_ARGLIST liberally.
2019-08-27 15:52:26 +09:00
Jeremy Evans 04735c48ab Minor documentation fixes [ci skip]
From zverok (Victor Shepelev)

Fixes [Misc #16126]
2019-08-24 14:05:19 -07:00
git c393734c95 * expand tabs. 2019-08-13 23:00:56 +09:00
Aaron Patterson dd1344b81e
Add compaction callbacks for Enumerator
This commit gives Enumerator compaction support
2019-08-13 10:00:38 -04:00
Nobuyoshi Nakada 1549fbfda5
Use predefined idTo_proc 2019-08-01 16:40:03 +09:00
Nobuyoshi Nakada 16729f6430
Remove duplicate functions 2019-06-21 17:53:32 +09:00
git 432b28af90 * expand tabs. 2019-06-21 17:43:21 +09:00
Shugo Maeda 702cf3ec90
Enumerator::Lazy should support filter_map
Fixes [Bug #15949]
2019-06-21 17:42:27 +09:00
Nobuyoshi Nakada 35392ff0a0
Fix an example [ci skip] 2019-06-21 17:40:28 +09:00
Kazuhiro NISHIYAMA 887163beb8
Fix call-seq of lazy.filter_map [ci skip] 2019-06-21 17:11:11 +09:00
git 0174285e8c * expand tabs. 2019-06-21 16:31:42 +09:00
Nobuyoshi Nakada 06a622b76e
Lazy filter_map 2019-06-21 16:28:39 +09:00
Marcus Stollsteimer acf6689a8c [DOC] Improve documentation for Enumerator::Lazy 2019-05-18 13:04:04 +02:00
Aaron Patterson 0cc893d01d
Static symbols can't be moved (they are not RValue)
This is my mistake, I thought they were regular objects, but apparently
they are not.  We don't need to pin them.

Revert "Symbols can move so only cache IDs"

This reverts commit 672ee5f6ed.
2019-05-14 20:41:31 -07:00
Aaron Patterson 672ee5f6ed
Symbols can move so only cache IDs
IDs can't move, we need to use them to look up the symbol objects later.
2019-05-14 20:30:16 -07:00
Kazuhiro NISHIYAMA 48313f129a
Add `or nil` to call-seq of `Enumerator::ArithmeticSequence#begin`
```
% ruby -ve 'p (nil..).first'
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
nil
% ruby -ve 'p (nil..).begin'
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
nil
```
2019-04-27 12:22:54 +09:00
nobu 06eece87c6 enumerator.c: force hash values fixable
* enumerator.c (arith_seq_hash): force hash values fixable on
  LLP64 environment.  [ruby-core:92190] [Bug #15755]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-08 03:26:27 +00:00
mrkn f1fb989f1a enumerator.c: make arith_seq_first support nil begin
* enumerator.c: (arith_seq_first): support nil begin.

* test/ruby/test_arithmetic_sequence.rb (test_first): add assertions for
  beginless and endless arithmetic sequences.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-04 03:34:55 +00:00
hsbt f2ea705d68 Add Enumerator::Lazy docs.
* explanation of the class concept, with examples;
  * docs for all class methods (most of them just say "Like Enumerable#<methodname>, but chains operation to be lazy-evaluated.", but I believe they are useful this way because now have proper call-sequences and link to corresponding Enumerable's explanations)
  * simplified example for ::new to emphasize the main concept
  * Enumerable#lazy docs are slightly lightened and linked to this class for more in-depth explanations.

  [Misc #15529][ruby-core:91046]

  Co-authored-by: zverok <zverok.offline@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-20 23:32:11 +00:00
knu c2d3b8dfb4 Implement Enumerator::Yielder#to_proc
A Yielder object can now be directly passed to another method as a
block argument.

```ruby
enum = Enumerator.new { |y|
  Dir.glob("*.rb") { |file|
    File.open(file) { |f| f.each_line(&y) }
  }
}
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-11 09:49:14 +00:00
svn ea88f7ddf9 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 06:06:02 +00:00
mrkn 6f6cf042d2 enumerator.c: fix arith_seq_first for Infinity
* enumerator.c (arith_seq_first): fix for Float::INFINITY.

* test/ruby/test_arithmetic_sequence.rb: add tests.

* numeric.c (ruby_float_step_size): export for internal use.

* internal.h: add prototype declaration of ruby_float_step_size.

[ruby-core:90937][Bug #15518]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 06:05:57 +00:00
nobu 483c7290f2 enumerator.c: fix inspect with the last empty hash
[ruby-core:90685] [Bug #15455]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-24 00:48:15 +00:00
mrkn 7bef465e9b range.c: reject ArithmeticSequence in rb_range_values
Reject ArithmeticSequence in rb_range_values so that methods like
Array#[] raises TypeError for ArithmeticSequence as an index.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-21 13:05:16 +00:00
mrkn 09b3d38c72 enumerator.c: Fix airth_seq_each for Rational
Fix the wrong uses of rb_int_ge in arith_seq_each.

[ruby-core:90648] [Bug #15444]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-21 00:03:39 +00:00
mrkn 31eb48a0ac enumerator.c: Add rb_arithmetic_sequence_components_t
Add rb_arithmetic_sequence_components_t struct for encapsulating
the components of ArithmeticSequence.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12 07:16:07 +00:00
mrkn 914a290324 enumerator.c: rb_arithmetic_sequence_extract
New public C-API for extracting components of Enumerator::ArithmeticSequence
or Range.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12 06:39:58 +00:00
nobu 98e65d9d92 Prefer rb_check_arity when 0 or 1 arguments
Especially over checking argc then calling rb_scan_args just to
raise an ArgumentError.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 07:49:24 +00:00
ko1 1e9896ae31 use RARRAY_AREF instead of RARRAY_PTR_USE.
* enumerator.c (enum_chain_total_size): use RARRAY_AREF
  instead of RARRAY_PTR_USE because we don't need non-const
  ptr.

* enumerator.c (enum_chain_each): ditto.

* enumerator.c (enum_chain_rewind): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 03:51:55 +00:00
kazu eaf9bc00ed Add Float::INFINITY or nil to call-seq of Enumerator::Chain#size [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27 23:57:55 +00:00
normal 7b5c2d3f9e enumerator.c (enum_chain_yield_block): use predefined ID
No point in having rb_intern lookup and cache a predefined ID

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27 22:48:07 +00:00
knu 045b0e54d8 Implement Enumerator#+ and Enumerable#chain [Feature #15144]
They return an Enumerator::Chain object which is a subclass of
Enumerator, which represents a chain of enumerables that works as a
single enumerator.

```ruby
e = (1..3).chain([4, 5])
e.to_a #=> [1, 2, 3, 4, 5]

e = (1..3).each + [4, 5]
e.to_a #=> [1, 2, 3, 4, 5]
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-24 08:38:35 +00:00
shyouhei 3a083985a4 avoid division by zero
* cvt(): use signbit() instead of 1/d < 0
* w_float(): ditto
* ruby_float_step_size(): unit==0 check shall be prior to divisions
* arith_seq_float_step_size(): ditto
* rb_big_divide(): same as r65642
* fix_divide(): ditto
* rb_big_fdiv_double(): ditto
* fix_fdiv_double(): ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16 01:52:39 +00:00
svn 483dcef8fb * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22 11:23:57 +00:00
knu 8717f0787d Set the size of a new enumerator created by Enumerator#each with arguments to nil
When each() takes arguments, it is never safe to assume that the iteration
would repeat the same number of times as with each() without any
argument.  Actually, there is no way to get the exact number, so the
size should be set to nil to denote that.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22 11:23:56 +00:00
stomar ee2416e33c enumerator.c: [DOC] small fix
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12 21:55:49 +00:00
nobu aefdd4e25f Lazy Enumerator reduce intermediate array creation
[ruby-core:87907] [Bug #14908] [Fix GH-1912]

From: Anmol Chopra <chopraanmol1@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-18 08:49:40 +00:00
kazu c0f62450bb [DOC] aseq.each always return self [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 16:05:07 +00:00
mrkn 1595421ce0 [DOC] Add the documentation of ArithmeticSequence
[ci-skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 08:36:48 +00:00
mrkn 11ff6569ea enumerator.c: Fix ArithmeticSequence for complex step
Make sure Enumerator::ArithmeticSequence#each to work well
for a complex step value.

This reverts commit ca47fb329a.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 07:35:42 +00:00
mrkn ca47fb329a Revert "enumerator.c: Fix ArithmeticSequence for complex step"
This reverts commit 0a0f8238d0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 05:52:27 +00:00