* Support ArithmeticSequence in Array#slice
* Extract rb_range_component_beg_len
* Use rb_range_values to check Range object
* Fix ary_make_partial_step
* Fix for negative step cases
* range.c: Describe the role of err argument in rb_range_component_beg_len
* Raise a RangeError when an arithmetic sequence refers the outside of an array
[Feature #16812]
RARRAY_AREF has been a macro for reasons. We might not be able to
change that for public APIs, but why not relax the situation internally
to make it an inline function.
This is my first attempt at a pull request. I was reading the ruby docs
the other day and noticed that the output didn't match the code sample
on the with_object documentation. Inserted spaces to fix it.
This removes the warnings added in 2.7, and changes the behavior
so that a final positional hash is not treated as keywords or
vice-versa.
To handle the arg_setup_block splat case correctly with keyword
arguments, we need to check if we are taking a keyword hash.
That case didn't have a test, but it affects real-world code,
so add a test for it.
This removes rb_empty_keyword_given_p() and related code, as
that is not needed in Ruby 3. The empty keyword case is the
same as the no keyword case in Ruby 3.
This changes rb_scan_args to implement keyword argument
separation for C functions when the : character is used.
For backwards compatibility, it returns a duped hash.
This is a bad idea for performance, but not duping the hash
breaks at least Enumerator::ArithmeticSequence#inspect.
Instead of having RB_PASS_CALLED_KEYWORDS be a number,
simplify the code by just making it be rb_keyword_given_p().
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead. This would significantly
speed up incremental builds.
We take the following inclusion order in this changeset:
1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very
first thing among everything).
2. RUBY_EXTCONF_H if any.
3. Standard C headers, sorted alphabetically.
4. Other system headers, maybe guarded by #ifdef
5. Everything else, sorted alphabetically.
Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
* Make it correctly handle lambdas
* Make it iterate over the block if block is given
The original implementation was flawed, based on lazy_set_method
instead of lazy_add_method.
Note that there is no implicit map when passing a block, the return
value of the block passed to with_index is ignored, just as it
is for Enumerator#with_index. Also like Enumerator#with_index,
when called with a block, the return value is an enumerator without
the index.
Fixes [Bug #16414]
Previously, lambdas were converted to procs because of how
rb_block_call works. Switch to rb_funcall_with_block, which
handles procs as procs and lambdas as lambdas.
Fixes [Bug #15613]
This removes the related tests, and puts the related specs behind
version guards. This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
Currently, there is not a way to create a sized enumerator in C
with a different set of arguments than provided by Ruby, and
correctly handle keyword arguments. This function allows that.
The need for this is fairly uncommon, but it occurs at least in
Enumerator.produce, which takes arugments from Ruby but calls
rb_enumeratorize_with_size with a different set of arguments.
This fixes instance_exec and similar methods. It also fixes
Enumerator::Yielder#yield, rb_yield_block, and a couple of cases
with Proc#{<<,>>}.
This support requires the addition of rb_yield_values_kw, similar to
rb_yield_values2, for passing the keyword flag.
Unlike earlier attempts at this, this does not modify the rb_block_call_func
type or add a separate function type. The functions of type
rb_block_call_func are called by Ruby with a separate VM frame, and we can
get the keyword flag information from the VM frame flags, so it doesn't need
to be passed as a function argument.
These changes require the following VM functions accept a keyword flag:
* vm_yield_with_cref
* vm_yield
* vm_yield_with_block
When Object#to_enum is passed a block, the block is called to get
a size with the arguments given to to_enum. This calls the block
with the same keyword flag as to_enum is called with.
This requires adding rb_check_funcall_kw and
rb_check_funcall_default_kw to handle keyword flags.
Remove rb_add_empty_keyword, and instead of calling that every
place you need to add empty keyword hashes, run that code in
a single static function in vm_eval.c.
Add 4 defines to include/ruby/ruby.h, these are to be used as
int kw_splat values when calling the various rb_*_kw functions:
RB_NO_KEYWORDS :: Do not pass keywords
RB_PASS_KEYWORDS :: Pass final argument (which should be hash) as keywords
RB_PASS_EMPTY_KEYWORDS :: Add an empty hash to arguments and pass as keywords
RB_PASS_CALLED_KEYWORDS :: Passes same keyword type as current method was
called with (for method delegation)
rb_empty_keyword_given_p needs to stay. It is required if argument
delegation is done but delayed to a later point, which Enumerator
does.
Use RB_PASS_CALLED_KEYWORDS in rb_call_super to correctly
delegate keyword arguments to super method.
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.
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.
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]
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]
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.
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.
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.
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.
* 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
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
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
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
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
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
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
* 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
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
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
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
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
Make sure Enumerator::ArithmeticSequence#each to work well
for a complex step value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64692 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
added documentation of Enumerator::Lazy#force, just to clarify that it
is an alias of an inherited method. [ruby-core:88872] [Bug #15079]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This fixes a bug of Enumerator::ArithmeticSequence#last in the case that
a non-integral argument is passed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Undefine new and allocate methods of Enumerator::ArithmeticSequence.
[ruby-core:82816] [Feature #13904]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit introduces new core class Enumerator::ArithmeticSequence.
Enumerator::ArithmeticSequence is a subclass of Enumerator, and
represents a number generator of an arithmetic sequence.
After this commit, Numeric#step and Range#step without blocks
returned an ArithmeticSequence object instead of an Enumerator.
This class introduces the following incompatibilities:
- You can create a zero-step ArithmeticSequence,
and its size is not ArgumentError, but Infinity.
- You can create a negative-step ArithmeticSequence from a range.
[ruby-core:82816] [Feature #13904]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* In Enumerable, Enumerator::Lazy, Array, Hash and Set
[Feature #13784] [ruby-core:82285]
* Share specs for the various #select#select! methods and
reuse them for #filter/#filter!.
* Add corresponding filter tests for select tests.
* Update NEWS.
[Fix GH-1824]
From: Alexander Patrick <adp90@case.edu>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Needlessly exporting can reduce performance locally and increase
binary size.
Increasing the footprint of our C-API larger is also detrimental
to our development as it encourages tighter coupling with our
internals; making it harder for us to preserve compatibility.
If some parts of the core codebase needs access to globals,
internal.h should be used instead of anything in include/ruby/*.
"Urabe, Shyouhei" <shyouhei@ruby-lang.org> wrote:
> On Thu, Jan 18, 2018 at 7:33 PM, Eric Wong <normalperson@yhbt.net> wrote:
> > shyouhei@ruby-lang.org wrote:
> >> https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61908
> >>
> >> export rb_mFConst
> >
> > Why are we exporting all these and making the public C-API bigger?
> > If anything, we should make these static. Thanks.
>
> No concrete reason, except they have already been externed in 2.5.
> These variables had lacked declarations so far, which resulted in their
> visibility to be that of extern. The commit is just confirming the status quo.
>
> I'm not against to turn them into static.
This reverts changes from r61910, r61909, r61908, r61907, and r61906.
* transcode.c (rb_eUndefinedConversionError): make static
(rb_eInvalidByteSequenceError): ditto
(rb_eConverterNotFoundError): ditto
* process.c (rb_mProcGID, rb_mProcUid, rb_mProcID_Syscall): ditto
* file.c (rb_mFConst): ditto
* error.c (rb_mWarning, rb_cWarningBuffer): ditto
* enumerator.c (rb_cLazy): ditto
[Misc #14381]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
It seems HUGE_VAL is already used. Why not eliminate INTINITY.
NAN is also float. That of double is called nan(). This is also
fixed.
Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e