Commit Graph

148 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 033aa98cf4 time.c: Windows API provides clock_gettime.
`gettimeofday` emulation needed no longer.
2021-05-08 10:34:38 +09:00
Yukihiro "Matz" Matsumoto 4d249c28d9 Skip tests that use Float inside; ref #5421 2021-04-24 12:04:08 +09:00
Yukihiro "Matz" Matsumoto 4b4622f711 time.c: fixable_time_t_p is not used with MRB_NO_FLOAT; #5421 2021-04-24 11:38:56 +09:00
Yukihiro "Matz" Matsumoto dc88a87f9b time.c: time_t may be unsigned on some platforms. 2021-04-23 07:53:17 +09:00
Yukihiro "Matz" Matsumoto 049ec9056e time.c: add integer boundary check for year.
On configurations where `sizeof(mrb_int) > sizeof(int)`.
2021-04-19 15:49:50 +09:00
Yukihiro "Matz" Matsumoto bf524e7002 time.c: calendar clock should use CLOCK_REALTIME; 5e95f11
The issue was reported by @shuujii
2021-03-14 14:54:53 +09:00
Yukihiro "Matz" Matsumoto f2b3529441 time.c: fix errors on Windows and macOS; ref #5354
`gmtime_r` detection logic was too strict.
2021-03-08 15:23:29 +09:00
Yukihiro "Matz" Matsumoto cb3a6dd168 ISO C99 doesn't support unnamed unions; fix #5354 2021-03-08 11:50:52 +09:00
Yukihiro "Matz" Matsumoto 2be1a9c3c7 time.c: timespec_get() never fails. 2021-03-03 12:01:49 +09:00
Yukihiro "Matz" Matsumoto 42afafbd23 time.c: fixed wrong condition to include unistd.h. 2021-03-03 10:15:50 +09:00
Yukihiro "Matz" Matsumoto 79e2ad9a44 time.c: Windows does not have unistd.h. 2021-03-03 10:01:32 +09:00
Yukihiro "Matz" Matsumoto 5e95f11756 time.c: use clock_gettime() if possible. 2021-03-03 09:53:11 +09:00
Yukihiro "Matz" Matsumoto 0c631a4c08 time.c: adjust buffer size in mrb_time_asctime(). 2021-03-03 09:52:26 +09:00
Yukihiro "Matz" Matsumoto 384209b8dd time.c: fix compile errors in mrb_time_asctime(). 2021-03-03 09:51:27 +09:00
Yukihiro "Matz" Matsumoto 935a135553 time.c: fixed a bug on no builtin overflow (e.g. VC). 2021-03-01 11:35:15 +09:00
Yukihiro "Matz" Matsumoto 65add8c650 time.c: avoid using mrb_int_{add,sub}_overflow().
The size and signedness of `mrb_int` and `time_t` may differ.
2021-03-01 07:58:14 +09:00
Yukihiro "Matz" Matsumoto 03eb3b5e87 time.c: check overflow in addition and subtraction of Time. 2021-02-28 19:33:57 +09:00
Yukihiro "Matz" Matsumoto 8684abd697 Remove periods from error messages according to the convention. 2021-02-28 19:32:52 +09:00
Yukihiro "Matz" Matsumoto b61766473b time.c: change RuntimeError to ArgumentError. 2021-02-28 19:26:40 +09:00
Yukihiro "Matz" Matsumoto 17ecf14511 Revert "Minimize the changes in #5277"
This reverts commit dc51d89ac2.
2021-01-26 10:57:07 +09:00
Yukihiro "Matz" Matsumoto dc51d89ac2 Minimize the changes in #5277
Instead of including `mruby/presym.h` everywhere, we provided the
fallback `mruby/presym.inc` under `include/mruby` directory, and specify
`-I<build-dir>/include` before `-I<top-dir>/include` in `presym.rake`.
So even when someone drops `-I<build-dir>/include` in compiler options,
it just compiles without failure.
2021-01-22 18:38:53 +09:00
KOBAYASHI Shuji 90b53f4c29 Avoid including presym.inc in existing header files
Addressed an issue where existing programs linking `libmruby.a` could only
be built by adding `<build-dir>/include` to compiler's include path.
2021-01-11 09:21:07 +09:00
KOBAYASHI Shuji 3d056d084a Rename MRB_{ENABLE,DISABLE}_ to MRB_{USE,NO}_; close #5163
|        Previous Name         |        New Name         |
|------------------------------|-------------------------|
| MRB_ENABLE_ALL_SYMBOLS       | MRB_USE_ALL_SYMBOLS     |
| MRB_ENABLE_SYMBOLL_ALL       | MRB_USE_ALL_SYMBOLS     |
| MRB_ENABLE_CXX_ABI           | MRB_USE_CXX_ABI         |
| MRB_ENABLE_CXX_EXCEPTION     | MRB_USE_CXX_EXCEPTION   |
| MRB_ENABLE_DEBUG_HOOK        | MRB_USE_DEBUG_HOOK      |
| MRB_DISABLE_DIRECT_THREADING | MRB_NO_DIRECT_THREADING |
| MRB_DISABLE_STDIO            | MRB_NO_STDIO            |
| ENABLE_LINENOISE             | MRB_USE_LINENOISE       |
| ENABLE_READLINE              | MRB_USE_READLINE        |
| DISABLE_MIRB_UNDERSCORE      | MRB_NO_MIRB_UNDERSCORE  |
| DISABLE_GEMS                 | MRB_NO_GEMS             |

