39 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 59e1fe29d6 mrbconf.h: rename MRB_WORDBOX_NO_FLOAT_TRUNCATE to MRB_WORDBOX_NO_INLINE_FLOAT
The old name referred to "truncation" of float precision, which no
longer happens with rotation encoding. The new name describes the
actual behavior: disabling inline float encoding in word boxing.
The old name is kept as an obsolete alias for backward compatibility.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 10:30:01 +09:00
Yukihiro "Matz" Matsumoto 40b0cb98f7 mruby.h: add MRB_OPEN_FAILURE() macro and refactor MRB_OPEN_SUCCESS()
since all current uses check for failure (!MRB_OPEN_SUCCESS), add
MRB_OPEN_FAILURE() as the primary macro for better readability. define
MRB_OPEN_SUCCESS() in terms of MRB_OPEN_FAILURE() to avoid duplication
and optimize the common case. update all usage sites to use the clearer
MRB_OPEN_FAILURE() form.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-16 06:53:02 +09:00
Yukihiro "Matz" Matsumoto 8e50a45f3e mrb_print_error: handle NULL gracefully to simplify error checking
made mrb_print_error() handle NULL by printing "Failed to allocate
mrb_state" when mrb is NULL. since mrb_close() already handles NULL,
this allows simplified error checking pattern:

  if (!MRB_OPEN_SUCCESS(mrb)) {
    mrb_print_error(mrb);  // handles NULL
    mrb_close(mrb);        // handles NULL
    return EXIT_FAILURE;
  }

updated all binary tools (mruby, mirb, mrdb, mrbtest) to use this
simplified pattern, removing nested if checks.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-14 00:49:55 +09:00
Yukihiro "Matz" Matsumoto 05ffe0c441 mrb_open: return mrb_state with exc set on init failure
changed mrb_open() and mrb_open_core() to return mrb_state with mrb->exc
set (instead of NULL) when initialization fails. this allows callers to
programmatically inspect error details, which is essential for embedded
systems without stderr. return NULL only for true allocation failure.

added MRB_OPEN_SUCCESS(mrb) macro to check initialization success, since
mrb != NULL no longer guarantees success. updated all binary tools
(mruby, mirb, mrdb, mrbtest) to use new pattern: check MRB_OPEN_SUCCESS,
print exception details via mrb_print_error if available, then mrb_close.

mrb_core_init_protect now preserves exception in mrb->exc instead of
printing and clearing it, giving caller control over error handling.

