Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Cleanup Kernel.select #346

Merged
merged 3 commits into from

2 participants

@johnnyt
Owner

Closes #345. This also consolidates the code from IO#select into Kernel.select.

@MagLev - what do you guys think?

@timfel
Owner

Shouldnt IO already respond to select because it includes Kernel? If so, maybe the argument error should print the correct class this was called on? What error(s) does MRI raise? Is there a Rubyspec? Just thinking that if we touch the code, we might fix a spec or two

@timfel
Owner

Since this still passes, I'll just merge it.

@timfel timfel merged commit 0abcc19 into from
@johnnyt johnnyt deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 6, 2014
  1. @johnnyt
  2. @johnnyt

    Allow nil timeouts

    johnnyt authored
  3. @johnnyt

    Test for #345

    johnnyt authored
This page is out of date. Refresh to see the latest.
View
16 src/kernel/bootstrap/IO.rb
@@ -650,20 +650,8 @@ def sysseek(offset, whence = SEEK_SET)
self.pos
end
- def self.select( reads, writes=nil, errs=nil, timeout=nil )
- if timeout._isFixnum
- ms = timeout * 1000
- unless ms._isFixnum && ms >= 0
- raise ArgumentError , "IO#select, timeout not representable as Fixnum milliseconds >=0"
- end
- elsif timeout._not_equal?(nil)
- timeout = Maglev::Type.coerce_to(timeout, Float, :to_f)
- ms = (timeout * 1000.0 ).to_int
- unless ms._isFixnum && ms >= 0
- raise ArgumentError , "IO#select, timeout not representable as Fixnum milliseconds >=0"
- end
- end
- Kernel.__select(reads, writes, errs, *[ ms ]).map{|arr| Array(arr)}
+ def self.select(reads, writes=nil, errs=nil, timeout=nil)
+ Kernel.select(reads, writes, errs, timeout)
end
primitive 'stat', 'stat'
View
25 src/kernel/bootstrap/Kernel.rb
@@ -863,19 +863,22 @@ def scan(pattern, &block)
primitive_nobridge '__select*', 'selectRead:write:error:timeout:'
def select(reads, writes=nil, errs=nil, timeout=nil)
- if timeout._isFixnum
- ms = timeout * 1000
- unless ms._isFixnum && ms >= 0
- raise ArgumentError , "IO#select, timeout not representable as Fixnum milliseconds >=0"
- end
- elsif timeout._not_equal?(nil)
+ ms = if timeout._equal?(nil)
+ nil
+ elsif timeout._isFixnum
+ timeout * 1000
+ else
timeout = Maglev::Type.coerce_to(timeout, Float, :to_f)
- ms = (timeout * 1000.0 ).to_int
- unless ms._isFixnum && ms >= 0
- raise ArgumentError , "IO#select, timeout not representable as Fixnum milliseconds >=0"
- end
+ (timeout * 1000.0 ).to_int
end
- Kernel.__select(reads, writes, errs, *[ ms ]).map{|arr| Array(arr)}
+
+ if ms._isFixnum && ms < 0
+ raise ArgumentError, 'Kernel.select, timeout not representable as Fixnum milliseconds >=0'
+ end
+
+ arrays = __select(reads, writes, errs, *[ ms ])
+ return arrays if arrays._equal?(nil)
+ arrays.map{|arr| Array(arr)}
end
# Preferred alternative to class << self ; self ; end .
View
3  src/test/github345.rb
@@ -0,0 +1,3 @@
+arrays = select nil, nil, nil, 0.01
+
+raise "#select should return nil when no selectors are provided" if arrays._not_equal?(nil)
Something went wrong with that request. Please try again.