summaryrefslogtreecommitdiff
path: root/enum.c
AgeCommit message (Collapse)Author
2019-11-19Fix memory corruption in Enumerable#reverse_each [ruby-dev:50867] [Bug #16354]Kazuki Tsujimoto
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-08-27rb_rescue / rb_rescue2 now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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#define RB_BLOCK_CALL_FUNC_STRICT 1卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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-25Document that Enumerable#sum may not respect redefinition of Range#eachJeremy Evans
It already documented that it may not respect redefinition of Integer#+. Fixes [Bug #13700]
2019-08-17Remove redundant each from `sum` example (#2190) [ci skip]OKURA Masafumi
It used to be `Enumerator#sum`, now it's range of string which calls `Enumerable#sum` and causes TypeError.
2019-08-07enum.c: Remove unused #includeYusuke Endoh
transient_heap.h is no longer needed.
2019-08-03Predefine some IDsNobuyoshi Nakada
2019-07-09[DOC] Add link to Enumerable#grep from Enumerable#selectKazuhiro NISHIYAMA
2019-06-13squeeze space [ci skip]Kazuhiro NISHIYAMA
2019-06-13add comments to mention sort.reverse!Martin Dürst
For array.c (Array#sort) and enum.c (Enumerable#sort_by), add comments mentioning that sort.reverse! / sort_by { ... }.reverse! can/should be used to reverse the result. [ci skip]
2019-06-02Make size on an infinite each_slice enumerator return InfinityJeremy Evans
Fixes [Bug #15889]
2019-05-23enum.c (enum_tally): better example in rdocYusuke Endoh
2019-05-23Adding Enumerable#filter_mapAlfonso Jiménez
[Feature #15323] Closes: https://github.com/ruby/ruby/pull/2017
2019-05-18[DOC] Use '&&' instead of 'and' in boolean expressionMarcus Stollsteimer
2019-05-13Improve doc for Enumerable#include? and member?okuramasafumi
Existing doc for Enumerable#include? and member? has some problems. * `IO.constants` is not commonly used, and only some know that `SEEK_SET` is actually included in constants. * `IO.constants` is actually an Array, not the example is not appropriate for `Enumerable` module. So in this commit, the old example is replaced with new one. New example uses integer range, which is much simpler and easier to understand. Closes: https://github.com/ruby/ruby/pull/2168
2019-04-26memo.c might not always be initializedUrabe, Shyouhei
memo.float_value might change inside of hash_sum. In case it flipped from false to true there, and the calculated sum is Inf, memo.c might not be initialized at all. This is bad. Found using memory sanitizer: ==55293==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x55dfb8d6c529 in rb_float_new_inline internal.h:1814:53 #1 0x55dfb8d1b30c in enum_sum enum.c:4017:18 #2 0x55dfb86d75ad in call_cfunc_m1 vm_insnhelper.c:2041:12 #3 0x55dfb864b141 in vm_call_cfunc_with_frame vm_insnhelper.c:2207:11 #4 0x55dfb85e843d in vm_call_cfunc vm_insnhelper.c:2225:12 #5 0x55dfb85e08f3 in vm_call_method_each_type vm_insnhelper.c:2560:9 #6 0x55dfb85de9c7 in vm_call_method vm_insnhelper.c:2686:13 #7 0x55dfb849eac6 in vm_call_general vm_insnhelper.c:2730:12 #8 0x55dfb8686103 in vm_sendish vm_insnhelper.c:3623:11 #9 0x55dfb84dc29e in vm_exec_core insns.def:789:11
2019-04-12[DOC] Add `ifnone` example to `find` documentation [ci skip]nagachika
[Fix GH-2110] From: OKURA Masafumi <masafumi.o1988@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22[DOC] fix markups [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-08enum.c: [DOC] tally does not take a blocknobu
[Feature #11076] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07enum.c: Enumerable#tallynobu
* enum.c (enum_tally): new methods Enumerable#tally, which group and count elements of the collection. [Feature #11076] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07enum.c: hosited out enum_hashifynobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Prefer rb_check_arity when 0 or 1 argumentsnobu
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-05Build error method name at failurenobu
So `struct nmin_data` size is reduced. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05Adjust indent [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05Prefer rb_check_arity when 0 or 1 argumentsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03make `RARRAY_PTR_USE` more conservertive.ko1
* include/ruby/ruby.h: de-transient at `RARRAY_PTR_USE` and `RARRAY_PTR_USE_START`. Introduce `RARRAY_PTR_USE_TRANSIENT` and `RARRAY_PTR_USE_START_TRANSIENT` if you don't want to de-transient an array. Generally, it is difficult so C-extension writers should not use them. * array.c: use `RARRAY_PTR_USE_TRANSIENT` if possible. * hash.c: ditto. * enum.c (enum_sort_by): remove `rb_ary_transient_heap_evacuate()` because `RARRAY_PTR_USE` do de-transient. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30introduce TransientHeap. [Bug #14858]ko1
* transient_heap.c, transient_heap.h: implement TransientHeap (theap). theap is designed for Ruby's object system. theap is like Eden heap on generational GC terminology. theap allocation is very fast because it only needs to bump up pointer and deallocation is also fast because we don't do anything. However we need to evacuate (Copy GC terminology) if theap memory is long-lived. Evacuation logic is needed for each type. See [Bug #14858] for details. * array.c: Now, theap for T_ARRAY is supported. ary_heap_alloc() tries to allocate memory area from theap. If this trial sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on. We don't need to free theap ptr. * ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that if ary is allocated at theap, force evacuation to malloc'ed memory. It makes programs slow, but very compatible with current code because theap memory can be evacuated (theap memory will be recycled). If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT() instead of RARRAY_CONST_PTR(). If you can't understand when evacuation will occur, use RARRAY_CONST_PTR(). (re-commit of r65444) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30revert r65444 and r65446 because of commit missko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30introduce TransientHeap. [Bug #14858]ko1
* transient_heap.c, transient_heap.h: implement TransientHeap (theap). theap is designed for Ruby's object system. theap is like Eden heap on generational GC terminology. theap allocation is very fast because it only needs to bump up pointer and deallocation is also fast because we don't do anything. However we need to evacuate (Copy GC terminology) if theap memory is long-lived. Evacuation logic is needed for each type. See [Bug #14858] for details. * array.c: Now, theap for T_ARRAY is supported. ary_heap_alloc() tries to allocate memory area from theap. If this trial sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on. We don't need to free theap ptr. * ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that if ary is allocated at theap, force evacuation to malloc'ed memory. It makes programs slow, but very compatible with current code because theap memory can be evacuated (theap memory will be recycled). If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT() instead of RARRAY_CONST_PTR(). If you can't understand when evacuation will occur, use RARRAY_CONST_PTR(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-29use RARRAY_AREF() instead of RARRAY_CONST_PTR().ko1
* class.c (rb_keyword_error_new): use RARRAY_AREF() because RARRAY_CONST_PTR() can introduce additional overhead in a futre. Same fixes for other files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-10revisit `RARRAY_PTR()`.ko1
* array.c (yield_indexed_values): use RARRAY_AREF/ASET instead of using RARRAY_PTR(). * enum.c (nmin_filter): ditto. * proc.c (rb_sym_to_proc): ditto. * enum.c (rb_nmin_run): use RARRAY_PTR_USE() instead of RARRAY_PTR(). It is safe because they don't make new referecen from an array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-21Fix a typo [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-20Enumerable#to_h with block and so onnobu
[Feature #15143] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13warn unused blocks with Enumerable#all? any? one? none?nobu
[Fix GH-1953] From: Koji Onishi <fursich0@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24UNREACHABLE_RETURNnobu
* include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end of non-void functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-22fix sum on infinitynobu
* array.c (rb_ary_sum): consider non-finite floats. [ruby-core:88024] [Bug #14926] * enum.c (sum_iter): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-02enum.c: bignum counternobu
* enum.c (imemo_count_up, imemo_count_value): promote the counter value to a bignum on overflow. [Bug #14805] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-02enum.c: mitigate overflowsnobu
* enum.c (enum_count): convert counters to Integer as unsigned long, instead of long, to mitigate overflows. [ruby-core:87348] [Bug #14805] * enum.c (ary_inject_op): ditto. * enum.c (each_with_index_i): ditto, instead of int. * enum.c (find_index_i, find_index_iter_i): ditto, instead of unsigned int. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-02memo->u3.cnt is long not int [Bug #14805]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-25Add a new #filter alias for #selecteregon
* 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
2018-02-13Fixing some minimal formating on enum.c examplesnobu
This will fix the formatting shown on detect|find and revese_arch generated by RDoc. [Fix GH-1816] From: Espartaco Palma <esparta@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19INFINITY is float. That of double is HUGE_VAL.shyouhei
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
2018-01-09internal.h: remove dependecy on ruby/encoding.hnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14enum.c: improve docs for Enumerable#{any?,all?,none?,one?}stomar
* enum.c: [DOC] reword docs for Enumerable#{any?,all?,none?,one?} to not mention the receiver (`enum') from call-seq, because it does not appear in the call-seq of the rendered HTML docs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12Add more example of `Enumerable#one?` [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-10Add case equality arity to Enumerable#all?, any?, none? and one?,marcandre
and specialized Array#any? and Hash#any? Based on patch by D.E. Akers [#11286] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-05enum.c: check argument firstnobu
* enum.c (enum_cycle_size): check an argument before the size of the receiver, if it is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e