ml.ruby-lang.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

ruby-core

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
ruby-core@ml.ruby-lang.org

  • 2 participants
  • 4064 discussions
[ruby-core:111244] [Ruby master Feature#19036] Provide a way to set path for File instances created with for_fd
by headius (Charles Nutter) 09 Dec '22

09 Dec '22
Issue #19036 has been updated by headius (Charles Nutter). Eregon (Benoit Daloze) wrote in #note-7: > > - Should we introduce `IO#path=`? > > I think not, AFAIK there is no need for this to be mutable. Agree. Also briefly brainstormed some possible security issues with being able to mutate the path after init. Don't want to go there and don't really see a need. > > - Should we introduce `IO#dup(..., path:)`? > > Definitely not worth the complexity, and `dup` doesn't have this general contract anyway. Agree. Additional question: why is rb_io_path not part of the public C API? Luckily, rb_file_path wasn't either, but it seems like it would be useful to expose rb_io_path now. ---------------------------------------- Feature #19036: Provide a way to set path for File instances created with for_fd https://bugs.ruby-lang.org/issues/19036#change-100535 * Author: headius (Charles Nutter) * Status: Closed * Priority: Normal ---------------------------------------- Ruby provides `IO.for_fd` to instantiate an IO object from an existing file descriptor value. The logic for this simply calls the base `IO.new` logic, which for all IO and subtypes simply wraps the given file descriptor. When called against File, or other subtypes of IO, this has the side effect of creating an IO instance with that type, e.g. `File.for_fd` will behave identically to `IO.for_fd` except that the class of the resulting object will be File. Unfortunately, this results in a File object that does not have any `path` associated with it: ``` 3.1.2 :001 > f = File.open('README.md') => #<File:README.md> 3.1.2 :002 > f.path => "README.md" 3.1.2 :003 > f2 = File.for_fd(f.fileno) => #<File:fd 5> 3.1.2 :004 > f2.path (irb):4:in `path': File is unnamed (TMPFILE?) (IOError) from (irb):4:in `<main>' from /home/headius/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>' from /home/headius/.rvm/rubies/ruby-3.1.2/bin/irb:25:in `load' from /home/headius/.rvm/rubies/ruby-3.1.2/bin/irb:25:in `<main>' ``` I propose that there should be a way, via an extra parameter or a keyword argument, to provide a path when constructing a new File via `for_fd`. Possible forms: * `File.for_fd(fileno, "my/path")` * `File.for_fd(fileno, path: "my/path")` This would necessitate a separate implementation for `File.for_fd` unless we want to make it possible to set a path for all `for_fd` calls (which may not make sense for many of them). This came up while trying to implement a pure-Ruby (plus FFI) version of the "pty" library. Without overriding the `path` function, it is not possible for the File object returned by `PTY.open` to gain the "masterpty:<slavename>" filename, and therefore it does not clearly indicate it is from a PTY. See https://github.com/jruby/jruby/pull/7391, an attempt to match inspect output for these return values using `define_singleton_method`. Providing a way to set the path would make this automatic without the singleton definition. -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:111243] [Ruby master Feature#19000] Data: Add "Copy with changes method" [Follow-on to #16122 Data: simple immutable value object]
by Eregon (Benoit Daloze) 08 Dec '22

08 Dec '22
Issue #19000 has been updated by Eregon (Benoit Daloze). I also agree the 0-kwargs case should be supported for general use like `data.with(**changes)`, whether `changes` is empty or not. And that reads fine of course. It's also like `Hash#merge` with no arguments. I think `#with` with empty kwargs should do the same as `dup`. So this depends on what `Data#dup` does. If `Data#dup` returns `self` like immutable objects (Fixnum/Symbol/true/false/nil/etc) then let's do that too, if not let's dup in that case. Note that `Data` is not truly immutable (nor always Ractor-shareable) because it can refer to mutable objects. Currently `Data#dup` creates a new instance. ---------------------------------------- Feature #19000: Data: Add "Copy with changes method" [Follow-on to #16122 Data: simple immutable value object] https://bugs.ruby-lang.org/issues/19000#change-100533 * Author: RubyBugs (A Nonymous) * Status: Open * Priority: Normal ---------------------------------------- *As requested: extracted a follow-up to #16122 Data: simple immutable value object from [this comment](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/109815)* # Proposal: Add a "Copy with changes" method to Data Assume the proposed `Data.define` exists. Seeing examples from the [[Values gem]](https://github.com/ms-ati/Values): ```ruby require "values" # A new class Point = Value.new(:x, :y) # An immutable instance Origin = Point.with(x: 0, y: 0) # Q: How do we make copies that change 1 or more values? right = Origin.with(x: 1.0) up = Origin.with(y: 1.0) up_and_right = right.with(y: up.y) # In loops movements = [ [ :x, +0.5 ], [ :x, +0.5 ], [ :y, -1.0 ], [ :x, +0.5 ], ] # position = Point(x: 1.5, y: -1.0) position = movements.inject(Origin) do |p, (field, delta)| p.with(field => p.send(field) + delta) end ``` ## Proposed detail: Call this method: `#with` ```ruby Money = Data.define(:amount, :currency) account = Money.new(amount: 100, currency: 'USD') transactions = [+10, -5, +15] account = transactions.inject(account) { |a, t| a.with(amount: a.amount + t) } #=> Money(amount: 120, currency: "USD") ``` ## Why add this "Copy with changes" method to the Data simple immutable value class? Called on an instance, it returns a new instance with only the provided parameters changed. This API affordance is now **widely adopted across many languages** for its usefulness. Why is it so useful? Because copying immutable value object instances, with 1 or more discrete changes to specific fields, is the proper and ubiquitous pattern that takes the place of mutation when working with immutable value objects. **Other languages** C# Records: “immutable record structs — Non-destructive mutation” — is called `with { ... }` https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-t… Scala Case Classes — is called `#copy` https://docs.scala-lang.org/tour/case-classes.html Java 14+ Records — Brian Goetz at Oracle is working on adding a with copy constructor inspired by C# above as we speak, likely to be called `#with` https://mail.openjdk.org/pipermail/amber-spec-experts/2022-June/003461.html Rust “Struct Update Syntax” via `..` syntax in constructor https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-insta… ## Alternatives Without a copy-with-changes method, one must construct entirely new instances using the constructor. This can either be (a) fully spelled out as boilerplate code, or (b) use a symmetrical `#to_h` to feed the keyword-args constructor. **(a) Boilerplate using constructor** ```ruby Point = Data.define(:x, :y, :z) Origin = Point.new(x: 0.0, y: 0.0, z: 0.0) change = { z: -1.5 } # Have to use full constructor -- does this even work? point = Point.new(x: Origin.x, y: Origin.y, **change) ``` **(b) Using a separately proposed `#to_h` method and constructor symmetry** ```ruby Point = Data.define(:x, :y, :z) Origin = Point.new(x: 0.0, y: 0.0, z: 0.0) change = { z: -1.5 } # Have to use full constructor -- does this even work? point = Point.new(**(Origin.to_h.merge(change))) ``` Notice that the above are not ergonomic -- leading so many of our peer language communities to adopt the `#with` method to copy an instance with discrete changes. -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:111242] [Ruby master Feature#19036] Provide a way to set path for File instances created with for_fd
by Eregon (Benoit Daloze) 08 Dec '22

08 Dec '22
Issue #19036 has been updated by Eregon (Benoit Daloze). ioquatix (Samuel Williams) wrote in #note-6: > Implemented in https://github.com/ruby/ruby/pull/6867. Thanks! > Follow up discussion: > > - Should we introduce `IO#path=`? I think not, AFAIK there is no need for this to be mutable. > - Should we introduce `IO#dup(..., path:)`? Definitely not worth the complexity, and `dup` doesn't have this general contract anyway. ---------------------------------------- Feature #19036: Provide a way to set path for File instances created with for_fd https://bugs.ruby-lang.org/issues/19036#change-100532 * Author: headius (Charles Nutter) * Status: Closed * Priority: Normal ---------------------------------------- Ruby provides `IO.for_fd` to instantiate an IO object from an existing file descriptor value. The logic for this simply calls the base `IO.new` logic, which for all IO and subtypes simply wraps the given file descriptor. When called against File, or other subtypes of IO, this has the side effect of creating an IO instance with that type, e.g. `File.for_fd` will behave identically to `IO.for_fd` except that the class of the resulting object will be File. Unfortunately, this results in a File object that does not have any `path` associated with it: ``` 3.1.2 :001 > f = File.open('README.md') => #<File:README.md> 3.1.2 :002 > f.path => "README.md" 3.1.2 :003 > f2 = File.for_fd(f.fileno) => #<File:fd 5> 3.1.2 :004 > f2.path (irb):4:in `path': File is unnamed (TMPFILE?) (IOError) from (irb):4:in `<main>' from /home/headius/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>' from /home/headius/.rvm/rubies/ruby-3.1.2/bin/irb:25:in `load' from /home/headius/.rvm/rubies/ruby-3.1.2/bin/irb:25:in `<main>' ``` I propose that there should be a way, via an extra parameter or a keyword argument, to provide a path when constructing a new File via `for_fd`. Possible forms: * `File.for_fd(fileno, "my/path")` * `File.for_fd(fileno, path: "my/path")` This would necessitate a separate implementation for `File.for_fd` unless we want to make it possible to set a path for all `for_fd` calls (which may not make sense for many of them). This came up while trying to implement a pure-Ruby (plus FFI) version of the "pty" library. Without overriding the `path` function, it is not possible for the File object returned by `PTY.open` to gain the "masterpty:<slavename>" filename, and therefore it does not clearly indicate it is from a PTY. See https://github.com/jruby/jruby/pull/7391, an attempt to match inspect output for these return values using `define_singleton_method`. Providing a way to set the path would make this automatic without the singleton definition. -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:111241] [Ruby master Misc#18976] [ANN] blade.nagaokaut.ac.jp is down
by hsbt (Hiroshi SHIBATA) 08 Dec '22

08 Dec '22
Issue #18976 has been updated by hsbt (Hiroshi SHIBATA). I restored some of mojibake messages of Japanese lists that are `ruby-list` and `ruby-dev`. ---------------------------------------- Misc #18976: [ANN] blade.nagaokaut.ac.jp is down https://bugs.ruby-lang.org/issues/18976#change-100531 * Author: hsbt (Hiroshi SHIBATA) * Status: Closed * Priority: Normal * Assignee: hsbt (Hiroshi SHIBATA) ---------------------------------------- The mail archive server named `blade.nagaokaut.ac.jp` is down now. blade had some hardware issues. Prof. Hara tries to salvage mail data and rebuild blade. But It's difficult status. I have a plan to migrate Ruby mail server includes mailing-list to Google workspace. I also rebuild mail archives using Google groups or others. Sorry for the inconvenient experience. FYI: original announce in Japanese https://github.com/ruby-no-kai/official/issues/306#issuecomment-1207819210 -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:111135] [Ruby master Bug#19167] Object#inspect does not correctly show NilClass TrueClass and FalseClass stored in instance variables
by tompng (tomoya ishida) 08 Dec '22

08 Dec '22
Issue #19167 has been reported by tompng (tomoya ishida). ---------------------------------------- Bug #19167: Object#inspect does not correctly show NilClass TrueClass and FalseClass stored in instance variables https://bugs.ruby-lang.org/issues/19167 * Author: tompng (tomoya ishida) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- ~~~ruby Object.new.instance_eval do @a = nil @b = NilClass @c = true @d = TrueClass @e = [nil, NilClass, true, TrueClass] puts self.inspect end # actual # => #<Object:0x2f15e3c8 @a=nil, @b=nil, @c=true, @d=true, @e=[nil, NilClass, true, TrueClass]> # expected # => #<Object:0x2f15e3c8 @a=nil, @b=NilClass, @c=true, @d=TrueClass, @e=[nil, NilClass, true, TrueClass]> ~~~ -- https://bugs.ruby-lang.org/
4 6
0 0
[ruby-core:111239] [Ruby master Misc#18976] [ANN] blade.nagaokaut.ac.jp is down
by hsbt (Hiroshi SHIBATA) 08 Dec '22

08 Dec '22
Issue #18976 has been updated by hsbt (Hiroshi SHIBATA). Status changed from Assigned to Closed >I'll build the simple txt archives like https://blade.ruby-lang.org/ruby-core/xxxxxx. >I restore mailing-list data to it with ruby-core, ruby-dev, ruby-list, ruby-ext and ruby-math. >Change archive link of bugs.ruby-lang.org to them. done. You can access the above archive like https://blade.ruby-lang.org/ruby-core/1 , https://blade.ruby-lang.org/ruby-dev/1 ... >I'll create the mirror program for the new mail for ruby-core and ruby-dev. also done. https://github.com/ruby/b.r-l.o/pull/170 I didn't confirm all of mail data are restored. Because I only have the archives provided from Prof. Hara, ko1 and shugo. If you find a missing messages, please share to me. I'll restore it manually. ---------------------------------------- Misc #18976: [ANN] blade.nagaokaut.ac.jp is down https://bugs.ruby-lang.org/issues/18976#change-100529 * Author: hsbt (Hiroshi SHIBATA) * Status: Closed * Priority: Normal * Assignee: hsbt (Hiroshi SHIBATA) ---------------------------------------- The mail archive server named `blade.nagaokaut.ac.jp` is down now. blade had some hardware issues. Prof. Hara tries to salvage mail data and rebuild blade. But It's difficult status. I have a plan to migrate Ruby mail server includes mailing-list to Google workspace. I also rebuild mail archives using Google groups or others. Sorry for the inconvenient experience. FYI: original announce in Japanese https://github.com/ruby-no-kai/official/issues/306#issuecomment-1207819210 -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:111238] [Ruby master Feature#19036] Provide a way to set path for File instances created with for_fd
by ioquatix (Samuel Williams) 08 Dec '22

08 Dec '22
Issue #19036 has been updated by ioquatix (Samuel Williams). Status changed from Open to Closed Implemented in https://github.com/ruby/ruby/pull/6867. Follow up discussion: - Should we introduce `IO#path=`? - Should we introduce `IO#dup(..., path:)`? ---------------------------------------- Feature #19036: Provide a way to set path for File instances created with for_fd https://bugs.ruby-lang.org/issues/19036#change-100527 * Author: headius (Charles Nutter) * Status: Closed * Priority: Normal ---------------------------------------- Ruby provides `IO.for_fd` to instantiate an IO object from an existing file descriptor value. The logic for this simply calls the base `IO.new` logic, which for all IO and subtypes simply wraps the given file descriptor. When called against File, or other subtypes of IO, this has the side effect of creating an IO instance with that type, e.g. `File.for_fd` will behave identically to `IO.for_fd` except that the class of the resulting object will be File. Unfortunately, this results in a File object that does not have any `path` associated with it: ``` 3.1.2 :001 > f = File.open('README.md') => #<File:README.md> 3.1.2 :002 > f.path => "README.md" 3.1.2 :003 > f2 = File.for_fd(f.fileno) => #<File:fd 5> 3.1.2 :004 > f2.path (irb):4:in `path': File is unnamed (TMPFILE?) (IOError) from (irb):4:in `<main>' from /home/headius/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>' from /home/headius/.rvm/rubies/ruby-3.1.2/bin/irb:25:in `load' from /home/headius/.rvm/rubies/ruby-3.1.2/bin/irb:25:in `<main>' ``` I propose that there should be a way, via an extra parameter or a keyword argument, to provide a path when constructing a new File via `for_fd`. Possible forms: * `File.for_fd(fileno, "my/path")` * `File.for_fd(fileno, path: "my/path")` This would necessitate a separate implementation for `File.for_fd` unless we want to make it possible to set a path for all `for_fd` calls (which may not make sense for many of them). This came up while trying to implement a pure-Ruby (plus FFI) version of the "pty" library. Without overriding the `path` function, it is not possible for the File object returned by `PTY.open` to gain the "masterpty:<slavename>" filename, and therefore it does not clearly indicate it is from a PTY. See https://github.com/jruby/jruby/pull/7391, an attempt to match inspect output for these return values using `define_singleton_method`. Providing a way to set the path would make this automatic without the singleton definition. -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:111235] [Ruby master Feature#19000] Data: Add "Copy with changes method" [Follow-on to #16122 Data: simple immutable value object]
by RubyBugs (A Nonymous) 07 Dec '22

07 Dec '22
Issue #19000 has been updated by RubyBugs (A Nonymous). Hi @mame! Thank you for your questions. mame (Yusuke Endoh) wrote in #note-24: > Thanks for the update. > > Now I have a question. Do you really want to write `p.with(field => p.send(field) + delta)`? I don't think it is very elegant. It is not very convincing (at least, to me) as a first motivation example. > The challenge is that this operation "make a copy of an immutable value object with 0 or more fields changed" is so fundamental, it's hard to find examples that strip away every other concern. Staying with the `Point` example, would **translate** and **invert** work better as examples that change multiple fields? ```ruby ## # Example of proposed Data#with # # To try this out: # # ruby-install ruby-3.2.0-preview3 # ## Point3d = Data.define(:x, :y, :z) do # Example only, too slow due to allocations def with(**args) raise ArgumentError unless args.keys.all? { |k| members.include? k } self.class.new(**(to_h.merge(args))) end def translate_2d(dx: 0, dy: 0) with(x: x + dx, y: y + dy) end def invert_2d with(x: -x, y: -y) end end Origin3d = Point3d.new(x: 0, y: 0, z:0) north = Origin3d.translate_2d(dy: 1.0) south = north.invert_2d east = Origin3d.translate_2d(dx: 1.0) west = east.invert_2d west == Point3d.new(x: -1.0, y: 0, z: 0) # => true mountain_height = 2.0 western_mountain = west.with(z: mountain_height) # => #<data Point3d x=-1.0, y=0, z=2.0> ``` > Also, do you need the ability to update multiple fields at once? Both motivation examples only update a single field. This may be the result of simplifying the motivation example, though. > Yes! Definitely need to update multiple fields at once > Looking at these motivation examples, there may be room to consider an API like `p.with(field) {|old_value| old_value + delta }` or something. Agreed that this probably comes out of a motivating example which is trying to calculate the new value for a **single** field based on **only** the previous value of that field. ---------------------------------------- Feature #19000: Data: Add "Copy with changes method" [Follow-on to #16122 Data: simple immutable value object] https://bugs.ruby-lang.org/issues/19000#change-100524 * Author: RubyBugs (A Nonymous) * Status: Open * Priority: Normal ---------------------------------------- *As requested: extracted a follow-up to #16122 Data: simple immutable value object from [this comment](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/109815)* # Proposal: Add a "Copy with changes" method to Data Assume the proposed `Data.define` exists. Seeing examples from the [[Values gem]](https://github.com/ms-ati/Values): ```ruby require "values" # A new class Point = Value.new(:x, :y) # An immutable instance Origin = Point.with(x: 0, y: 0) # Q: How do we make copies that change 1 or more values? right = Origin.with(x: 1.0) up = Origin.with(y: 1.0) up_and_right = right.with(y: up.y) # In loops movements = [ [ :x, +0.5 ], [ :x, +0.5 ], [ :y, -1.0 ], [ :x, +0.5 ], ] # position = Point(x: 1.5, y: -1.0) position = movements.inject(Origin) do |p, (field, delta)| p.with(field => p.send(field) + delta) end ``` ## Proposed detail: Call this method: `#with` ```ruby Money = Data.define(:amount, :currency) account = Money.new(amount: 100, currency: 'USD') transactions = [+10, -5, +15] account = transactions.inject(account) { |a, t| a.with(amount: a.amount + t) } #=> Money(amount: 120, currency: "USD") ``` ## Why add this "Copy with changes" method to the Data simple immutable value class? Called on an instance, it returns a new instance with only the provided parameters changed. This API affordance is now **widely adopted across many languages** for its usefulness. Why is it so useful? Because copying immutable value object instances, with 1 or more discrete changes to specific fields, is the proper and ubiquitous pattern that takes the place of mutation when working with immutable value objects. **Other languages** C# Records: “immutable record structs — Non-destructive mutation” — is called `with { ... }` https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-t… Scala Case Classes — is called `#copy` https://docs.scala-lang.org/tour/case-classes.html Java 14+ Records — Brian Goetz at Oracle is working on adding a with copy constructor inspired by C# above as we speak, likely to be called `#with` https://mail.openjdk.org/pipermail/amber-spec-experts/2022-June/003461.html Rust “Struct Update Syntax” via `..` syntax in constructor https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-insta… ## Alternatives Without a copy-with-changes method, one must construct entirely new instances using the constructor. This can either be (a) fully spelled out as boilerplate code, or (b) use a symmetrical `#to_h` to feed the keyword-args constructor. **(a) Boilerplate using constructor** ```ruby Point = Data.define(:x, :y, :z) Origin = Point.new(x: 0.0, y: 0.0, z: 0.0) change = { z: -1.5 } # Have to use full constructor -- does this even work? point = Point.new(x: Origin.x, y: Origin.y, **change) ``` **(b) Using a separately proposed `#to_h` method and constructor symmetry** ```ruby Point = Data.define(:x, :y, :z) Origin = Point.new(x: 0.0, y: 0.0, z: 0.0) change = { z: -1.5 } # Have to use full constructor -- does this even work? point = Point.new(**(Origin.to_h.merge(change))) ``` Notice that the above are not ergonomic -- leading so many of our peer language communities to adopt the `#with` method to copy an instance with discrete changes. -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:111228] [Ruby master Bug#19190] `Regexp.compile('regexp', 'n')` raises `unknown regexp option: n (ArgumentError)`
by koic (Koichi ITO) 07 Dec '22

07 Dec '22
Issue #19190 has been reported by koic (Koichi ITO). ---------------------------------------- Bug #19190: `Regexp.compile('regexp', 'n')` raises `unknown regexp option: n (ArgumentError)` https://bugs.ruby-lang.org/issues/19190 * Author: koic (Koichi ITO) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0dev (2022-12-07T03:32:29Z master bcd8b2f00a) [x86_64-darwin19] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- I get the following unexpected error when using Ruby 3.2.0-dev. ## Expected (Ruby 3.1 and prior) No errors: ```console % ruby -ve "Regexp.compile('regexp', 'n')" ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-darwin19] ``` ## Actual (Ruby 3.2.0-dev) An unexpected error occurs. ```console % ruby -ve "Regexp.compile('regexp', 'n')" ruby 3.2.0dev (2022-12-07T03:32:29Z master bcd8b2f00a) [x86_64-darwin19] -e:1:in `initialize': unknown regexp option: n (ArgumentError) Regexp.compile('regexp', 'n') ^^^^^^^^^^^^^ from -e:1:in `compile' from -e:1:in `<main>' ``` ## Context I encountered the following error when developing the Parser gem with Ruby 3.2.0-dev. This is not encountered in Ruby 3.1. ```console % cd whitequark/parser % bundle exec rake racc --superclass=Parser::Base lib/parser/ruby32.y -o lib/parser/ruby32.rb --no-line-convert /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/statetransitiontable.rb:219:in `initialize': unknown regexp option: n (ArgumentError) Regexp.compile(map, 'n') ^^^^^^^^ from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/statetransitiontable.rb:219:in `compile' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/statetransitiontable.rb:219:in `mkmapexp' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/statetransitiontable.rb:179:in `addent' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/statetransitiontable.rb:122:in `block in gen_action_tables' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/state.rb:56:in `each' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/state.rb:56:in `each_state' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/statetransitiontable.rb:112:in `gen_action_tables' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/statetransitiontable.rb:72:in `generate' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/statetransitiontable.rb:35:in `generate' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/state.rb:93:in `state_transition_table' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/grammar.rb:153:in `parser_class' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/grammarfileparser.rb:144:in `<module:Racc>' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/grammarfileparser.rb:20:in `<top (required)>' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/static.rb:3:in `require' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/lib/racc/static.rb:3:in `<top (required)>' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/bin/racc:11:in `require' from /Users/koic/.rbenv/versions/3.2.0-dev/lib/ruby/gems/3.2.0+3/gems/racc-1.6.0/bin/racc:11:in `<top (required)>' from /Users/koic/.rbenv/versions/3.2.0-dev/bin/racc:25:in `load' from /Users/koic/.rbenv/versions/3.2.0-dev/bin/racc:25:in `<main>' rake aborted! Command failed with status (1): [racc --superclass=Parser::Base lib/parser/...] /Users/koic/src/github.com/whitequark/parser/Rakefile:166:in `block in <top (required)>' /Users/koic/.rbenv/versions/3.2.0-dev/bin/bundle:25:in `load' /Users/koic/.rbenv/versions/3.2.0-dev/bin/bundle:25:in `<main>' Tasks: TOP => default => test => generate => lib/parser/ruby32.rb (See full trace by running task with --trace) ``` -- https://bugs.ruby-lang.org/
2 1
0 0
[ruby-core:111227] [Ruby master Bug#19012] BasicSocket#recv* methods return an empty packet instead of nil on closed connections
by byroot (Jean Boussier) 07 Dec '22

07 Dec '22
Issue #19012 has been updated by byroot (Jean Boussier). I was able to implement the desired behavior in https://github.com/ruby/ruby/pull/6407 ---------------------------------------- Bug #19012: BasicSocket#recv* methods return an empty packet instead of nil on closed connections https://bugs.ruby-lang.org/issues/19012#change-100516 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- `man recvmsg(2)` states: > Return Value > These calls return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown. But somehow the entire `receiv` family of methods in Ruby seem to interpret `0` as empty string instead of "EOF". ```ruby require 'socket' puts "=== pipes ===" r, w = IO.pipe r.read_nonblock(1, exception: false) # => :wait_readable w.close r.read_nonblock(1, exception: false) # => nil (EOF) puts "=== sockets ====" r, w = UNIXSocket.socketpair r.read_nonblock(1, exception: false) # => :wait_readable r.recvmsg_nonblock(1, exception: false) # => :wait_readable r.recv_nonblock(1, exception: false) # => :wait_readable w.close r.read_nonblock(1, exception: false) # => nil (EOF) r.recvmsg_nonblock(1, exception: false) # => ["", #<Addrinfo: empty-sockaddr SOCK_STREAM>, 128]] r.recvmsg # => ["", #<Addrinfo: empty-sockaddr SOCK_STREAM>, 0]] r.recv_nonblock(1, exception: false) # => "" ``` ### Expected behavior I would expect `recvmsg_nonblock`, `recvmsg`, `recv_nonblock` and `recv` to return `nil` when the connection is closed. -- https://bugs.ruby-lang.org/
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • ...
  • 407
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.