breaking change: callers must use MRB_OPEN_SUCCESS(mrb) or check both
mrb != NULL && mrb->exc == NULL. old NULL-only checks will miss
initialization failures.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-13 19:10:46 +09:00
Yukihiro "Matz" Matsumoto f2c8b43d42 mruby-test: stop unused local variable warning 2025-03-09 16:43:28 +09:00
dearblue 79d7ac5f7e Restore the GC arena with tests.
This was the unintentional catalyst for finding the problem in #6329, but it is preferable to add a test if necessary.
2024-08-25 11:08:40 +09:00
Yukihiro "Matz" Matsumoto c5314a29b7 mruby-test: move declarations in driver.c and vformat.c 2024-05-01 13:24:32 +09:00
Yukihiro "Matz" Matsumoto eea72ec84a fix spaces in the type cast expressions (cosmetic changes) 2023-05-18 23:29:16 +09:00
Yukihiro "Matz" Matsumoto d9145b8621 mruby-test/drive.c: add string type check 2023-01-11 10:43:11 +09:00
Yukihiro "Matz" Matsumoto c39ee489e1 Remove non formatting fprintf(). 2022-11-25 16:17:29 +09:00
Yukihiro "Matz" Matsumoto 9c5dc42e59 small cosmetic changes.
I prefer `i++` style unless absolutely necessary.
This commit is an addition to 41e4148.
2022-11-19 17:11:56 +09:00
Yukihiro "Matz" Matsumoto 89ea41f15e mrbconf.h: rename a configuration macro for no truncate floats.
Rename `MRB_WORDBOX_USE_HEAP_FLOAT` to `MRB_WORDBOX_NO_FLOAT_TRUNCATE'.
2021-09-25 14:44:43 +09:00
Yukihiro "Matz" Matsumoto fdfa0caa46 boxing_word.h: rename configuration macro name.
`MRB_WORDBOX_USE_HEAP_FLOAT` instead of `MRB_USE_FLOAT_FULL_PRECISION`.
2021-08-26 16:06:01 +09:00
Yukihiro "Matz" Matsumoto 3b4c4caddc mruby-test/driver.c: change FLOAT_TOLERANCE bigger for inline floats. 2021-08-21 15:25:59 +09:00
Yukihiro "Matz" Matsumoto a5ac9c8790 test/driver.c: remove unused constants related to FIXNUM. 2021-08-02 08:56:38 +09:00
Yukihiro "Matz" Matsumoto 4d6f5be1df mruby-test: MRB_INT_MAX etc. may not fit in Fixnum (inline int). 2021-05-13 15:34:20 +09:00
Yukihiro "Matz" Matsumoto 1cc20978cf Enlarge tolerance limit for float32; close #5329
Along with some refactoring on `mruby-math` tests.
2021-02-07 14:56:34 +09:00
dearblue f0a64329b1 Prohibit array changes by "a"/"*" specifier of mrb_get_args()
The "a"/"*" specifier of the `mrb_get_args()` function will now return `const mrb_value *`.
This is because it is difficult for the caller to check if it is an array object and write-barrier if necessary.
And it requires calling `mrb_ary_modify()` on the unmodified array object, which is also difficult (this is similar to #5087).
2020-10-22 22:55:35 +09:00
Yukihiro "Matz" Matsumoto 5b40bb8d15 Avoid using C struct dump for test Ruby code.
Files under `test/t` and `mrbgem/*/test` are for tests, not for actual
execution. So symbols in those files need not to be pre-allocated. This
change slightly reduce the memory consumption.
2020-10-14 15:52:14 +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 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 52507b1083 Generate C struct from irep instead of binary dump. 2020-10-12 16:21:10 +09:00
KOBAYASHI Shuji eea42e06af Add new specifiers/modifiers to format string of mrb_vfromat()
Format sequence syntax:

  %[modifier]specifier

Modifiers:

  ----------+------------------------------------------------------------
  Modifier  | Meaning
  ----------+------------------------------------------------------------
      !     | Convert to string by corresponding `inspect` instead of
            | corresponding `to_s`.
  ----------+------------------------------------------------------------

Specifiers:

  ----------+----------------+--------------------------------------------
  Specifier | Argument Type  | Note
  ----------+----------------+--------------------------------------------
      c     | char           |
     d,i    | mrb_int        |
      f     | mrb_float      |
      l     | char*, mrb_int | Arguments are string and length.
      n     | mrb_sym        |
      s     | char*          | Argument is NUL terminated string.
      t     | mrb_value      | Convert to type (class) of object.
     v,S    | mrb_value      |
      C     | struct RClass* |
      T     | mrb_value      | Convert to real type (class) of object.
      Y     | mrb_value      | Same as `!v` if argument is `true`, `false`
            |                | or `nil`, otherwise same as `T`.
      %     | -              | Convert to percent sign itself (no argument
            |                | taken).
  ----------+----------------+--------------------------------------------

This change will increase the binary size, but replacing all format strings
with new specifiers/modifiers will decrease the size because it reduces
inline expansion of `mrb_obj_value()`, etc. at the caller.
2019-08-01 13:24:52 +09:00
Yukihiro "Matz" Matsumoto cd8fc9bcb8 Resolved conflicts in #4320 2019-07-29 01:02:03 +09:00
Yukihiro "Matz" Matsumoto 7cf1bc39a7 Merge pull request #4356 from shuujii/add-assert_match-and-assert_not_match
Add `assert_match` and `assert_not_match`
2019-04-22 22:29:15 +09:00
KOBAYASHI Shuji 716a99b069 Add assert_match and assert_not_match 2019-04-14 19:06:28 +09:00
Yukihiro "Matz" Matsumoto b351bdb8d5 Fixed old style declaration; ref #4365 2019-04-10 06:00:38 +09:00
KOBAYASHI Shuji df4b081392 Refactor t_print for test 2019-03-23 19:27:21 +09:00
KOBAYASHI Shuji c3122c887a Do not raise an exception when bintest fail
- An exception do not raise when mrbtest fail.
- There are no useful informations in exception message and backtrace.
2019-03-13 22:04:14 +09:00
KOBAYASHI Shuji f6326803c7 Add a missing file for #4314 2019-03-07 21:36:54 +09:00
KOBAYASHI Shuji f209f781ac Integrate init_mrbtest.c to driver.c in mruby-test mrbgem
- `mrbgemtest_init()` is needed if `DISABLE_GEMS` is enabled because core
  tests are run as part of `mruby-test` mrbgem (moreover, `DISABLE_GEMS` is
  disabled when `enable_test` is used in build config).
- For the same reason `mrb_open_core()` etc for core tests is unneeded.
2019-02-22 20:41:20 +09:00
YAMAMOTO Masaya 625f9f6fa3 Merge branch 'master' of github.com:mruby/mruby 2017-11-04 01:23:12 +09:00
Yukihiro "Matz" Matsumoto fda64be996 Flush stdout after every print from tests 2017-10-28 00:29:30 +09:00
YAMAMOTO Masaya dcd5d0ffec Test for MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
Tomasz Dąbrowski d713f8d761 fix: mrbgems\mruby-test\driver.c(67): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski a8b8abbd82 Fixed float tolerance in tests when MRB_USE_FLOAT is set 2016-11-24 12:48:41 +01:00
Yukihiro "Matz" Matsumoto 5c405dea3d include changed from by quotes ("") to by brackets (<>); close #3032 2015-11-27 17:48:23 +09:00
Zachary Scott 383a7d24d3 Move test source code and rake task to mrbgem 2015-08-22 10:18:12 -04:00