Commit Graph

33 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 8956c5abb5 mruby.h: include mruby/presym.h for all source files
Since presym is now mandatory, mruby.h includes presym.h so that
MRB_SYM() macros are available everywhere without explicit include.
Remove redundant #include <mruby/presym.h> from all source files.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-09 16:50:58 +09:00
Yukihiro "Matz" Matsumoto 07b803e28a docs: replace xml-style markup with markdown in comments
Replace XML-style markup tags in comments with markdown equivalents:
- <code>...</code> to `...` (inline code)
- <tt>...</tt> to `...` (teletype/monospace)
- <i>...</i> to *...* (italics/emphasis)
- +...+ to `...` (parameter/variable references)

Updated 80+ files across core source, headers, mrbgems, and libraries
to use consistent markdown formatting in documentation comments.
Handled edge cases including special characters like <=> operators.

Co-authored-by: Atlassian Rovo Dev
2025-08-14 10:52:49 +09:00
Yukihiro "Matz" Matsumoto 2907fdad06 mruby-data: add comprehensive call-seq documentation for missing methods
Added complete call-seq documentation for 4 missing public methods in the
data gem, improving documentation coverage from 46% to 77%.

Documentation added:
- Data.members: Returns array of member symbols for the class
- Data.define: Creates new data instances with positional or keyword arguments
- Data#initialize: Initializes data structure with hash values
- Data#initialize_copy: Copies data structure for dup/clone operations

Each method now includes:
- Clear method signatures with parameter and return types
- Detailed descriptions of data structure behavior
- Practical examples showing usage patterns
- Notes about member access and initialization
- Cross-references between class and instance methods

Co-authored-by: Atlassian Rovo Dev
2025-07-17 07:40:38 +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 085adaf408 mruby-date: make Data#initialize_copy private 2025-06-16 12:43:34 +09:00
Yukihiro "Matz" Matsumoto acf3656e49 mruby-data: add README.md
The document is written by Google Jules.
2025-06-09 11:01:05 +09:00
dearblue e476d9a344 Need to restore the GC arena after some function calls
When calling `mrb_equal()` or `mrb_funcall()` family functions, the GC arena should be restored if the loop is repeated by a non-immediate return value.

In my opinion, restoring the GC arena is unnecessary when a non-immediate (true) value causes the function to return (e.g. the `mrb_ary_index_m()` function).

The patch does not take into account the case of recursive calls and may be incomplete.
2024-09-03 21:29:06 +09:00
Yukihiro "Matz" Matsumoto 8bd66a9358 mruby-data: use presym for initialization 2024-06-14 01:59:10 +09:00
Yukihiro "Matz" Matsumoto 1e61a875ed mruby-data: adjust local variable declarations 2024-05-05 18:56:20 +09:00
dearblue 2a1ea7d605 Inherit MRB_FL_UNDEF_ALLOCATE in subclasses
If `Class#allocate` is prohibited, subclasses should also be implicitly prohibited.

```ruby
p Class.new(Struct).allocate.class
# => #<Class:0x82362ac00>                                             by #6122
# => allocator undefined for #<Class:0x000000083a983220> (TypeError)  by Ruby 3.2
```

Added `MRB_DEFINE_ALLOCATOR()` to allow subclasses to use `Class#allocate`.

Supplement to #6122.
2023-12-23 21:01:42 +09:00
dearblue 8ecfacefca Prohibit Class#allocate in a different way
The method introduced by #5979 causes a fault by swapping classes.

```console
% bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
zsh: segmentation fault (core dumped)  bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
```

After applying this patch, a `TypeError` exception will be raised.

```console
% bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
trace (most recent call last):
        [1] -e:1
-e:1:in method: allocation failure of Proc (TypeError)
```

However, if the `mrb_vtype` is the same object, the same care must still be taken as before.

