[#116016] [Ruby master Bug#20150] Memory leak in grapheme clusters — "peterzhu2118 (Peter Zhu) via ruby-core" <ruby-core@...>
Issue #20150 has been reported by peterzhu2118 (Peter Zhu).
7 messages
2024/01/04
[#116382] [Ruby master Feature#20205] Enable `frozen_string_literal` by default — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Issue #20205 has been reported by byroot (Jean Boussier).
77 messages
2024/01/23
[ruby-core:116483] [Ruby master Bug#20223] For simple objects each_cons appears to work as I expect, but for other objects it seems to fail to terminate iterations when I would expect.
From:
"mjflynt (Jeffrey Flynt) via ruby-core" <ruby-core@...>
Date:
2024-01-29 16:48:16 UTC
List:
ruby-core #116483
Issue #20223 has been reported by mjflynt (Jeffrey Flynt).
----------------------------------------
Bug #20223: For simple objects each_cons appears to work as I expect, but for other objects it seems to fail to terminate iterations when I would expect.
https://bugs.ruby-lang.org/issues/20223
* Author: mjflynt (Jeffrey Flynt)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [aarch64-linux]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Reproduce process:
``` ruby
p `ruby -v`
class X
include Enumerable
attr_accessor :obj
def initialize = @obj = (1..5).to_a
def each(&block) = yield @obj.each(&block)
end
wtf = X.new
(1..5).each_cons(3) { |g| p g }
p '~' * 20
(1..5).to_a.each_cons(3) { |g| p g }
p '~' * 20
('a'..'e').each_cons(3) { |g| p g }
p '~' * 20
wtf.each_cons(3) { |g| p g }
```
Result of reproduce process
```
"ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [aarch64-linux]\n"
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
"~~~~~~~~~~~~~~~~~~~~"
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
"~~~~~~~~~~~~~~~~~~~~"
["a", "b", "c"]
["b", "c", "d"]
["c", "d", "e"]
"~~~~~~~~~~~~~~~~~~~~"
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
[4, 5, [1, 2, 3, 4, 5]]
[Done] exited with code=0 in 0.173 seconds
```
Expected result and the reason why you expect
I expect the results to not include the last line of output "[4, 5, [1, 2, 3, 4, 5]]" because my understanding is each_cons ends its iteration over the collection before it runs out of elements. In this case, this fourth row does not have enough elements to do three consecutive elements, but it is doing so anyway, appearing to use the original array as the third element before it completes.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/