On 32-bit platforms whose ABI gives 8-byte members 8-byte alignment
(xtensa, ARM, MIPS, PowerPC, ...), MRB_NAN_BOXING failed to build with
"RVALUE size must be within 5 words" because two structs got padded
past the budget:
- struct RBreak: had an existing MRB_USE_RBREAK_VALUE_UNION workaround
that stores the value as uint32_t[] to avoid forcing 8-byte alignment
on the struct, but the gate only enabled it for MRB_NO_BOXING.
Extend to NAN_BOXING + 32-bit, with a NAN_BOXING-specific get/set
(no separate tt to stash since nan-boxing encodes type in the bits).
- struct RArray: MRB_ARY_NO_EMBED was similarly gated to NO_BOXING;
embedded mrb_value[] forces 8-byte alignment of the inner union and
pads the heap-form layout. Extend the gate to NAN_BOXING + 32-bit.
Both gates now name the structural property (32-bit + mrb_value has an
8-byte aligned member) rather than enumerating boxing modes, so adding
new boxing modes won't silently miss this class of bug again.
i386's System V ABI gives uint64_t only 4-byte alignment, hiding the
problem on x86 -m32; -malign-double simulates the strict-alignment ABI
that exhibits the failure, and is what was used to verify the fix.
Closes#6815, reported by dearblue.
Co-authored-by: Claude <noreply@anthropic.com>
- array.h: disable embedded arrays when MRB_INT64 makes mrb_value
too large to embed (fixes MRB_ARY_EMBED_LEN_MAX assertion)
- error.h: enable MRB_USE_RBREAK_VALUE_UNION for all 32-bit
no-boxing builds (MRB_USE_FLOAT32 is irrelevant without
word/nan boxing)
- gc.c: restrict RVALUE 8-byte alignment padding to
MRB_WORD_BOXING builds (fixes RVALUE size assertion)
- vm.c: guard direct ary->as.ary access with MRB_ARY_NO_EMBED
Fixes#6722.
Co-authored-by: Claude <noreply@anthropic.com>
during eql? callbacks, array modifications can cause elements in khash to
be freed by GC, leading to use-after-free. create temporary shared copies
of arrays before populating khash to protect elements during callbacks.
Co-authored-by: Claude <noreply@anthropic.com>
Internal functions can only be called from within the library.
Functions listed in `mruby/internal.h` can be called from:
* core (src/*.c)
* gems (mrbgems/**/*.c)
But not from the application linked with `libmruby`.
Running pre-commit with GitHub Actions now gives us more tests and coverage
Remove duplicate GitHub Actions for merge conflicts and trailing whitespace
Remove duplicate checks for markdownlint and yamllint from the GitHub Super-Linter
Add new custom pre-commit hook running with a shell script to sort alphabetically and uniquify codespell.txt
Add new pre-commit hook to check spelling with codespell
https://github.com/codespell-project/codespell
Fix spelling
Normally a single spell checker can't find all the mistakes or check all types of code.
These mistakes were found by another spell checker inside my editor with a more manual sift / find.
Formerly, `__send__(*args)` modified `args` with `Array#shift`.
This bug affects optcarrot.
This changeset avoids the array destruction by using
`args = args[1, len-1]`.
When removing elements from an array, it is possible to avoid creating
an empty array.
Before this patch:
```c
mrb_ary_splice(mrb, ary, head, len, mrb_ary_new(mrb));
```
After this patch:
```c
mrb_ary_splice(mrb, ary, head, len, mrb_undef_value());
```
Previously, `mrb_int` was used as the type that represents the buffer size
on memory, but the sizes of `RString` and `RArray` exceed 6 words when
`MRB_INT64` is enabled on 32-bit CPU.
I don't think it is necessary to be able to represent the buffer size on
memory that exceeds the virtual address space. Therefore, for this purpose,
introduce `mrb_ssize` which doesn't exceed the sizes of `mrb_int` and
pointer.
I think all `mrb_int` used for this purpose should be changed to
`mrb_ssize`, but currently only the members of the structures (`RString`,
`mrb_shared_string`, `RArray` and `mrb_shared_array`) are changed.
Functions to add prototypes to headers:
* mrb_ary_splice()
* mrb_notimplement()
* mrb_vformat()
* mrb_cstr_to_dbl()
* mrb_cstr_to_inum()
Functions to be made `static` (`MRB_API` was not needed):
* mrb_mod_module_function()
* mrb_obj_hash()
* mrb_str_len_to_inum()
Functions to remove `MRB_API` from definitions (referenced from within `libmruby`):
* mrb_mod_cv_defined()
* mrb_mod_cv_get()
* mrb_f_send()
It reduces the memory consumption and sometimes improve the
performance as well. For example, the consumed memory size
of `bench/bm_ao_render.rb` is reduced from 1.2GB to 1GB, and
its total execution time become 18.795 sec from 22.229 sec.
if you see compiler errors due to this commit, you'd better to use array-modifying
functions, e.g. mrb_ary_set() or mrb_ary_push(), otherwise you might see nasty
GC bugs in the future. if you are sure what you are doing, replace `RARRAY_PTR(ary)`
by `mrb_ary_ptr(ary)->ptr`. but be warned.