Skip to content

Commit 66547f4

Browse files
committed
Fix rb_time_nano_new - don't call Time.at directly
1 parent 82f5ec3 commit 66547f4

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Bug fixes:
2323
* Fix `\P{}` matching in regular expressions (#2798, @andrykonchin).
2424
* Fix constants lookup when `BasicObject#instance_eval` method is called with a String (#2810, @andrykonchin).
2525
* Don't trigger the `method_added` event when changing a method's visibility or calling `module_function` (@paracycle, @nirvdrum).
26+
* Fix `rb_time_timespec_new` function to not call `Time.at` method directly (@andrykonchin).
2627

2728
Compatibility:
2829

lib/truffle/truffle/cext.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ module Truffle::CExt
112112
LIBTRUFFLERUBY = libtruffleruby
113113
end
114114

115+
ORIGINAL_TIME_AT = Time.method(:at)
116+
115117
def self.register_libtruffleruby(libtruffleruby)
116118
SET_LIBTRUFFLERUBY.call(libtruffleruby)
117119
end
@@ -1673,21 +1675,21 @@ def warning?
16731675
end
16741676

16751677
def rb_time_nano_new(sec, nsec)
1676-
Time.at sec, nsec, :nanosecond
1678+
ORIGINAL_TIME_AT.call(sec, nsec, :nanosecond)
16771679
end
16781680

16791681
def rb_time_timespec_new(sec, nsec, offset, is_utc, is_local)
16801682
if is_local
1681-
Time.at(sec, nsec, :nanosecond)
1683+
ORIGINAL_TIME_AT.call(sec, nsec, :nanosecond)
16821684
elsif is_utc
1683-
Time.at(sec, nsec, :nanosecond, in: 0).getgm
1685+
ORIGINAL_TIME_AT.call(sec, nsec, :nanosecond, in: 0).getgm
16841686
else
1685-
Time.at(sec, nsec, :nanosecond, in: offset)
1687+
ORIGINAL_TIME_AT.call(sec, nsec, :nanosecond, in: offset)
16861688
end
16871689
end
16881690

16891691
def rb_time_num_new(timev, off)
1690-
Time.at(timev).getlocal(off)
1692+
ORIGINAL_TIME_AT.call(timev).getlocal(off)
16911693
end
16921694

16931695
def rb_time_interval_acceptable(time_val)

spec/ruby/optional/capi/time_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@
283283
-> { @s.rb_time_timespec_new(1447087832, 476451125, 86400) }.should raise_error(ArgumentError)
284284
-> { @s.rb_time_timespec_new(1447087832, 476451125, -86400) }.should raise_error(ArgumentError)
285285
end
286+
287+
it "doesn't call Time.at directly" do
288+
Time.should_not_receive(:at)
289+
@s.rb_time_timespec_new(1447087832, 476451125, 32400).should be_kind_of(Time)
290+
end
286291
end
287292

288293
describe "rb_timespec_now" do

0 commit comments

Comments
 (0)