Граф коммитов

591 Коммитов

Автор SHA1 Сообщение Дата
nobu 934e3e0e12 time.c: [DOC] about timezone arguemnt [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28 04:00:26 +00:00
nobu 4c875b6e66 time.c: benchmark recovery
* time.c (time_localtime): check if `vtm.zone` is a simple zone
  name string before trying to call the conversion method.  since
  r64952, `Time.getlocal` on UTC time has lost the performance
  about 45%, due to this call.  the performance is about 90% of
  r64951 by avoiding it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-25 00:36:23 +00:00
nobu fc3b500fb1 Let Time::TM share the implementation with Time
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-23 12:43:07 +00:00
nobu 6fdbf5a804 No longer subsec and isdst members
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22 14:02:59 +00:00
nobu 0bed6345ce Revert TM_IS_TIME to 1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22 13:56:41 +00:00
nobu 385b772149 Return fixed values at subsec, utc_offset, and isdst
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22 13:53:20 +00:00
nobu 8747974d4b time.c: optional arguments of Time::TM#initialize
* time.c (tm_initialize): arguments other than year are optional
  now as Time.new.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22 01:25:29 +00:00
nobu fa8b08b424 Prefer `rb_fstring_lit` over `rb_fstring_cstr`
The former states explicitly that the argument must be a literal,
and can optimize away `strlen` on all compilers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13 09:59:22 +00:00
nobu 1821e9f4dc Fix overwritten zone string
* time.c (zone_str): while rb_fstring_usascii and the family
  require that the argument string is never modified, tzname may
  point areas which will be discarded by calling tzset().
  make a String then call rb_fstring to copy the zone name.
  when an ID equals TZ environment variable, its name string also
  has modified by changing tzname.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12 15:48:06 +00:00
nobu ade73091cb Initialize zone
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12 02:49:39 +00:00
nobu 75ac8e866b Load as FIXOFF mode if zone is present
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12 02:25:38 +00:00
nobu 093398f979 Just copy tzmode
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12 02:25:37 +00:00
nobu fcf308e5fc Timezone at Time#+ and Time#-
* time.c (time_add): support for Timezone.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-08 04:03:32 +00:00
svn b8fbe8b59f * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-08 02:35:33 +00:00
nobu ee58c638b8 Timezone support by Time [Feature #14850]
* strftime.c (rb_strftime): support timezone object by `%z`.

* time.c (time_init_1, time_new_timew, time_getlocaltime): accept
  timezone object as `off`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-08 02:35:31 +00:00
nobu 0e3e0f8249 Fix messages for too small year
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-27 10:22:08 +00:00
nobu 351b8a322e time.c split time_utc_or_local
* time.c (time_utc_or_local): split into time_s_mkutc and
  time_s_mktime without utc flag.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 14:37:51 +00:00
akr efb002cd7a rename an argument of calc_wday.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-21 14:40:18 +00:00
akr 3d3ff9f324 gmtimew_noleapsecond uses tables for mon and mday.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-15 14:24:44 +00:00
akr 8507904385 timegm_noleapsecond uses calc_tm_yday.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-12 16:45:02 +00:00
akr 4078be54ad rename several internal macros in time.c
TIME_UTC_P -> TZMODE_UTC_P
TIME_SET_UTC -> TZMODE_SET_UTC
TIME_LOCALTIME_P -> TZMODE_LOCALTIME_P
TIME_SET_LOCALTIME -> TZMODE_SET_LOCALTIME
TIME_FIXOFF_P -> TZMODE_FIXOFF_P
TIME_SET_FIXOFF -> TZMODE_SET_FIXOFF
TIME_COPY_GMT -> TZMODE_COPY



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08 12:48:58 +00:00
kazu 0f904ff1fc Update comment of tzmode [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08 11:50:39 +00:00
akr b81a33263a Rename gmt field to tzmode in struct time_object.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08 10:39:31 +00:00
akr 277cedb84c Store String as zone in struct vtm.
This removes zone_table and use fstring instead.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08 10:00:43 +00:00
nobu 5ad205b81d renamed ruby_tz_update as ruby_tz_uptodate_p
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-19 11:22:03 +00:00
nobu 4bc1669127 reduce tzset
* time.c (rb_localtime_r): call tzset() only after TZ environment
  variable is changed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-18 10:30:41 +00:00
nobu 33354d2928 Prefixed reset_leap_second_info
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-06 01:40:04 +00:00
naruse 6538f67d4d Re-apply r63848 (Optimize Time.utc)
* Both timegmw and gmtimew ignores leap second if the timezone doesn't
  have leap seconds on the first call of init_leap_second_info()
* Add Bug::Time.reset_leap_second_info for testing

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-05 11:43:42 +00:00
naruse bd9a78a0fe Revert "Optimize Time.utc"
This reverts commit r63848.
It breaks tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04 10:59:36 +00:00
naruse dda048381f Optimize Time.utc
Time.utc uses timegmw() and it uses leap second information.
If the given time is larger than known_leap_seconds_limit, it calls
find_time_t, which uses localtime(3) and calls stat(2) in it.

This patch avoid it by setting known_leap_seconds_limit to 0 if the timezone doesn't have leapsecond information (if no leap second is found "now", I assume the timezone doesn't have leapsecond information).

Before:
% time ./miniruby --disable-gem -e'time = Time.now; year = time.year; month = time.month; day = time.day; hour = time.hour; min = time.min; sec = time.sec + time.subsec; i = 0; while i < 100000; ::Time.utc(year, month, day, hour, min, sec); i += 1; end'
./miniruby --disable-gem   0.35s user 0.19s system 99% cpu 0.542 total

After:
% time ./miniruby --disable-gem -e'time = Time.now; year = time.year; month = time.month; day = time.day; hour = time.hour; min = time.min; sec = time.sec + time.subsec; i = 0; while i < 100000; ::Time.utc(year, month, day, hour, min, sec); i += 1; end'
./miniruby --disable-gem   0.23s user 0.00s system 99% cpu 0.233 total

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04 10:06:51 +00:00
nobu 482bbde6e2 time.c: [DOC] Time#localtime
* time.c: state that Time#localtime does nothing when nothing
  changes.  [ruby-core:87675] [Bug #14880]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-02 07:46:38 +00:00
normal 218b8324bb time.c (num_exact): use predefined IDs
No need to waste space on "to_r" and "to_int" which are
predefined in defs/id.def

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-22 03:04:26 +00:00
normal 8a6c76b510 time.c: constify compat_* tables
compat_common_month_table and compat_leap_month_table should
not be writable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-22 00:40:11 +00:00
normal 377b189562 time.c: use "unsigned int" for bitfields
Followup to r61870

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17 05:03:43 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
shyouhei db5d556f9b bit-fields other than int is a C99ism
To be precise C90 says "A bit-field may have type int, unsigned
int, or signed int". It is clear that char or enum are NG.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:50 +00:00
naruse 189ecfd2eb extern rb_time_utc_offset to get utc offset
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-11 12:09:47 +00:00
naruse 97c5a33f7e Time#at receives 3rd argument which specifies the unit of 2nd argument [Feature #13919]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-25 06:20:10 +00:00
eregon 3efe410dd0 time.c (Time#-): Fix documentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 14:54:29 +00:00
nobu 202fbe3046 time.c: preserve marshalled timezone
* time.c (time_add): preserve timezone name restored by Marshal.
  [ruby-core:81892] [Bug #13710]

* time.c (time_mload): reset localtime if having timezone.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-04 04:23:06 +00:00
watson1978 6fcb76ed80 Improve performance of some Time methods
internal.h : add rb_numeric_quo() as internal API.
rational.c : rename numeric_quo() to rb_numeric_quo() as internal API.
time.c (quov): optimize by invoking rb_numeric_quo() to retrieve a value of
    Numeric#quo instead of method dispatching via rb_funcall().

    Time#subsec ->  7 % up
    Time#-      -> 26 % up
    Time#to_f   -> 30 % up
    Time#to_r   ->  7 % up

    [ruby-core:80915] [Bug #13519] [Fix GH-1601]

### Before
         Time#subsec      2.024M (± 8.7%) i/s -     10.062M in   5.009762s
              Time#-      5.049M (± 4.7%) i/s -     25.186M in   5.002379s
           Time#to_f      5.625M (± 4.2%) i/s -     28.066M in   5.000749s
           Time#to_r      1.880M (± 9.7%) i/s -      9.361M in   5.027527s

### After
         Time#subsec      2.155M (± 9.7%) i/s -     10.724M in   5.022579s
              Time#-      6.362M (± 2.0%) i/s -     31.824M in   5.004625s
           Time#to_f      7.287M (± 4.8%) i/s -     36.402M in   5.010983s
           Time#to_r      2.020M (± 9.4%) i/s -     10.059M in   5.021852s

### Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "Time#subsec" do |t|
    time = Time.now
    t.times { time.subsec }
  end

  x.report "Time#-" do |t|
    time1 = Time.now
    time2 = Time.now
    t.times { time1 - time2 }
  end

  x.report "Time#to_f" do |t|
    time = Time.now
    t.times { time.to_f }
  end

  x.report "Time#to_r" do |t|
    time = Time.now
    t.times { time.to_r }
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-27 05:41:00 +00:00
watson1978 c208d15ff7 Improve Time#+ & Time#- performance
* time.c (wadd): use internal addv() function to calculate internal value in
    Time object. On 64-bit machine, Time object might have Fixnum object
    internally by default and addv() can calculate Fixnum objects directly.

* time.c (wsub): use internal subv() function due the same reason in above.

    Time#+ & Time#- will be faster around 15%.

    [ruby-dev:50036] [Bug #13357] [Fix GH-1547]

### Before
             user     system      total        real
Time#+   0.820000   0.000000   0.820000 (  0.818081)
Time#-   0.810000   0.000000   0.810000 (  0.813835)

### After
             user     system      total        real
Time#+   0.710000   0.000000   0.710000 (  0.710241)
Time#-   0.710000   0.010000   0.720000 (  0.714151)

### Test code
require 'benchmark'

Benchmark.bmbm do |x|

  x.report "Time#+" do
    t = Time.now
    2000000.times do
      t + 1
    end
  end

  x.report "Time#-" do
    t = Time.now
    2000000.times do
      t - 1
    end
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-21 03:36:31 +00:00
watson1978 92ea637c62 Improve Time#<=> performance
* time.c (wcmp): use internal cmp() function for comparing internal Fixnum value
    in Time objects. On 64-bit machine, Time object might have Fixnum object
    internally by default and cmp() can compare the Fixnum objects directly.

    Time#<=> will be faster around 60% on 64-bit machine.

* time.c (cmp): add optimized path for comparing internal Bignum value by using
    rb_big_cmp() API. On 32-bit machine, Time object might have Bignum object
    internally by default.

    Time#<=> will be faster around 50% on 32-bit machine.

    [ruby-dev:50034] [Bug #13354] [Fix GH-1546]

### Before
             user     system      total        real
Fixnum   1.410000   0.000000   1.410000 (  1.407848)
Bignum   1.550000   0.000000   1.550000 (  1.549145)

### After
             user     system      total        real
Fixnum   0.880000   0.000000   0.880000 (  0.886662)
Bignum   1.050000   0.000000   1.050000 (  1.047994)

### Test code
require 'benchmark'

Benchmark.bmbm do |x|

  x.report "Fixnum" do
    t1 = Time.now
    t2 = Time.now
    10000000.times do
      t1 <=> t2
    end
  end

  x.report "Bignum" do
    t1 = Time.at(2 ** 64)
    t2 = Time.at(2 ** 64 + 1)
    10000000.times do
      t1 <=> t2
    end
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-21 03:36:30 +00:00
mame fd6dd50f95 time.c: avoid taking a pointer to a member of packed struct
clang 4.0.0 emitted a warning: "taking address of packed member
'subsecx' of class or structure 'vtm' may result in an unaligned
pointer value [-Waddress-of-packed-member]".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-04 13:42:47 +00:00
nobu 2cb399af44 time.c: rename div as divv
* time.c (divv): add suffix to get rid of the name in C standard
  library, and others together.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-11 02:40:14 +00:00
normal c68ec6f147 time.c: use predefined IDs
This reduces rb_intern calls during startup and shortens code.

* time.c: include id.h for predefined IDs
  (id_mul, id_eq, id_ne, id_cmp): remove static variables
  (eq): replace id_eq with idEq
  (cmp, wcmp): replace id_cmp with idCmp
  (weq): replace id_eq with idEq
  (time_timespec): replace id_mul with '*'
  (Init_Time): remove rb_intern calls for removed variables
* common.mk (time.$(OBJEXT)): add depend on id.h

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-10 18:16:58 +00:00
normal 5d3fac0db9 time.c: Improve Time#to_i performance
Time#to_i will be faster around 80% (on 64-bit platforms).

* Before
       user     system      total        real
   2.840000   0.000000   2.840000 (  2.847238)

* After
       user     system      total        real
   1.600000   0.000000   1.600000 (  1.598911)

* Test code
require 'benchmark'

Benchmark.bmbm do |x|
  x.report do
    t = Time.now
    20000000.times do
      t.to_i
    end
  end
end

* time.c (_div): new function avoid rb_funcall
  (div): replace with new _div function
  [ruby-core:80636] [Bug #13418]
  Thanks to Watson <watson1978@gmail.com> for the patch.

From: Watson <watson1978@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-10 18:08:16 +00:00
normal 9b69e9fafc time.c (time_strftime): avoid garbage in common case
strftime format strings which are dynamically-generated will benefit
from avoiding garbage, here.

* time.c (time_strftime): use rb_str_tmp_frozen_{acquire,release}
* test/ruby/test_time.rb (test_strftime_no_hidden_garbage): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-31 02:18:58 +00:00
nobu 44a4d7b057 time.c: fix type of usec2subsecx
* time.c (usec2subsecx): fix return type, which is a numeric
  object but not a long int.  [ruby-dev:49912] [Bug #13066]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-24 12:21:52 +00:00
nobu 4e41d5dedd time.c: remove debug code
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-24 12:19:23 +00:00
nobu 65a884ebad time.c: fix typo in value_insane_p
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-24 11:56:12 +00:00
nobu 11e386cf6c time.c: inquire suspicious values
* time.c (time_arg): dump sec and subsec arguments if subsecx is
  insane.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-23 00:05:40 +00:00
nobu bd2e1034d5 time.c: inquire suspicious values
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-22 22:34:18 +00:00
nobu edaf4500f8 time.c: debug print
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 13:46:46 +00:00
nobu 5518b5c21a time.c: refine num_exact error message
* time.c (num_exact): show the original argument when conversion
  failed, instead of intermediate nil.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 12:06:40 +00:00
nobu 33e8eef020 time.c: use RB_TYPE_P
* time.c (time_timespec): use RB_TYPE_P instead of switching by
  TYPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 12:05:41 +00:00
nobu 5064e9201a time.c: refine error message
* time.c (validate_vtm): separate validation failure messages for
  each members.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-19 08:36:21 +00:00
akr a03411b63e fix vtm_add_offset yday on last day of year.
* time.c (vtm_add_offset): Fix yday on last day of year.
  [ruby-core:72878] [Bug #11994] Fixed by Andrew White.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 14:59:51 +00:00
usa 774442d27f * time.c (time_arg): guard for mswin64 CI.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-12 15:16:09 +00:00
akr 577de1e93d replace fixnum by integer in documents.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 04:57:49 +00:00
usa a260f093be * time.c (obj2subsecx): subsec might be GC'ed. try to get rid of SEGV on mswin
CI.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-06 01:21:54 +00:00
usa 8b9f9274c6 * time.c (time_arg): revert r55688 beause it had no effect. retry...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-15 21:39:57 +00:00
usa 363c90853e * time.c (time_arg): it seems that this function sometimes causes SEGV
on mswin CI, then force to prevent `vtm->subsecx` from GC.  this is
  experimental.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-15 06:35:37 +00:00
naruse 173005bb6f * time.c: define _DEFAULT_SOURCE because glibc 2.20 depracates
_BSD_SOURCE.
  https://sourceware.org/glibc/wiki/Release/2.20

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54802 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 16:15:21 +00:00
nobu 5fd589287d time.c: add example [ci skip]
* time.c (time_asctime): [DOC] add ctime example, not only
  asctime.  [ruby-core:75126] [Bug #12310]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-22 11:34:05 +00:00
nobu 5396d8a1ab strftime.c: format in String
* strftime.c (rb_strftime_with_timespec): append formatted results
  to the given string with expanding, and also deal with NUL chars.
* strftime.c (rb_strftime, rb_strftime_timespec): return formatted
  string, not the length put in the given buffer.
* time.c (rb_strftime_alloc): no longer needs to retry with
  reallocating buffers.
* time.c (time_strftime): no longer needs to split by NUL chars.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-23 11:57:01 +00:00
usa 15af93fcc8 * time.c (wmul): wrong condition.
fixed many test failures on 32bit and LLP64 platforms.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-22 02:41:24 +00:00
usa 6957898ad0 * time.c (wdiv, wmod): wdivmod0() assumes the 3rd and the 4th arguments
are valid pointers.
  maybe checking them in wdivmod0() is better manner, but I guess that
  passing real dummy pointers may be faster than checking and branching
  in wdivmod0().
  this commit fixes SEGV on 32bit and LLP64 platforms.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-22 01:37:01 +00:00
usa 0dbbcdb6bb * time.c (divmodv): void function never returns any value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-22 01:24:55 +00:00
naruse 520650798c fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 19:14:27 +00:00
naruse 03d0501f51 * time.c (MUL_OVERFLOW_FIXWV_P): defined for FIXWV.
* time.c (wmul): use MUL_OVERFLOW_FIXWV_P and only switch.

* time.c (wmul): use mul which has Fixnum optimization.

* time.c (rb_time_magnify): If WIDEVALUE_IS_WIDER, wmul() has the same
  optimized logic, else mul() has also the similar logic for Fixnum.

* time.c (rb_time_unmagnify): almost ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 18:57:30 +00:00
naruse 74d7b281d3 fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 18:57:25 +00:00
naruse 849bbc6566 * time.c (divmodv): add the case both arguments are Fixnum.
* time.c (wquo): use quo which has Fixnum optimization.

* time.c (wdivmod0): added for WIDEVALUE_IS_WIDER.

* time.c (wdivmod): use wdivmod0 and divmodv.
  divmodv has Fixnum optimization.

* time.c (wdiv): use wdivmod0 and div to avoid the use of divmodv which
  calls id_quo whose return value is array.

* time.c (wmod): use wdivmod0 and mod to avoid the use of divmodv which
  calls id_quo whose return value is array.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 18:19:15 +00:00
naruse 51c4ffa45b * internal.h (rb_fix_divmod_fix): like r54213, use FIX2NUM only if
x == FIXNUM_MIN && y == -1. This must be a rare case and it is
  expected compiler to handle well.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:36:03 +00:00
nobu 2118eccc77 time.c (quo): fix missing return
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:31:30 +00:00
naruse 654788793d fix commit miss
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:21:12 +00:00
naruse f5715289ac * time.c (mod): Add Fixnum case.
* time.c (quo): c can be Fixnum except a == FIXNUM_MIN && b == -1.
  Such case can be optimized out because quo()'s argument is constant.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:17:45 +00:00
nobu ce5ba9197d time.c (mul): fix missing return.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 11:26:17 +00:00
naruse 148f1b9d57 * internal.h (DLONG): defined if long is 32bit (and LONG_LONG is 64bit;
but LONG_LONG is always defined as 64bit), or there's int128_t.

* internal.h (DL2NUM): defined if DLONG is defined.

* internal.h (rb_fix_mul_fix): defined for `Fixnum * Fixnum`.

* insns.def (opt_mul): use rb_fix_mul_fix().

* numeric.c (fix_mul): ditto.

* time.c (mul): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 11:10:43 +00:00
naruse cb390bef8a * time.c (add): remove FIXABLE() which is in LONG2NUM().
* time.c (sub): ditto.

* time.c (mul): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 09:47:20 +00:00
naruse 4eb908d21a * time.c (LOCALTIME): organize #ifdefs.
* time.c (GMTIME): define only ifndef HAVE_STRUCT_TM_TM_GMTOFF.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 19:06:33 +00:00
naruse 9a8b21446e * configure.in (rb_cv_member_struct_tm_tm_gmtoff): For Linux (glibc)
define _BSD_SOURCE for time.h to define struct tm.tm_gmtoff.

* time.c: define _BSD_SOURCE at the top.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 19:06:32 +00:00
hsbt 8709f42ff2 * time.c: Minor typo in Time#dst? documentation.
[ci skip][fix GH-1290]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-15 00:56:45 +00:00
naruse 911b1c6b06 * time.c (rb_time_timespec_new): swap utc and localtime
to generate gmt flag by INT_MAX - gmtoff.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-10 05:36:47 +00:00
naruse f1df08e76d * time.c (rb_timespec_now): added.
* time.c (rb_time_timespec_new): added.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-10 02:59:47 +00:00
naruse 2b15d16987 fix comment: tobj->gmt is 0:localtime 1:utc 2:fixoff 3:init
see also TIME_UTC_P and TIME_LOCALTIME_P

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-09 17:18:35 +00:00
nobu 4191a6b90d preserve encodings in error messages
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-28 02:40:46 +00:00
akr 3093ffab83 * time.c (time_getlocaltime): [DOC] Add examples of valid utc_offset
formats.
  [ruby-core:68306] [Misc #10905] Patch by Charles Korn.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-14 11:10:49 +00:00
normal f6cd582505 variable.c: avoid compatibility table with generic ivars
This recovers and improves performance of Marshal.dump/load on
Time objects compared to when we implemented generic ivars
entirely using st_table.

This also recovers some performance on other generic ivar objects,
but does not bring bring Marshal.dump/load performance up to
previous speeds.

benchmark results:
minimum results in each 10 measurements.
Execution time (sec)
		name    trunk   geniv   after
marshal_dump_flo        0.343   0.334   0.335
marshal_dump_load_geniv 0.487   0.527   0.495
marshal_dump_load_time  1.262   1.401   1.257

Speedup ratio: compare with the result of `trunk' (greater is better)
		name    geniv   after
marshal_dump_flo        1.026   1.023
marshal_dump_load_geniv 0.925   0.985
marshal_dump_load_time  0.901   1.004

* include/ruby/intern.h (rb_generic_ivar_table): deprecate
* internal.h (rb_attr_delete): declare
* marshal.c (has_ivars): use rb_ivar_foreach
  (w_ivar): ditto
  (w_object): update for new interface
* time.c (time_mload): use rb_attr_delete
* variable.c (generic_ivar_delete): implement
  (rb_ivar_delete): ditto
  (rb_attr_delete): ditto
  [ruby-core:69323] [Feature #11170]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30 00:20:15 +00:00
naruse 1e4172467f * win32/Makefile.sub: MSVC14 have struct timespec.
* win32/rtname.cmd: support vcruntime140.dll.

* time.c (localtime_with_gmtoff_zone): MSVC14 doesn't have tzname and
  daylight but have _tzname and _daylight.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-23 19:51:18 +00:00
nobu 004ce53b25 time.c: locale time zone name
* time.c (time_zone_name): should be US-ASCII only if all 7-bits,
  otherwise locale encoding.  [ruby-core:68230] [Bug #10887]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-24 02:49:51 +00:00
naruse 5b4afd0281 zone may be ASCII-8BIT on Windows [Bug #10887]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-23 09:32:27 +00:00
eregon 9759173cfc * time.c: zone encoding should be US-ASCII if all 7-bits. Fix r46907.
* test/ruby/test_time.rb, test/ruby/test_time_tz.rb: Update tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-22 22:26:55 +00:00
akr 9bbe6b9d0c * time.c (timelocalw): Set tm_isdst field -1 if vtm->isdst is
VTM_ISDST_INITVAL.  This bug is introduced at packing struct
  vtm (r45155).
  [ruby-core:67345] [Bug #10698] Reported by Boris Ruf.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-06 12:41:20 +00:00
nobu e580a631be use 0 for reserved
use 0 for rb_data_type_t::reserved instead of NULL, since its type
may be changed in the future and possibly not a pointer type.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01 06:38:04 +00:00
nobu 1e4292a9d0 time.c: indent
* time.c (find_time_t): adjust indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48604 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-27 08:08:32 +00:00
akr 15bfc6ffbf * time.c (time_s_mkutc): [DOC] Time.utc's 10 arguments form
doesn't examine wday, yday, isdst and tz.
  (time_s_mktime): [DOC] Time.mktime's 10 arguments form
  doesn't examine wday, yday and tz.
  Suggested by naruse.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-27 03:48:42 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
akr 6c41b73dec update doc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-04 14:20:56 +00:00
akr 1efb3c31b7 * Avoid undefined behaviors found by gcc -fsanitize=undefined.
gcc (Debian 4.9.1-16) 4.9.1

* include/ruby/ruby.h (INT2FIX): Avoid undefined behavior.

* node.h (nd_set_line): Ditto.

* pack.c (encodes): Ditto.
  (pack_unpack): Ditto.

* regint.h (BIT_STATUS_AT): Ditto.
  (BS_BIT): Ditto.

* time.c (time_mdump): Ditto.
  (time_mload): Ditto.

* vm_core.h (VM_FRAME_MAGIC_MASK): Ditto.

* vm_trace.c (recalc_add_ruby_vm_event_flags): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-17 08:50:01 +00:00
glass 5697b2f013 * time.c: raise exception when minutes of utc_offset is out of 00-59.
patch is from Kenichi Kamiya.
  [ruby-dev:47539] [Bug #8679]

* test/ruby/test_time.rb: test for above.
  patch is from Kenichi Kamiya.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-21 16:58:47 +00:00
normal 6c396e94f9 time.c: DATA_PTR is never NULL
* time.c (time_mark): remove NULL check
  (time_memsize): ditto
  (time_free): remove, use RUBY_TYPED_DEFAULT_FREE instead
  [Feature #10219]

Tiny improvement on my old Phenom II X4 945 system:
$ ruby --disable=gems -e '6000000.times { Time.now }'
before: 2.51user 0.00system 0:02.51elapsed 100%CPU
 after: 2.45user 0.00system 0:02.45elapsed 100%CPU

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 06:01:36 +00:00
akr 092c647cb7 * time.c (rb_time_unmagnify_to_float): Avoid double rounding.
Reported by Tsuyoshi Sawada.
  https://bugs.ruby-lang.org/issues/10135#note-1



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-26 11:48:21 +00:00
normal ed2e8b2e70 time.c (time_timespec): fix tv_nsec overflow
test/ruby/test_float.rb (test_sleep_with_Float) causes tv_nsec
to hit 1000000000 exactly.  This bug is currently hidden from
our test by the platform-dependent native_cond_timeout
functions, but a future native_cond_timedwait implementation may
prefer relative timeouts to match ConditionVariable#wait
semantics more closely.
[Bug #10144]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-16 01:27:19 +00:00
akr 05e756f367 Revert r46977. [ruby-core:63857] [Bug #10071]
The removed comment is useful to understand the behind idea to
solve the year 2038 problem.

The broken link is replaced to refer the internet archive.
0eed69757d (commitcomment-7166665)



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-14 13:10:07 +00:00
zzak ea418dda41 * time.c: [DOC] Clarify %Y in strftime, which can accept any digits
and will output at least 4 digits as the year. Reported by Yury
  Trofimenko [Bug #8941]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-27 20:58:05 +00:00
zzak 0eed69757d * time.c: [DOC] Remove dead link and old bug report, which hasn't been
reproduced in a few years. Reported by Federico Builes [Bug #10071]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-27 20:14:11 +00:00
nobu 2e8ce8899a time.c: unnecessary encoding
* time.c (time_zone_name): remove unnecessary encoding and
  conversion if it is 7bit-ascii only.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-23 07:20:39 +00:00
akr dd5d029db0 * compile.c (BUFSIZE): Unused macro removed.
* vm.c (BUFSIZE): Ditto.

* pack.c (INT64toNUM): Ditto.
  (UINT64toNUM): Ditto.
  (BYTEWIDTH): Ditto.

* time.c (lshift): Ditto.
  (UINT64toNUM): Ditto.
  (id_lshift): Unused variable removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-11 13:29:16 +00:00
nobu 0989529f88 time.c: fix underflow of unsigned integers
* time.c (vtm_add_offset): get rid of underflow of unsigned
  integers.  fix up r45155.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-02 18:43:23 +00:00
nobu c23a9376ca time.c: fix non-terminated string
* time.c (month_arg, time_strftime): RSTRING_PTR() may not be
  NUL-terminated.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 15:09:49 +00:00
normal e0a0edf548 time.c: freeze and preserve marshal-loaded time zone
We need to prevent vtm.zone from pointing to a GC-ed string buffer.
The rb_copy_generic_ivar call misses it because get_attr deleted it.
Thanks to nobu for the rb_str_new_frozen suggestion.

* time.c (time_mload): freeze and preserve marshal-loaded time zone
* test/ruby/test_time.rb: add test for GC on loaded object
  [Bug #9652]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-19 08:19:13 +00:00
nobu fc23374f06 [DOC] add links to `Object#hash`
add links to `Object#hash` to each #`hash` methods rdocs.
[Fixes GH-567]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:43 +00:00
akr abb0286b72 [DOC]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-28 16:01:54 +00:00
nobu cc216f9aae adjust indent and style
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-27 07:10:14 +00:00
nobu df9199d468 configure.in, win32/Makefile.sub: PACKED_STRUCT with VC
* configure.in (PACKED_STRUCT): check VC pragma too, and make
  function-style macro.

* win32/Makefile.sub (PACKED_STRUCT): enable with VC.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-25 07:00:10 +00:00
normal 131e4bec04 time: only use packed struct on x86*
* configure.in: define PACKED_STRUCT_UNALIGNED for x86*
* timev.h (struct vtm): use PACKED_STRUCT_UNALIGNED
* time.c (struct time_object): ditto
  [Bug #9558] non-x86 cannot safely access unaligned addresses

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-24 11:10:11 +00:00
normal b2f3063cae time: rearrange+pack vtm and time_object structs
struct time_object shrinks from 88 to 46 bytes on my 64-bit system.

* configure.in: use -Wno-packed-bitfield-compat for GCC 4.4+
  use __attribute__((packed)) if available
* timev.h: shrink and pack struct vtm
* time.c: pack struct time_object and adjust/introduce helpers
  [ruby-core:60794]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-24 03:38:14 +00:00
akr caa3c88040 * time.c (v2w): Normalize a rational value to an integer if possible.
[ruby-core:58070] [Bug #9059] reported by Isaac Schwabacher.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-30 03:22:23 +00:00
ko1 c5e08b764e * add RUBY_TYPED_FREE_IMMEDIATELY to data types which only use
safe functions during garbage collection such as xfree().
  On default, T_DATA objects are freed at same points as fianlizers.
  This approach protects issues such as reported by [ruby-dev:35578].
  However, freeing T_DATA objects immediately helps heap usage.
  Most of T_DATA (in other words, most of dfree functions) are safe.
  However, we turned off RUBY_TYPED_FREE_IMMEDIATELY by default
  for safety.
* cont.c: ditto.
* dir.c: ditto.
* encoding.c: ditto.
* enumerator.c: ditto.
* error.c: ditto.
* file.c: ditto.
* gc.c: ditto.
* io.c: ditto.
* iseq.c: ditto.
* marshal.c: ditto.
* parse.y: ditto.
* proc.c: ditto.
* process.c: ditto.
* random.c: ditto.
* thread.c: ditto.
* time.c: ditto.
* transcode.c: ditto.
* variable.c: ditto.
* vm.c: ditto.
* vm_backtrace.c: ditto.
* vm_trace.c: ditto.
* ext/bigdecimal/bigdecimal.c: ditto.
* ext/objspace/objspace.c: ditto.
* ext/stringio/stringio.c: ditto.
* ext/strscan/strscan.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 11:16:54 +00:00
akr 888e5cbbe7 * process.c: Remove spaces between SI prefix and unit to follow
SI brochure.
  http://www.bipm.org/en/si/si_brochure/
  https://www.nmij.jp/library/units/si/

* time.c: Ditto.

* ext/socket/ancdata.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-09 12:33:36 +00:00
nobu 5685abe6c3 time.c: ignore invalid data
* time.c (time_mload): ignore invalid offset and zone.
  [ruby-core:56648] [Bug #8795]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-17 13:20:50 +00:00
ktsj f9cbf0e89f * time.c (get_timeval, get_new_timeval): use rb_obj_class()
instead of CLASS_OF() because CLASS_OF() may return
  a singleton class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-09 01:56:51 +00:00
akr fef170e87c * time.c (time_overflow_p): Avoid signed integer overflow.
(rb_time_new): Fix overflow condition.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-08 12:59:21 +00:00
akr 685597fdc1 Fix the previous commit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-08 12:34:30 +00:00
akr 319dc9f6c6 * time.c (time_overflow_p): Avoid signed integer overflow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-08 12:13:04 +00:00
zzak 0ea2ae132f * time.c: [DOC] Typo in Time overview by @sparr [Fixes GH-374]
https://github.com/ruby/ruby/pull/374


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-06 13:39:15 +00:00
akr a338c4ed5d Unused variable removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-11 16:37:37 +00:00
akr b23d9a8a63 * bignum.c (validate_integer_pack_format): Don't require a word order
flag if numwords is 1 or less.
  (absint_numwords_generic): Don't specify a word order for
  rb_integer_pack.

* hash.c (rb_hash): Ditto.

* time.c (v2w_bignum): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-11 14:40:16 +00:00
akr 0e8caa7d0f * bignum.c (rb_integer_pack): Returns sign instead of words.
(absint_numwords_generic): Follow the above change.
  (big2str_base_powerof2): Follow the above change.

* internal.h: Ditto.

* hash.c (rb_hash): Ditto.

* pack.c (pack_pack): Ditto.

* random.c (int_pair_to_real_inclusive): Ditto.
  (rand_init): Ditto.
  (random_load): Ditto.
  (limited_big_rand): Ditto.

* time.c (v2w_bignum): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-10 10:37:39 +00:00
akr 837392b452 * bignum.c (rb_integer_pack): numwords_allocated argument removed.
* internal.h (rb_integer_pack): Follow the above change.

* hash.c (rb_hash): Ditto.

* time.c (v2w_bignum): Ditto.

* pack.c (pack_pack): Ditto.

* random.c (int_pair_to_real_inclusive): Ditto.
  (rand_init): Ditto.
  (random_load): Ditto.
  (limited_big_rand): Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-09 05:53:00 +00:00
akr 874f10cbf2 * time.c (v2w): Use rb_absint_size instead of RBIGNUM_LEN.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 13:31:35 +00:00
akr f1a6b64b1d * time.c (v2w_bignum): Simplified using rb_integer_pack.
(rb_big_abs_find_maxbit): Removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 12:48:39 +00:00
akr 747894a32d * bignum.c (rb_absint_singlebit_p): New function.
* internal.h (rb_absint_singlebit_p): Declared.

* time.c (v2w_bignum): Use rb_absint_singlebit_p instead of
  rb_big_abs_find_minbit.
  (rb_big_abs_find_minbit): Removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 12:05:57 +00:00
akr af612be8e0 * time.c (rb_big_abs_find_maxbit): Use rb_absint_size.
(bdigit_find_maxbit): Removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 11:25:07 +00:00
ktsj edb98f8b91 fix typos. Patch by k_takata.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-19 03:10:21 +00:00
akr a4460ddb48 * time.c (localtime_with_gmtoff_zone): musl libc may return NULL for
tm_zone.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-01 12:12:25 +00:00
akr f674d8623d * time.c (time_strftime): Describe %L and %N truncates digits under
the specified length.
  [ruby-core:52130] [Bug #7829]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-04 13:37:22 +00:00
nobu 77ff241fa0 timev.h: move time_t stuffs
* timev.h (TYPEOF_TIMEVAL_TV_SEC, unsigned_time_t): move from time.c.

* thread.c: use definitions in timev.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-30 21:08:36 +00:00
nobu f2e1bfb897 thread.c: format specifiers for time_t
* thread.c (sleep_timeval): fix format specifiers for time_t.

* time.c (DEBUG_REPORT_GUESSRANGE): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-30 21:08:34 +00:00
akr c64f26a281 * time.c (num_exact): use to_r method only if to_int method is
available.
  [ruby-core:53764] [Bug #8173] reported by Hiro Asari.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-27 11:37:59 +00:00
akr bfb0edbad2 * internal.h: Define TIMET_MAX and TIMET_MIN here.
* time.c: Remove TIMET_MAX and TIMET_MIN definitions.

* thread.c: Ditto.

* thread_pthread.c: Remove TIMET_MAX definition.

* thread_win32.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-26 14:45:55 +00:00
akr e1540cd74d update doc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-26 12:22:12 +00:00
kosaki 798ff850e4 * configure.in: check struct timeval exist or not.
* include/ruby/missing.h (struct timeval): check HAVE_STRUCT_TIMEVAL
  properly. and don't include sys/time.h if struct timeval exist.

* file.c: include sys/time.h explicitly.
* random.c: ditto.
* thread_pthread.c: ditto.
* time.c: ditto.
* ext/date/date_strftime.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-16 05:06:47 +00:00
nobu 84085167f8 time.c: check re-initialize
* time.c (GetTimeval): check if already initialized instance.
* time.c (GetNewTimeval): check if newly created instance.
* time.c (time_init_0, time_init_1, time_init_copy, time_mload): must
  be newly created instance.  [ruby-core:53436] [Bug #8099]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-15 14:06:21 +00:00
zzak c2204ca328 * array.c: Document #<=> return values and formatting
* bignum.c: ditto
* file.c: ditto
* object.c: ditto
* numeric.c: ditto
* rational.c: ditto
* string.c: ditto
* time.c: ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-23 03:35:38 +00:00
nobu 44c5c2a312 compar.c: inversed comarison without infinite recursion
* compar.c (rb_invcmp): compare by inversed comarison, with preventing
  from infinite recursion.  [ruby-core:52305] [Bug #7870]
* string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite
  recursion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-17 11:55:50 +00:00
nobu a773539d3a time.c: st_update
* time.c (zone_str): lookup or insert by using st_update() at once.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-12 09:27:12 +00:00
naruse 1bb1d096fb * time.c (time_mdump): dump timezone string to private instance variable
on marshaling.

* time.c (time_mload): load timezone string from private instance
  variable named 'zone'.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-07 02:55:35 +00:00
nobu 3faee6520e time.c, vm_method.c: update rdoc
* time.c (time_{mdump,dump,mload,load): update rdoc.

* vm_method.c (obj_respond_to_missing): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-01 13:54:54 +00:00