159 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto afc0753c1d symbol.c: add dynamic symbol limit (MRB_SYMBOL_MAX)
track dynamic (runtime-created) symbols separately from presyms,
inline symbols, and static C API symbols. raise RuntimeError when
the dynamic symbol count exceeds MRB_SYMBOL_MAX (default 4096).

this prevents DoS attacks via unbounded symbol creation (e.g.
"str".to_sym in a loop). presyms and inline symbols are not
counted toward the limit.

infrastructure for future symbol GC: sym_flags array tracks
per-symbol metadata (SYM_FL_DYNAMIC flag).

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:26 +09:00
HASUMI Hitoshi 736a72cdc9 [skip ci] Update include/mrbconf.h
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-03-19 09:50:15 +09:00
HASUMI Hitoshi 5e9eed2d0c Fix KHASH_DEFAULT_SIZE to KHASH_INITIAL_SIZE rename inconsistencies
Commit 250bf6edd renamed KHASH_DEFAULT_SIZE to KHASH_INITIAL_SIZE but
missed updating build_config files and documentation. Also restore the
default value in khash.h to 32, consistent with the documented default
and the profile hierarchy (MRB_CONSTRAINED_BASELINE_PROFILE reduces it
to 16).
2026-03-19 09:38:36 +09:00
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 eaaa66b39b mrbconf.h: prohibit MRB_INT64 on 32-bit with word/NaN boxing
Heap-allocated RInteger with int64_t requires 8-byte alignment,
but GC heap slots on 32-bit may not guarantee it, causing SIGBUS
on architectures like MIPS. MRB_NO_BOXING is still allowed since
integers are stored inline in mrb_value (no heap RInteger).

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 09:55:21 +09:00
Yukihiro "Matz" Matsumoto a217935e7d symbol.c: implement adaptive symbol table for memory efficiency
Replace fixed 256-element hash array in mrb_state with adaptive approach:
- Linear search for <=255 symbols (typical embedded use case)
- Hash table allocated on-demand when symbols exceed threshold
- Reduces mrb_state size by 1KB per instance (1068->36 bytes in symbol fields)
- Configurable threshold via MRB_SYMBOL_LINEAR_THRESHOLD in mrbconf.h

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:08 +09:00
Yukihiro "Matz" Matsumoto eb5fbfbb40 class.c: Remove MRB_INLINE_METHOD_CACHE support from mt_tbl
The sorted array binary search implementation no longer uses the inline
cache array, so remove all MRB_INLINE_METHOD_CACHE definitions and
related code.
2025-05-28 08:33:21 +09:00
John Bampton e12da35645 Fix spelling 2024-09-24 00:14:24 +10:00
dearblue 328eb71e52 Reorganize mrb_cache_entry and mrb_method_t types
The purpose is to remove the `mid` field from the `mrb_cache_entry` structure.
The resulting RAM requirement for the method cache is reduced from 5 words per entry to 4 words per entry for 32-bit CPUs.

The relevant changes are as follows:

  - Removed `MRB_USE_METHOD_T_STRUCT`.

    The `mrb_method_t` type is now always defined as a structure.

  - Include method IDs in `mrb_method_t`

    Change the `flags` member to `uint32_t`.
    The bitstring structure should be the same as the keys of the `mt` table in `class.c`.