* `MRB_ENABLE_SYMBOLL_ALL` seems to be a typo, so it is fixed.
* `MRB_` prefix is added to those without.
* The previous names can also be used for compatibility.
2020-11-21 21:14:40 +09:00
Yukihiro "Matz" Matsumoto d0b5d720ac Use mrb_integer() instead of mrb_int().
`mrb_int()` includes implicit integer conversion, where `mrb_integer()`
does not. In this case, we know `obj` is an integer before hand.
2020-10-12 18:20:07 +09:00
Yukihiro "Matz" Matsumoto 5134031e18 Use mrb_int_value() instead of mrb_fixnum_value().
Where fixnum overflow can happen.
2020-10-12 18:20:05 +09:00
Yukihiro "Matz" Matsumoto 2b188ed8a1 Reorganize Integer system.
- Integrate `Fixnum` and `Integer`
- Remove `Integral`
- `int / int -> int`
- Replace `mrb_fixnum()` to `mrb_int()`
- Replace `mrb_fixnum_value()` to `mrb_int_value()`.
- Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12 18:19:54 +09:00
Yukihiro "Matz" Matsumoto 55163a8a0a Rename MRB_TT_FIXNUM to MRB_TT_INTEGER.
We still have `#define MRB_TT_FIXNUM MRB_TT_INTEGER` for compatibility.
2020-10-12 16:21:47 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT`
- `MRB_USE_FLOAT` => `MRB_USE_FLOAT32`

The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto dea185e687 Change out-of-range condition of time_t conversion. 2020-10-12 16:21:38 +09:00
Yukihiro "Matz" Matsumoto 968053a35b Avoid out-of-range error for negative time on MRB_TIME_T_UINT.
On platforms where `time_t` is unsigned, negative time can be a result
of integer casting. Out-of-range error is too strict for those cases.
This fix does not address wrong time value in `MRB_WORD_BOXING`. It will
be addressed later (by introducing "big" integers).
2020-10-12 16:21:37 +09:00
Yukihiro "Matz" Matsumoto 2a366ffba8 Use functions that take symbols to reduce string litrals in C. 2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto 49ae2a69f2 Add mrb_get_arg1() that retrieves single (and only) argument.
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one
argument.

And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
2020-06-20 12:49:46 +09:00
Yukihiro "Matz" Matsumoto 8bca11a64e Merge pull request #4800 from shuujii/set-MRB_STR_ASCII-flag-to-some-stringize-methods
Set `MRB_STR_ASCII` flag to some stringize methods
2020-06-03 14:01:52 +09:00
dearblue cc1db2d117 Remove unnecessary 'stdio.h'; ref #4947
'stdio.h' is included in 'mruby.h' ('mrbconf.h').

However, keep 'stdio.h' used by mruby-test.
2020-03-08 21:42:09 +09:00
Yukihiro "Matz" Matsumoto 0301d8a89b Fix integer boundary check before float to time_t casting. 2020-02-12 11:54:32 +09:00
KOBAYASHI Shuji b493229a23 Silence GCC warning in time.c on Travis CI
Silence the following warnings:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:260:55: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if ((MRB_INT_MAX > MRB_TIME_MAX && i > 0 && i > MRB_TIME_MAX) ||
                                                  ^
  ```
