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

335 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 8b48b57fd8
Comparing nonnull argument to NULL is useless 2021-09-23 16:55:35 +09:00
S-H-GAMELINKS 83a5e2bb5c Using RB_FLOAT_TYPE_P macro 2021-09-12 11:16:31 +09:00
S-H-GAMELINKS bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
Nobuyoshi Nakada e4f891ce8d
Adjust styles [ci skip]
* --braces-after-func-def-line
* --dont-cuddle-else
* --procnames-start-lines
* --space-after-for
* --space-after-if
* --space-after-while
2021-06-17 10:13:40 +09:00
Jeremy Evans fd8991f797 Fix lazy enumerator with index size
Fixes [Bug #17889]
2021-05-27 14:17:32 -07:00
Jeremy Evans 9c31fb6114 Fix documentation for Enumerator::Lazy#with_index
If a block is given, it returns a lazy enumerator that will iterate
over the block, it doesn't iterate over the block immediately.

Fixes [Bug #17789]
2021-04-09 10:44:07 -07:00
Jeremy Evans 68d028578a Undef Enumerator::Chain#{feed,next,next_values,peek,peek_values}
Previously these methods were defined but raised TypeError, which
seems worse.
2021-03-06 13:56:16 -08:00
Jeremy Evans e1d16a9e56 Make Enumerator#{+,chain} create lazy chain if any included enumerator is lazy
Implements [Feature #17347]
2021-03-06 13:56:16 -08:00
Jeremy Evans bf40fe9fed Fix calling enumerator methods such as with_index on Enumerator::Chain
This previously raised a TypeError.  Wrap the Enumerator::Chain in
an Enumerator to work around the problem.

Fixes [Bug #17216]
2021-03-06 13:56:16 -08:00
Masataka Pocke Kuwabara 391ee3ee3a Replace `Kernel.#open` with `URI.open` in doc
Because `Kernel.#open` no longer opens URI since Ruby 3.0.
2021-01-08 07:31:27 -08:00
zverok b8d33df1d9 Add Enumerable#compact and Enumerator::Lazy#compact 2021-01-02 17:27:24 +09:00
卜部昌平 fa356a798a Enumerator.new: raise unless block given
Has been deprecated since c73b6bd7eb.
[Feature #17116] [ruby-dev:50945]
2020-12-22 13:52:03 +09:00
Victor Shepelev 5253b9579a
Document usage of ArithmeticSequence in Array#slice, and add to NEWS (#3952) 2020-12-21 09:32:30 +09:00
Kenta Murata fad3023e94
Fix ArithmeticSequence#last and ArithmeticSequence#each for non-integer sequences (#3870)
[Bug #17218]
[ruby-core:100312]
2020-12-09 18:48:59 +09:00
Nobuyoshi Nakada 4640c4ea8a
Removed more unnecessary ID caches
```
find . -name \*.o -exec nm {} + |&
grep -e 'InitVM_.*\.rbimpl_id' -e 'Init_.*\.rbimpl_id' |
sed 's/^.* b //;s/\.[1-9][0-9]*$//;s/\.rbimpl_id$//' |
uniq
```
should be empty.
2020-10-21 13:04:20 +09:00
Kenta Murata a6a8576e87
Feature #16812: Allow slicing arrays with ArithmeticSequence (#3241)
* 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]
2020-10-21 02:40:18 +09:00
卜部昌平 ff30358d13 RARRAY_AREF: convert into an inline function
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.
2020-08-15 12:09:26 +09:00
Nobuyoshi Nakada 54acb3dd52
Improved Enumerable::Lazy#zip
|                    |compare-ruby|built-ruby|
|:-------------------|-----------:|---------:|
|first_ary           |    290.514k|  296.331k|
|                    |           -|     1.02x|
|first_nonary        |    166.954k|  169.178k|
|                    |           -|     1.01x|
|first_noarg         |    299.547k|  305.358k|
|                    |           -|     1.02x|
|take3_ary           |    129.388k|  188.360k|
|                    |           -|     1.46x|
|take3_nonary        |     90.684k|  112.688k|
|                    |           -|     1.24x|
|take3_noarg         |    131.940k|  189.471k|
|                    |           -|     1.44x|
|chain-first_ary     |    195.913k|  286.194k|
|                    |           -|     1.46x|
|chain-first_nonary  |    127.483k|  168.716k|
|                    |           -|     1.32x|
|chain-first_noarg   |    201.252k|  298.562k|
|                    |           -|     1.48x|
|chain-take3_ary     |    101.189k|  183.188k|
|                    |           -|     1.81x|
|chain-take3_nonary  |     75.381k|  112.301k|
|                    |           -|     1.49x|
|chain-take3_noarg   |    101.483k|  192.148k|
|                    |           -|     1.89x|
|block               |    296.696k|  292.877k|
|                    |       1.01x|         -|
2020-07-23 16:57:26 +09:00
Nobuyoshi Nakada 6b3cff12f6
Improved Enumerable::Lazy#flat_map
|        |compare-ruby|built-ruby|
|:-------|-----------:|---------:|
|num3    |     96.333k|  160.732k|
|        |           -|     1.67x|
|num10   |     96.615k|  159.150k|
|        |           -|     1.65x|
|ary2    |    103.836k|  172.787k|
|        |           -|     1.66x|
|ary10   |    109.249k|  177.252k|
|        |           -|     1.62x|
|ary20   |    106.628k|  177.371k|
|        |           -|     1.66x|
|ary50   |    107.135k|  162.282k|
|        |           -|     1.51x|
|ary100  |    106.513k|  177.626k|
|        |           -|     1.67x|
2020-07-23 16:57:26 +09:00
Nobuyoshi Nakada 89a86788e6
New functions to pass more elements than passed 2020-07-23 16:57:25 +09:00
Masataka Pocke Kuwabara 752041ca11
Update Enumerable::Yielder#to_proc document (#3142) 2020-05-26 23:46:42 -07:00
Masataka Pocke Kuwabara 64c5bf5721
Fix non-existent method reference in Enumerator.produce document (#3141) 2020-05-26 23:37:05 -07:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada 5d430c1b34
Added more NORETURN declarations 2020-05-11 00:40:14 +09:00
Marc-Andre Lafortune 7bde98125e Improve documentation for Enumerator#next, next_values, peek and peek_values.
[DOC] [#16829]
2020-05-05 17:04:11 -04:00
gerero20 bfe706716f [ci skip] Enumerator doc cleanup
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.
2020-04-11 11:23:30 +09:00
Nobuyoshi Nakada 11d5a8318d
Suppress C4244 "possible loss of data" warnings 2020-04-08 18:03:46 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada c47cd4be28
Removed duplicated code 2020-02-09 16:00:18 +09:00
Jeremy Evans beae6cbf0f Fully separate positional arguments and keyword arguments
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().
2020-01-02 18:40:45 -08:00
卜部昌平 5e22f873ed decouple internal.h headers
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).
2019-12-26 20:45:12 +09:00
Marcus Stollsteimer 27b4f477d9 [DOC] Improve docs for Enumerator.produce, Enumerator.new 2019-12-24 09:03:42 +01:00
zverok a4b99f9764 Fix typos of previous docs PR
In #2612 I made two typos (extra ,, and copy-pasted
same line of code instead of showing two different
ones), fixing them.
2019-12-23 08:36:58 +09:00
Marcus Stollsteimer 7c37f2cb1a Some fixes in Enumerator::Lazy docs
* fix list in #flat_map
* fix wrong indentation in #filter_map and #with_index
* other small fixes
2019-12-22 19:46:24 +01:00
Nobuyoshi Nakada c6c67254fb
Added rb_warn_deprecated 2019-12-19 09:52:17 +09:00
Jeremy Evans 85e43e1dfe Fix Enumerator::Lazy#with_index
* 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]
2019-12-11 04:59:56 +02:00
Jeremy Evans a029b54ec7 Make Enumerator::Chain#each treat lambdas as lambda
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]
2019-12-03 23:18:28 +02:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
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.
2019-11-18 01:00:25 +02:00
Lourens Naudé 0e68913f81 Right size the Enumerator internal lazy_use_super_method hash 2019-10-29 11:31:34 +09:00
zverok 417369e0cd Improve Enumerator.produce docs
* Add to NEWS;
* Add examples of while-alike cycles with practical tasks.
2019-10-27 18:57:39 +09:00
zverok bddb31bb37 Documentation improvements for Ruby core
* Top-level `return`;
* Documentation for comments syntax;
* `rescue` inside blocks;
* Enhance `Object#to_enum` docs;
* Make `chomp:` option more obvious for `String#each_line` and
  `#lines`;
* Enhance `Proc#>>` and `#<<` docs;
* Enhance `Processs` class docs.
2019-10-26 14:58:08 +09:00
Jeremy Evans 3073404e74 Add rb_enumeratorize_with_size_kw and related macros
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.
2019-09-30 07:06:42 -07:00
Jeremy Evans 660c7e050f Fix more keyword separation issues
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
2019-09-26 19:24:58 -07:00
Jeremy Evans 37f9213f89 Fix keyword argument separation issues in Enumerator::Generator#each
This requires adding rb_proc_call_kw to pass the keyword flag.
2019-09-26 15:30:51 -07:00
Jeremy Evans c9f2b790ad Handle keyword argument separation for Enumerator#size
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.
2019-09-20 07:45:18 -07:00
Jeremy Evans 3cfbfa9628 Consolidate empty keyword handling
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.
2019-09-13 16:42:27 -07:00
Akinori MUSHA ac3e8834e0
Document and test Enumerator.produce
Co-authored-by: Victor Shepelev <zverok.offline@gmail.com>
2019-09-12 20:18:53 +09:00
Akinori MUSHA 775037613b
Implement Enumerator.produce [Feature #14781] 2019-09-12 20:18:53 +09:00
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