* process.c (rb_clock_gettime): Strip "s" from unit names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-08-22 13:04:06 +00:00
Родитель 3873e09cad
Коммит a641003f66
3 изменённых файлов: 18 добавлений и 14 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Thu Aug 22 22:01:04 2013 Tanaka Akira <akr@fsij.org>
* process.c (rb_clock_gettime): Strip "s" from unit names.
Thu Aug 22 20:14:59 2013 Tanaka Akira <akr@fsij.org>
* process.c (unsigned_clock_t): Defined.

Просмотреть файл

@ -6672,27 +6672,27 @@ make_clock_result(struct timespec *tsp, VALUE unit)
{
long factor;
if (unit == ID2SYM(rb_intern("nanoseconds"))) {
if (unit == ID2SYM(rb_intern("nanosecond"))) {
factor = 1000000000;
goto return_integer;
}
else if (unit == ID2SYM(rb_intern("microseconds"))) {
else if (unit == ID2SYM(rb_intern("microsecond"))) {
factor = 1000000;
goto return_integer;
}
else if (unit == ID2SYM(rb_intern("milliseconds"))) {
else if (unit == ID2SYM(rb_intern("millisecond"))) {
factor = 1000;
goto return_integer;
}
else if (unit == ID2SYM(rb_intern("float_microseconds"))) {
else if (unit == ID2SYM(rb_intern("float_microsecond"))) {
factor = 1000000;
goto return_float;
}
else if (unit == ID2SYM(rb_intern("float_milliseconds"))) {
else if (unit == ID2SYM(rb_intern("float_millisecond"))) {
factor = 1000;
goto return_float;
}
else if (NIL_P(unit) || unit == ID2SYM(rb_intern("float_seconds"))) {
else if (NIL_P(unit) || unit == ID2SYM(rb_intern("float_second"))) {
factor = 1;
goto return_float;
}
@ -6792,12 +6792,12 @@ make_clock_result(struct timespec *tsp, VALUE unit)
*
* +unit+ specifies a type of the return value.
*
* [:float_seconds] number of seconds as a float (default)
* [:float_milliseconds] number of milliseconds as a float
* [:float_microseconds] number of microseconds as a float
* [:milliseconds] number of milliseconds as an integer
* [:microseconds] number of microseconds as an integer
* [:nanoseconds] number of nanoseconds as an integer
* [:float_second] number of seconds as a float (default)
* [:float_millisecond] number of milliseconds as a float
* [:float_microsecond] number of microseconds as a float
* [:millisecond] number of milliseconds as an integer
* [:microsecond] number of microseconds as an integer
* [:nanosecond] number of nanoseconds as an integer
*
* The underlying function, clock_gettime(), returns a number of nanoseconds.
* Float object (IEEE 754 double) is not enough to represent

Просмотреть файл

@ -1661,9 +1661,9 @@ EOS
end if windows?
def test_clock_gettime
t1 = Process.clock_gettime(Process::CLOCK_REALTIME, :nanoseconds)
t1 = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
t2 = Time.now; t2 = t2.tv_sec * 1000000000 + t2.tv_nsec
t3 = Process.clock_gettime(Process::CLOCK_REALTIME, :nanoseconds)
t3 = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
assert_operator(t1, :<=, t2)
assert_operator(t2, :<=, t3)
assert_raise(Errno::EINVAL) { Process.clock_gettime(:foo) }