2019-12-31 21:52:20 +09:00
KOBAYASHI Shuji e6033e00fe Auto detect MRB_TIME_T_UINT 2019-12-05 21:40:15 +09:00
KOBAYASHI Shuji ea1911d23f Silence Clang warning with MRB_INT64 and MRB_32BIT in time.c
Silence the following warnings:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:871:15: warning: result of comparison of constant 9223372036854775807 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) {
        ~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:871:40: warning: result of comparison of constant -9223372036854775808 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) {
                                 ~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:887:16: warning: result of comparison of constant 9223372036854775807 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) {
        ~~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:887:42: warning: result of comparison of constant -9223372036854775808 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) {
                                ~~~~~~~~ ^ ~~~~~~~~~~~
  ```
2019-12-03 22:50:50 +09:00
KOBAYASHI Shuji 6973539005 Silence Clang warning with MRB_INT32 and MRB_64BIT in time.c
Silence the following warning:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:258:60: warning: result of comparison of constant -9223372036854775808 with expression of type 'mrb_int' (aka 'int') is always false [-Wtautological-constant-out-of-range-compare]
        if ((mrb_time_int)i > MRB_TIME_MAX || MRB_TIME_MIN > i) {
                                              ~~~~~~~~~~~~ ^ ~
  ```
2019-12-02 20:00:36 +09:00
KOBAYASHI Shuji ad6c58972c Set MRB_STR_ASCII flag to some stringize methods
- `Fixnum#to_s`, `Fixnum#inspect`
- `Float#to_s`, `Float#inspect`
- `NilClass#to_s`, `NilClass#inspect`
- `FalseClass#to_s`, `FalseClass#inspect`
- `TrueClass#to_s`, `TrueClass#inspect`
- `Time#to_s`, `Time#inspect`
2019-10-31 22:04:56 +09:00
Yukihiro "Matz" Matsumoto 529a336966 Fixed a bug in mruby-time with NO_GETTIMEOFDAT. 2019-10-10 20:46:12 +09:00
dearblue eb2f34719d Fix MRB_WITHOUT_FLOAT reversal; fix #4598 2019-09-25 22:55:41 +09:00
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in
my environment than before the introduction of new specifiers/modifiers
(5116789a) with this change.

  ------------+-------------------+-------------------+--------
   BINARY     | BEFORE (5116789a) |   AFTER (This PR) |  RATIO
  ------------+-------------------+-------------------+--------
   mruby      |      593416 bytes |      593208 bytes | -0.04%
   libmruby.a |      769048 bytes |      767264 bytes | -0.23%
  ------------+-------------------+-------------------+--------

BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613,
so I put it back.
2019-08-05 13:18:50 +09:00
dearblue 07308a2fc9 Suppress compiler warnings for mruby-time; fix #4600
Warnings:

- If `MRB_TIME_T_UINT` is defined, the compiler issues a warning with an
  integer comparison of different signs.
- It is mentioned that the `usec` variable passed to the
  `mrb_to_time_t()` function may not be initialized
2019-08-03 10:35:39 +09:00
KOBAYASHI Shuji 5116789aa0 Fix UTC offset representation in Time#to_s on some environments; ref #4604
Use own implementation to calculate UTC offset on Visual Studio 2015 or
earlier or MinGW because `strftime("%z")` on these environments does not
conform C99.
2019-07-31 20:34:27 +09:00
Sutou Kouhei effae4ae55 Fix Time#to_s encoding on Windows
strftime() on Windows returns locale encoding time zone for "%z" even
if MSDN says "%z" is "The offset from UTC in ISO 8601 format; no
characters if time zone is unknown" in MSDN:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=vs-2019

So we need to convert encoding of string from strftime().
2019-07-29 18:16:21 +09:00
dearblue fda5c0c073 Fix the lack of precision for Time; ref d74355061
- `Time.local` and `Time.utc` are able to use with `MRB_INT16 + MRB_WITHOUT_FLOAT`.

  - `time_t` is converted directly from the Ruby object.

  - `time + sec` and` time - sec` are not affected by the precision of `mrb_float`.

    Similarly, calculations are possible with `MRB_INT16 + MRB_WITHOUT_FLOAT`.
2019-07-27 21:25:18 +09:00
dearblue 1467c14adc Fix mruby-time with MRB_WITHOUT_FLOAT; ref d74355061 2019-07-27 14:42:37 +09:00
Yukihiro "Matz" Matsumoto d74355061b Fix mruby-time to work with MRB_WITHOUT_FLOAT; ref #4576
As a side effect, `mrb_time_at()` now takes `mrb_int` instead of
`double` as time arguments.
2019-07-22 21:34:37 +09:00
Yukihiro "Matz" Matsumoto 87d1b2a910 Improve conflict error message of Time and Math; ref #4576 2019-07-22 20:21:30 +09:00