I believe the impact on API compatibility with previous versions is minimal.
2024-03-30 18:19:26 +09:00
dearblue f6c9191cd0 Replace MRB_NO_DIRECT_THREADING with MRB_USE_VM_SWITCH_DISPATCH
The correct technique now is "Token Threading".
However, the new name was chosen because it was felt that if a different technique was added in the future, there would be no need to replace it.
2023-03-18 17:39:41 +09:00
Yukihiro "Matz" Matsumoto 16a224e25d mrbconf.h: add MRB_USE_INLINE_METHOD_CACHE option description.
Currently it does not improve the performance (yet).
2022-10-10 22:23:10 +09:00
Yukihiro "Matz" Matsumoto 13d909bd3c array.c: new configuration MRB_ARY_LENGTH_MAX.
The default value is 2**17 entries. If you want to avoid the limitation,
set this value to 0.
2022-07-25 10:58:02 +09:00
Yukihiro "Matz" Matsumoto c4cb416460 string.c: new configuration MRB_STR_LENGTH_MAX.
The default value is 1MB. If you want to avoid the limitation, set this
value to 0.
2022-07-25 10:58:02 +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 49602f636d value.h: add configuration macros around mrb_ro_data_p(); close #5547
- `MRB_USE_ETEXT_RO_DATA_P`: use `etext` and `edata`
- `MRB_NO_DEFAULT_RO_DATA_P`: not use the default `mrb_ro_data_p()`
2021-09-09 16:15:25 +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 e9c6e52f5b value.h: reconstruct mrb_ro_data_p().
* use predefined `mrb_ro_data_p()` for user-mode Linux and macOS
* define `MRB_LINK_TIME_RO_DATA_P` if predefined one is used
* configure macro `MRB_USE_LINK_TIME_RO_DATA_P` is no longer used
* contributions for new platforms are welcome
2021-08-26 16:06:01 +09:00
Yukihiro "Matz" Matsumoto 36632f55f4 boxing_word.h: embed mrb_float in mrb_value if possible.
Embedding reduce memory consumption, sacrificing precision. It clips least
significant 2 bits from `mrb_float`, so if you need to keep float precision,
define `MRB_USE_FLOAT_FULL_PRECISION`.

`MRB_WORD_BOXING` and `MRB_INT64`:

`mrb_float` (`double`) is embedded in `mrb_value` clipped last 2 bits.

`MRB_WORD_BOXING` and `MRB_INT64` and `MRB_USE_FLOAT_FULL_PRECISION`:

`mrb_float` is allocated in the heaps wrapped by `struct RFloat`.

`MRB_WORD_BOXING` and `MRB_INT32` and `MRB_USE_FLOAT32`:

`mrb_float` (`float`) is embedded in `mrb_value` clipped last 2 bits.
In addition, to reserve bit space in the `mrb_value`, maximum inline
symbol length become 4 (instead of 5) in the configuration.

`MRB_WORD_BOXING` and `MRB_INT32`:

Assume `MRB_USE_FLOAT_FULL_PRECISION` and allocate Float values in heap.
2021-08-21 15:25:58 +09:00
Yukihiro "Matz" Matsumoto 5c804cf68f Remove redundant include headers.
- stdlib.h
- stddef.h
- stdint.h
- stdarg.h
- limits.h
- float.h
2021-07-25 13:07:10 +09:00
Yukihiro "Matz" Matsumoto 1d0cfb359c Update mrb_bool definition; close #2385
- move `TRUE/FALSE` definition from `mrbconf.h` (not configurable)
- use C/C++ definition of boolean type for `mrb_bool`

The fix is originally written by @take-cheeze.
2021-05-13 19:30:41 +09:00
John Bampton 9d32d440eb feat(CI): add the GitHub Super Linter
The GitHub Super Linter is a more robust and better supported
tool than the current GitHub Actions we are using.

Running these checks:

ERROR_ON_MISSING_EXEC_BIT: true
VALIDATE_BASH: true
VALIDATE_BASH_EXEC: true
VALIDATE_EDITORCONFIG: true
VALIDATE_MARKDOWN: true
VALIDATE_SHELL_SHFMT: true
VALIDATE_YAML: true

https://github.com/marketplace/actions/super-linter
https://github.com/github/super-linter

Added the GitHub Super Linter badge to the README.

Also updated the pre-commit framework and added
more documentation on pre-commit.

Added one more pre-commit check: check-executables-have-shebangs

Added one extra check for merge conflicts to our
GitHub Actions.

EditorConfig and Markdown linting.

Minor grammar and spelling fixes.

Update linter.yml
2021-04-16 16:37:52 +09:00
KOBAYASHI Shuji 58ef897696 Allow obsoluted MRB_METHOD_T_STRUCT 2020-12-05 17:37:39 +09:00
Yukihiro "Matz" Matsumoto a33f9d7b65 Small refactoring regarding symbols for clarity. 2020-11-26 09:42:08 +09:00
Yukihiro "Matz" Matsumoto fc98aa290f Remove no longer used `MRB_IV_SEGMENT_SIZE; close #5188 [ci skip] 2020-11-25 08:31:10 +09:00
Yukihiro "Matz" Matsumoto 39a11f323e Remove mrb_str_buf_new() and MRB_STR_BUF_MIN_SIZE; close #5171 2020-11-22 22:54:21 +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 7f66e50ba2 Explain MRB_USE_MALLOC_TRIM; ref #5069 2020-10-12 18:20:14 +09:00
Yukihiro "Matz" Matsumoto 5a7cbebc8a Remove MRB_NO_FLOAT_INLINE and MRB_WBOX_FLOAT_INLINE configuration.
They are not used from the beginning.
2020-10-12 16:21:49 +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 72d071540c Rename MRB_METHOD_T_STRUCT to MRB_USE_METHOD_T_STRUCT.
It's the first change of renaming configuration options to `MRB_XXX` to
`MRB_USE_XXX` or `MRB_NO_XXX`.
2020-10-12 16:21:38 +09:00
Yukihiro "Matz" Matsumoto 66114f8332 Change default mrb_value representation to MRB_WORD_BOXING. 2020-10-12 16:21:37 +09:00
Yukihiro "Matz" Matsumoto a93ef815be Add static check for MRB_USE_FLOAT and MRB_WITHOUT_FLOAT. 2020-10-12 16:21:36 +09:00
Yukihiro "Matz" Matsumoto 1eb71b008f Change default boxing scheme from MRB_NO_BOXING.
On 64bit platforms: `MRB_NAN_BOXING`
On 32bit platforms: `MRB_WORD_BOXING`
On debugging: `MRB_NO_BOXING`
2020-10-12 16:21:26 +09:00
Yukihiro "Matz" Matsumoto 3d8a38bea4 You don't need to keep index in local variables info in irep. 2020-10-12 16:21:22 +09:00
Yukihiro "Matz" Matsumoto 639946a006 Enable method cache by default.
Introduced `MRB_NO_METHOD_CACHE` which is inverse of `MRB_METHOD_CACHE`
that should be enabled intestinally. In addition, the default cache is
made bigger (128 -> 256).
2020-10-12 16:21:22 +09:00
Horimoto Yasuhiro a5bfe548d7 Enable MRB_METHOD_T_STRUCT by default on 32bit GUN/Linux
Because we can't use the highest 2 bits of function pointers.
2020-05-04 15:34:16 +09:00
Sutou Kouhei 96d727177e Enable MRB_METHOD_T_STRUCT by default on 32bit Windows
Because we can't use the highest 2 bits of function pointers.
2020-03-04 18:35:40 +09:00
Yukihiro "Matz" Matsumoto ff57c0278f Remove broken MRB_INT16 configuration option. 2020-01-15 21:32:00 +09:00
KOBAYASHI Shuji 351c9c80e7 Always enable the rational and complex literals
I think they can always be enabled because the regular expression literal is
always enabled.
2019-11-19 21:10:59 +09:00
Fangrui Song 7f044341f9 Rename MRB_USE_ETEXT_EDATA to MRB_USE_LINK_TIME_RO_DATA_P and support lld linked programs
In lld linked programs, .rodata comes before .text, thus mrb_ro_data_p
will return false for strings in .rodata. Change the lower bound from
_etext to __ehdr_start to catch these cases. This works for ld.bfd, gold
and lld, and it does not have false positives even if .init_array does
not exist.

Remove the branch that uses _edata: strings in .data can be modified so
this is semantically incorrect. Delete the __APPLE__ branch (its
manpages say get_etext() and get_edata() are strongly discouraged).
.init_array has been adopted by most ELF platforms to supersede .ctors.

Neither _etext nor _edata is used, so rename MRB_USE_ETEXT_EDATA to
MRB_USE_EHDR_START.
2019-09-21 17:55:14 -07:00
Yukihiro "Matz" Matsumoto 2256bb07b0 Remove MRB_METHOD_TABLE_INLINE.
`MRB_METHOD_TABLE_INLINE` was fragile. It requires `-falign-functions=n`.
On platform that uses higher bits of function pointers, you can use new
`MRB_METHOD_T_STRUCT` configuration macro.
2019-09-16 11:14:13 +09:00
dearblue a14ae80102 (Proof of Concept) mruby tuning profiles [ci skip]
Not only mruby, it is one of the difficult things to adjust the performance vs. memory efficiency of the software.
If the approximate target device is divided and the adjustment value for it is prepared by default, it is a good indicator to do fine adjustment.

This PR divides into four profiles.

***Caution: There is no basis for the definitions in the patch.***

- `MRB_CONSTRAINED_BASELINE_PROFILE` - for microprocessors. Reduce memory consumption.
- `MRB_BASELINE_PROFILE` - Default value of mruby.
- `MRB_MAIN_PROFILE` - For desktop computers. Assume that a huge amount of RAM, 10 MiB or more, is on board.
- `MRB_HIGH_PROFILE` - for servers. Assume that mruby VM has a long life.

As you can see the profile name has been ~~stolen~~ imitated from H.264.
2019-05-17 22:32:01 +09:00
Ukrainskiy Sergey 8808219e6d Initial suffix support 2019-05-15 16:57:21 +09:00
dearblue 828a998941 Update document for MRB_USE_CUSTOM_RO_DATA_P 2019-04-27 22:29:20 +09:00
dearblue b57f61ac95 Update document for any configurations
- (Modify) `MRB_INT16`
- (Add)    `MRB_INT32`
- (Modify) `MRB_INT64`
- (Add)    `MRB_USE_ETEXT_EDATA`
- (Add)    `MRB_NO_INIT_ARRAY_START
- (Add)    `MRB_WITHOUT_FLOAT`
- (Add)    `MRB_METHOD_CACHE`
- (Add)    `MRB_METHOD_CACHE_SIZE`
- (Add)    `MRB_METHOD_TABLE_INLINE
- (Add)    `MRB_ENABLE_ALL_SYMBOLS`
2019-04-27 22:28:54 +09:00
Yukihiro "Matz" Matsumoto 37bc343e0a Disable Symbol.all_symbols. 2019-02-12 17:30:34 +09:00
dearblue e9ceb865b6 Fix MRB_ENDIAN_BIG is always defined, if byte order macro is not defined 2018-12-22 20:37:51 +09:00
Yukihiro "Matz" Matsumoto ed2bc5d4ed Simplify MRB_ENDIAN_BIG macro definition; ref #4190
`cpp` does not raise error on undefined macro access in condition.
2018-12-21 09:28:19 +09:00
Yukihiro "Matz" Matsumoto f5537912ab Define MRB_ENDIAN_BIG automatically; ref #4190
You had to define this macro on big endian platforms, but it is very
error-prone. So define the macro automatically if possible.
2018-12-21 08:57:17 +09:00
Yukihiro "Matz" Matsumoto 83f2654bac Do not use MRB_METHOD_TABLE_INLINE by default; fix #3924
It was default on Linux. Abandoned for 2 reasons:

* some cross-platform compiler defines `__linux__` even on bare metal
  environment (RTL8196 (MIPS big endian soc) for example).

* some compilers do not align functions pointers so that we need to
  specify `-falign-functions=n` (where n>1). It's not suitable for
  default configuration.

By our measurement, `mrbtest` consumes 400KB less memory. So if your
target machine is memory tight, add the following command-line options
to `GCC` (unfortunately `clang` does not support `-falign-functions`).

`-falign-functions=2 -DMRB_METHOD_TABLE_INLINE`
2018-01-25 14:22:01 +09:00