summaryrefslogtreecommitdiff
path: root/array.c
AgeCommit message (Collapse)Author
2024-05-02Rename ary_heap_alloc -> ary_heap_alloc_bufferMatt Valentine-House
To differentiate it from ary_alloc_heap
2024-04-14Resize ary when `Array#sort!` block modifies embedded aryZack Deveau
In cases where `rb_ary_sort_bang` is called with a block and tmp is an embedded array, we need to account for the block potentially impacting the capacity of ary. ex: ``` var_0 = (1..70).to_a var_0.sort! do |var_0_block_129, var_1_block_129| var_0.pop var_1_block_129 <=> var_0_block_129 end.shift(3) ``` The above example can put the array into a corrupted state resulting in a heap buffer overflow and possible segfault: ``` ERROR: AddressSanitizer: heap-buffer-overflow on address [...] WRITE of size 560 at 0x60b0000034f0 thread T0 [...] ``` This commit adds a conditional to determine when the capacity of ary has been modified by the provided block. If this is the case, ensure that the capacity of ary is adjusted to handle at minimum the len of tmp.
2024-03-31Add missing RB_GC_GUARDs related to DATA_PTRKJ Tsanaktsidis
I discovered the problem in `compile.c` from a failing TestIseqLoad#test_stressful_roundtrip test with ASAN enabled. The other two changes in array.c and string.c I found by auditing similar usages of DATA_PTR in the codebase. [Bug #20402]
2024-03-13[DOC] Array doc (#10199)Burdette Lamar
2024-03-06Add 'In brief' for Array#[]BurdetteLamar
2024-02-23Remove unneeded RUBY_FUNC_EXPORTEDPeter Zhu
2024-02-14[DOC] Doc compliance (#9955)Burdette Lamar
2024-02-12Comply with doc guideBurdetteLamar
2024-02-12Replace assert with RUBY_ASSERT in array.cPeter Zhu
assert does not print the bug report, only the file and line number of the assertion that failed. RUBY_ASSERT prints the full bug report, which makes it much easier to debug.
2024-01-23Rewrite Array#each in Ruby using Primitive (#9533)Takashi Kokubun
2024-01-18[DOC] correct doc comment for rb_ary_asetEdwing123
Signed-off-by: Edwin Garcia <[email protected]>
2024-01-09[DOC] Enhance documentation for `Array#zip`Akshay Birajdar
2023-12-27[DOC] Add parentheses to Array#eql?Peter Zhu
Makes the call-seq and code more consistent in format.
2023-12-25[DOC] Link to Array#eql? from Array#hashPeter Zhu
2023-12-23Remove useless `#if 1` in array.cPeter Zhu
2023-12-21Fix ary_make_partial_step for compactionPeter Zhu
ary could change embeddedness due to compaction, so we should only get the pointer after allocations. The included test was crashing with: TestArray#test_slice_gc_compact_stress ruby/lib/pp.rb:192: [BUG] Segmentation fault at 0x0000000000000038
2023-12-18[DOC] No document for internal or debug methodsNobuyoshi Nakada
2023-11-29Array#rassoc should try to convert to array implicitly. Fixes #20003Tema Bolshakov
2023-11-27Fix compaction during ary_make_partialPeter Zhu
The ary_make_shared call may allocate, which can trigger a GC compaction. This can cause the array to be embedded because it has a length of 0.
2023-11-22Get rid of flatten_memo_data_typeJean Boussier
We can use an hidden Hash instead, it's simpler, triggers write barriers, handle compaction, etc.
2023-09-04Keep write-barrier status after splicing arrayPeter Zhu
We don't need to remove the write-barrier protected status after splicing an array. We can simply add it to the rememberset for marking during the next GC. The benchmark illustrates the performance impact on minor GC: ``` require "benchmark" arys = 1_000_000.times.map do ary = Array.new(50) ary.insert(1, 3) ary end 4.times { GC.start } puts(Benchmark.measure do 1000.times do GC.start(full_mark: false) end end) ``` This branch: ``` 1.309910 0.004342 1.314252 ( 1.314580) ``` Master branch: ``` 54.376091 0.219037 54.595128 ( 54.742996) ``` Notes: Merged: https://github.com/ruby/ruby/pull/8350
2023-08-29[DOC] Remove typoNobuyoshi Nakada
2023-08-29Fix Array#bsearch when block returns a non-integer numeric valueKouhei Yanagita
Notes: Merged: https://github.com/ruby/ruby/pull/8314
2023-08-18Refactor ary_make_partialPeter Zhu
2023-08-11[DOC] Don't suppress autolinks (#8207)Burdette Lamar
Notes: Merged-By: peterzhu2118 <[email protected]>
2023-08-03No computing embed_capa_max in ary_make_partialKunshan Wang
ary_make_partial now uses the actual embed_capa of an allocated heap array to guide whether make an embedded copy or a slice view. Notes: Merged: https://github.com/ruby/ruby/pull/8164
2023-07-13Don't pass array into ary_heap_allocPeter Zhu
We no longer need a reference to the array when allocating the buffer because we no longer allocate through the transient heap. Notes: Merged: https://github.com/ruby/ruby/pull/8071
2023-07-13Remove unused references to the transient heapPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/8071
2023-07-13Remove RARRAY_CONST_PTR_TRANSIENTPeter Zhu
RARRAY_CONST_PTR now does the same things as RARRAY_CONST_PTR_TRANSIENT. Notes: Merged: https://github.com/ruby/ruby/pull/8071
2023-07-13Remove RARRAY_PTR_USE_TRANSIENTPeter Zhu
RARRAY_PTR_USE now does the same things as RARRAY_PTR_USE_TRANSIENT. Notes: Merged: https://github.com/ruby/ruby/pull/8071
2023-07-13[Feature #19730] Remove transient heapPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7942
2023-06-01[DOC] Mention the edge case of `any?`/`all?`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7883
2023-05-17Implement Hash ST tables on VWAPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7742
2023-05-10[DOC] Move docs of `Array#first` and `Array#last` to array.rbNobuyoshi Nakada
2023-05-09Document that Array#{&,intersection,intersect?} use hash method [ci skip]Jeremy Evans
Fixes [Bug #19622]
2023-04-19* expand tabs. [ci skip]git
Please consider using misc/expand_tabs.rb as a pre-commit hook.
2023-04-18Emit special instruction for array literal + .(hash|min|max)Aaron Patterson
This commit introduces a new instruction `opt_newarray_send` which is used when there is an array literal followed by either the `hash`, `min`, or `max` method. ``` [a, b, c].hash ``` Will emit an `opt_newarray_send` instruction. This instruction falls back to a method call if the "interested" method has been monkey patched. Here are some examples of the instructions generated: ``` $ ./miniruby --dump=insns -e '[@a, @b].max' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE) 0000 getinstancevariable :@a, <is:0> ( 1)[Li] 0003 getinstancevariable :@b, <is:1> 0006 opt_newarray_send 2, :max 0009 leave $ ./miniruby --dump=insns -e '[@a, @b].min' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE) 0000 getinstancevariable :@a, <is:0> ( 1)[Li] 0003 getinstancevariable :@b, <is:1> 0006 opt_newarray_send 2, :min 0009 leave $ ./miniruby --dump=insns -e '[@a, @b].hash' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,13)> (catch: FALSE) 0000 getinstancevariable :@a, <is:0> ( 1)[Li] 0003 getinstancevariable :@b, <is:1> 0006 opt_newarray_send 2, :hash 0009 leave ``` [Feature #18897] [ruby-core:109147] Co-authored-by: John Hawthorn <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/6090
2023-04-06[Feature #19474] Refactor NEWOBJ macrosMatt Valentine-House
NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec Notes: Merged: https://github.com/ruby/ruby/pull/7393
2023-04-04[Feature #19579] Remove !USE_RVARGC code (#7655)Peter Zhu
Remove !USE_RVARGC code [Feature #19579] The Variable Width Allocation feature was turned on by default in Ruby 3.2. Since then, we haven't received bug reports or backports to the non-Variable Width Allocation code paths, so we assume that nobody is using it. We also don't plan on maintaining the non-Variable Width Allocation code, so we are going to remove it. Notes: Merged-By: maximecb <[email protected]>
2023-04-01Remove an unneeded function copyTakashi Kokubun
2023-03-23`Array#first` and `Array#last` in RubyKoichi Sasada
Notes: Merged: https://github.com/ruby/ruby/pull/7486
2023-03-15rb_ary_sum: don't enter fast path if initial isn't a native numeric type.Jean Boussier
[Bug #19530] If the initial value isn't one of the special cased types, we directly jump to the slow path. Notes: Merged: https://github.com/ruby/ruby/pull/7519
2023-03-08Adjust styles [ci skip]Nobuyoshi Nakada
2023-03-07YJIT: Handle splat+rest for args pass greater than required (#7468)Jimmy Miller
For example: ```ruby def my_func(x, y, *rest) p [x, y, rest] end my_func(1, 2, 3, *[4, 5]) ``` Notes: Merged-By: maximecb <[email protected]>
2023-03-06Stop exporting symbols for MJITTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-02-19Remove (newly unneeded) remarks about aliasesBurdetteLamar
2023-02-02Keep shared arrays WB protectedPeter Zhu
Sharing an array will cause it to be WB unprotected due to the use of `RARRAY_PTR`. We don't need to WB unprotect the array because we're not writing to the buffer of the array. The following script demonstrates this issue: ``` ary = [1] * 1000 shared = ary[10..20] puts ObjectSpace.dump(ary) ``` Notes: Merged: https://github.com/ruby/ruby/pull/7224
2023-01-24Remove function ary_recycle_hashPeter Zhu
Freeing the memory of a Hash should be done by the garbage collector and not by array functions. This could potentially leak memory if ary_recycle_hash was not implemented properly. Notes: Merged: https://github.com/ruby/ruby/pull/7165
2023-01-10Remove ARY_SET_SHAREDPeter Zhu
We don't need ARY_SET_SHARED since we already have rb_ary_set_shared. Notes: Merged: https://github.com/ruby/ruby/pull/7089
2022-12-23Don't allow re-embedding frozen arraysPeter Zhu
Frozen arrays should not move from heap allocated to embedded because frozen arrays could be shared roots for other (shared) arrays. If the frozen array moves from heap allocated to embedded it would cause issues since the shared array would no longer know where to set the pointer in the shared root. Notes: Merged: https://github.com/ruby/ruby/pull/7013