Skip to content
This repository was archived by the owner on Mar 26, 2023. It is now read-only.

IO.select not coercing arguments #379

Open
mmmries opened this issue Mar 20, 2015 · 2 comments
Open

IO.select not coercing arguments #379

mmmries opened this issue Mar 20, 2015 · 2 comments

Comments

@mmmries
Copy link
Contributor

mmmries commented Mar 20, 2015

in MRI the IO.select says that is accepts any IO objects, but it actually enforces that via ducktyping rather than checking the type directly. In other words IO.select in MRI calls to_io on its arguments rather than checking their type directly.

Here is a little test script that shows the behavior:

class IOWrapper
  def initialize(io)
    @io = io
  end

  def to_io
    @io
  end
end

read_pipe, write_pipe = IO.pipe

read_wrapper = IOWrapper.new(read_pipe)
write_wrapper = IOWrapper.new(write_pipe)

write_pipe.write "ohai\nohai"

read_readies, write_readies = IO.select [read_wrapper], [write_wrapper]

p read_readies.first == read_wrapper # => true
p write_readies.first == write_wrapper # => true

Under ruby-2.2.0 this script runs correctly and outputs:

true
true

Under maglev-head this script raises the following error:

ERROR 2719 , a ArgumentTypeError occurred (error 2719), element 0 of reads arg to IO#select is neither a File nor Socket, anIOWrapper (TypeError)
topaz 1> exit
@AllenOtis
Copy link
Contributor

Right now IO.select is probably relying on a Smalltalk select primitive
which requires that the IO objects have a fileId instance variable.

On Thu, Mar 19, 2015 at 8:55 PM, Michael [email protected] wrote:

in MRI the IO.select says that is accepts any IO objects, but it actually
enforces that via ducktyping rather than checking the type directly. In
other words IO.select in MRI calls to_io on its arguments rather than
checking their type directly.

Here is a little test script that shows the behavior:

class IOWrapper
def initialize(io)
@io = io
end

def to_io
@io
endend

read_pipe, write_pipe = IO.pipe

read_wrapper = IOWrapper.new(read_pipe)
write_wrapper = IOWrapper.new(write_pipe)

write_pipe.write "ohai\nohai"

read_readies, write_readies = IO.select [read_wrapper], [write_wrapper]

p read_readies.first == read_wrapper # => true
p write_readies.first == write_wrapper # => true

Under ruby-2.2.0 this script runs correctly and outputs:

true
true

Under maglev-head this script raises the following error:

ERROR 2719 , a ArgumentTypeError occurred (error 2719), element 0 of reads arg to IO#select is neither a File nor Socket, anIOWrapper (TypeError)
topaz 1> exit


Reply to this email directly or view it on GitHub
#379.

@timfel
Copy link
Member

timfel commented Mar 21, 2015

IIRC, Kernel#select is in pure Ruby and delegates to a Smalltalk method after treating arguments. It should be easy to call to_io there.

----- Ursprüngliche Nachricht -----
Von: "Allen Otis" [email protected]
Gesendet: ‎20.‎03.‎2015 17:25
An: "MagLev/maglev" [email protected]
Betreff: Re: [maglev] IO.select not coercing arguments (#379)

Right now IO.select is probably relying on a Smalltalk select primitive
which requires that the IO objects have a fileId instance variable.

On Thu, Mar 19, 2015 at 8:55 PM, Michael [email protected] wrote:

in MRI the IO.select says that is accepts any IO objects, but it actually
enforces that via ducktyping rather than checking the type directly. In
other words IO.select in MRI calls to_io on its arguments rather than
checking their type directly.

Here is a little test script that shows the behavior:

class IOWrapper
def initialize(io)
@io = io
end

def to_io
@io
endend

read_pipe, write_pipe = IO.pipe

read_wrapper = IOWrapper.new(read_pipe)
write_wrapper = IOWrapper.new(write_pipe)

write_pipe.write "ohai\nohai"

read_readies, write_readies = IO.select [read_wrapper], [write_wrapper]

p read_readies.first == read_wrapper # => true
p write_readies.first == write_wrapper # => true

Under ruby-2.2.0 this script runs correctly and outputs:

true
true

Under maglev-head this script raises the following error:

ERROR 2719 , a ArgumentTypeError occurred (error 2719), element 0 of reads arg to IO#select is neither a File nor Socket, anIOWrapper (TypeError)
topaz 1> exit


Reply to this email directly or view it on GitHub
#379.


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants