Commit Graph

74 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 729b84cf26 mruby-array-ext: fix use-after-free in array set operations; fix #6662
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>
2025-11-13 11:51:53 +09:00
Yukihiro "Matz" Matsumoto c4464fa25a array.c: expose mrb_ary_dup() as a new C API 2025-06-29 20:46:51 +09:00
Yukihiro "Matz" Matsumoto b99c389ec3 internal.h: aggregate internal functions.
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`.
2022-04-02 18:25:13 +09:00
Yukihiro "Matz" Matsumoto 572a43de84 mruby.h: reorganize mrb_ensure/check functions in headers. 2021-09-01 07:00:53 +09:00
Yukihiro "Matz" Matsumoto cd02cef465 array.h: avoid duplicated defined of MRB_ARY_NO_EMBED; fix #5520 2021-08-07 06:48:03 +09:00
John Bampton dab5502e8a Run pre-commit with GitHub Actions
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
2021-06-16 08:34:54 +10:00
Yukihiro "Matz" Matsumoto 48b08fecba array.c: unify mrb_ary_ref and mrb_ary_entry
Use only `mrb_ary_entry` hereafter.
2021-05-27 21:43:43 +09:00
John Bampton be40e9c783 chore: 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.
2021-02-13 17:21:17 +10:00
Yukihiro "Matz" Matsumoto 2af8e16cc6 include/mruby/array.h: ARY_LEN() should return mrb_int.
It used to return `mrb_ssize` but its size may differ from `mrb_int`,
e.g. `MRB_INT64` on `MRB_32BIT` architecture.
2021-02-12 16:57:33 +09:00
Yukihiro "Matz" Matsumoto db1172b48c Allow the case MRB_32BIT and MRB_NO_BOXING and MRB_USE_FLOAT32; #4382 2021-02-08 17:46:38 +09:00
John Bampton 4fa3359d44 refactor: remove trailing whitespace from C, Header, Ruby and YAML files
Lint
2020-12-15 19:44:02 +10:00
John Bampton 940dec5e7d Fix spelling 2020-12-13 18:38:22 +10:00
dearblue 3ac6c3f090 Fix documents for mrb_ary_splice() [ci skip] 2020-11-21 15:47:59 +09:00
Yukihiro "Matz" Matsumoto 7c80edb577 Revert half of 9fbf0ef8.
I misunderstand the meaning of #4483. Sorry.
2020-11-17 22:47:25 +09:00
Yukihiro "Matz" Matsumoto 9fbf0ef886 Refactoring integer ranges.
- Remove `mrb_ssize`
- Fix `MRB_FIXNUM_{MIN,MAX}` to 32 bits on `MRB_NAN_BOXING`
2020-11-17 12:41:10 +09:00
Yukihiro "Matz" Matsumoto 8813ebec07 Skip array embedding if MRB_NO_BOXING and MRB_32BIT; fix #4382
On some platforms, `sizeof(mrb_value) > sizeof(void*)*3`, which makes
`MRB_ARY_EMBED_LEN_MAX` zero. And zero sized array cause compile errors.
2020-10-12 16:21:36 +09:00
Yukihiro "Matz" Matsumoto 6fbc03b3a8 Revert 4c001673b
Probably I misunderstand strict aliasing rule of C++. The fix in
4c001673b was other way around.
2020-10-12 16:21:30 +09:00
Yusuke Endoh 6f4c585bd7 Do not destruct rest arguments for __send__
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]`.
2020-05-24 01:25:03 +09:00
dearblue 26eb29547b Support undef for mrb_ary_splice() instead of []
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());
```
2020-04-24 21:32:35 +09:00
KOBAYASHI Shuji a2df247063 Introduce mrb_ssize type for buffer size on memory; ref #4483
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.
2019-11-21 19:34:02 +09:00
Yukihiro "Matz" Matsumoto 4c001673b6 Avoid C++ strict aliasing warning.
Based on code proposed by @dearblue to avoid the warning:
`dereferencing type-punned pointer will break strict-aliasing rules`.
2019-08-20 22:50:21 +09:00
Yukihiro "Matz" Matsumoto b5e2d208b9 Merge pull request #4636 from davidsiaw/doxygen
Generate doxygen docs for mruby
2019-08-19 07:29:46 +09:00
David Siaw b5299b1c58 fix up documentation for values 2019-08-18 20:12:44 +09:00
Yukihiro "Matz" Matsumoto b55e72b2d6 Resolve conflict between #4582 and C++ warning. 2019-08-17 15:47:14 +09:00
Yukihiro "Matz" Matsumoto c1a0a99309 Update struct RArray union to silence C++ warning. 2019-08-16 22:51:07 +09:00
KOBAYASHI Shuji 79a7f18150 Avoid potential zero size array declaration; fix #4382 2019-04-16 19:56:11 +09:00
Yukihiro "Matz" Matsumoto c2660b8111 Fix missing MRB_API prefix for functions below; clse #4267
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()
2019-03-26 10:23:52 +09:00
Yukihiro "Matz" Matsumoto 698f5f707c Removed to_ary conversion method. 2018-11-19 12:08:28 +09:00
Tomasz Dąbrowski 7507d46992 fix: src\array.c(86): warning C4244: '=': conversion from 'mrb_int' to 'uint32_t', possible loss of data 2017-09-27 22:22:04 +02:00
Yukihiro "Matz" Matsumoto 8fbc4bef55 Reduce signed/unsigned comparison warnings; ref #3785 2017-08-18 22:54:59 +09:00
Miura Hideki 75ec86ed00 Improve Array structure 2017-08-18 20:12:00 +09:00
Yukihiro "Matz" Matsumoto ef0b239704 Remove unnecessary inline function ary_elt.
And the function does not conform the naming convention anyway.
2017-08-11 12:57:37 +09:00
Yukihiro "Matz" Matsumoto 67e2dddb82 Remove mrb_ary_len function. Use RARRAY_LEN instead. 2017-08-11 12:52:36 +09:00
Yukihiro "Matz" Matsumoto 8f6b2121d9 Update document comment of array C API functions. 2017-08-11 12:51:45 +09:00
Yukihiro "Matz" Matsumoto ae04005092 The type of ARY_EMBED_LEN should be mrb_int. 2017-08-11 12:09:37 +09:00
Yukihiro "Matz" Matsumoto f26d00d9e8 Embed small size array elements in the heap.
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.
2017-07-27 16:13:06 +09:00
Herwin Weststrate d20c56c7fa Documented most methods in mruby/array.h 2016-11-17 11:41:49 +01:00
Herwin Weststrate c043dc631e Typo fix: poped => popped 2016-11-17 11:05:27 +01:00
Yukihiro "Matz" Matsumoto 739dad6e87 Fixed a memory problem in Array#to_h
Reported from Alex Snaps via Mathieu Leduc-Hamel,
both from shopify.com.  Thank you!
2016-11-16 01:29:04 +09:00
Yukihiro "Matz" Matsumoto 065966dae4 common.h are supposed to be included from other header, so call it with quotes; ref #3032 2015-11-28 00:10:38 +09:00
Yukihiro "Matz" Matsumoto 5c405dea3d include changed from by quotes ("") to by brackets (<>); close #3032 2015-11-27 17:48:23 +09:00
Seba Gamboa ef73ec560e array header cleanup 2015-10-08 13:33:38 -03:00
Seba Gamboa a0fe0c40b1 Remove old doxygen tags 2015-10-08 12:29:10 -03:00
Seba Gamboa 4c8205db1f Merge descriptions from doc/api/mruby/array.h.md 2015-09-21 15:13:43 -03:00
Seba Gamboa 40bf7bde78 Sorting documentation grouping 2015-09-21 01:48:42 -03:00
Seba Gamboa c127614638 Setting up doxygen groups 2015-09-20 21:14:07 -03:00
Yukihiro "Matz" Matsumoto 48c5321dca constify pointer from RARRAY_PTR to detect potential write barrier bugs.
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.
2014-09-12 12:42:39 +09:00
Jun Hiroe 3569723ab3 Refactor obj_free() in gc.c 2014-08-05 23:16:01 +09:00
Yukihiro "Matz" Matsumoto 206f89e209 add MRB_API modifiers to mruby API functions 2014-08-04 00:47:08 +09:00
take_cheeze 13d9631e21 Add new API mrb_ary_resize(mruby implementation of rb_ary_resize). 2014-07-06 22:23:29 +09:00