```console
% bin/mruby -e 'Method = Binding; p method(:puts).eval("12345")'
trace (most recent call last):
        [1] -e:1
-e:1:in eval: wrong argument type nil (expected Proc) (TypeError)
```
2023-12-22 21:59:34 +09:00
Yukihiro "Matz" Matsumoto 1578f4bb99 mruby-data/data.c: use direct array access
Unless we need boundary check, we don't need to use mrb_ary_ref()
2023-09-05 23:29:23 +09:00
Yukihiro "Matz" Matsumoto bbd4edc607 mruby-data/data.c (mrb_data_ref): remove code duplication 2023-07-29 08:42:25 +09:00
Yukihiro "Matz" Matsumoto 8d2f9b3d12 mruby-data/data.c: skip inefficient env for first some accessors 2023-07-28 23:45:25 +09:00
Yukihiro "Matz" Matsumoto 2b3ecef66c mruby-data/data.c: use mrb_ary_ref instead of direct memory access
Avoid out-of-bound memory access when actual data object size is smaller
than the number of data members.
2023-05-25 09:05:03 +09:00
Yukihiro "Matz" Matsumoto 9bc9ff771d mruby-data/data.c (mrb_data_s_def): simplify the code 2023-05-25 09:05:03 +09:00
Yukihiro "Matz" Matsumoto 05f4831751 mruby-data/data.c (mrb_data_s_def): add member duplication check 2023-05-25 09:05:03 +09:00
Yukihiro "Matz" Matsumoto eeab289f87 mruby-data/data.c (mrb_data_ref): avoid out-of-bound access 2023-05-25 09:05:02 +09:00
Yukihiro "Matz" Matsumoto de69190df5 mruby-struct/struct.c: need to copy the argument array
Just in case for stack reallocations.
2023-05-25 09:05:02 +09:00
Yukihiro "Matz" Matsumoto 8e579e6552 mruby-data/data.c (mrb_data_ref): check if reader has no argument 2023-05-24 22:45:35 +09:00
dearblue d3128ce58a Allow Class#allocate to be prohibited
Calling `Class#allocate` with `UnboundMethod#bind_call` usually succeeds without problems.
If this behavior does not make us happy, we can now prohibit it with `MRB_SET_INSTANCE_TT(klass, MRB_TT_UNDEF)`.

At the same time, it applies to the `Binding`, `Complex`, `Data`, `Float`, `Integer`, `Method`, `Rational` and `UnboundMethod` classes.
2023-04-09 21:14:07 +09:00
Yukihiro "Matz" Matsumoto 33320b08bb mruby-data: fix uninitialized variable error 2023-03-13 08:09:26 +09:00
Yukihiro "Matz" Matsumoto 927a9df453 mruby-data/data.c: allow empty Data 2023-03-10 08:52:06 +09:00
Yukihiro "Matz" Matsumoto 0628669790 mruby-data/data.c (to_s): add class name in string representation 2022-12-31 07:51:09 +09:00
Yukihiro "Matz" Matsumoto 672495555b mruby-data (mrb_data_init_copy): use data_corrupted() for errors 2022-12-07 07:49:19 +09:00
Yukihiro "Matz" Matsumoto 841bf6a270 mruby-data: update a comment (there's no Data.new) [ci skip] 2022-12-05 10:49:40 +09:00
Yukihiro "Matz" Matsumoto 0d261aff6b mruby-data: freeze Data object after initialize 2022-12-04 22:45:36 +09:00
Yukihiro "Matz" Matsumoto 0ef4796dfb mruby-data: improve comment description 2022-12-04 22:45:35 +09:00
Yukihiro "Matz" Matsumoto 951caa8f42 mruby-data: rename some internal functions and a macro 2022-12-04 22:45:35 +09:00
Yukihiro "Matz" Matsumoto 5f3aed7413 mruby-data (mrb_data_new): Data#new to accept keyword arguments 2022-12-01 15:38:06 +09:00
Yukihiro "Matz" Matsumoto a40fdfde5c mruby-data: cosmetic changes regarding for loop variables 2022-11-30 21:51:52 +09:00
Yukihiro "Matz" Matsumoto 138adbe282 mruby-data (mrb_data_initialize): update argument error conditions
- raise ArgumentError if arguments size differs from data size.
  Previously it accepted smaller argument size.

- the message is updated to "wrong number of arguments". It's not
  "struct" any longer.
2022-11-30 21:47:31 +09:00
Yukihiro "Matz" Matsumoto fce2c5131f mruby-data: new gem for Data class introduced in Ruby 3.2 2022-11-29 15:58:05 +09:00