dearblue
bf2db1ed2b
Check mrb_bigint_p() before mrb_integer()
2024-01-21 10:59:06 +09:00
dearblue
772f13520c
Fixed buffer overflow in mrb_memsearch()
2024-01-20 09:44:47 +09:00
Yukihiro "Matz" Matsumoto
f13101124c
string.c: add cast to remove warnings
2024-01-19 18:24:34 +09:00
Yukihiro "Matz" Matsumoto
69cf074778
string.c (mrb_memsearch): move simple search from mrb_memsearch_qs()
2024-01-19 15:21:43 +09:00
Yukihiro "Matz" Matsumoto
57fd0edaa7
mruby.h: rename ASCII flag to SINGLE_BYTE
...
This flag means all the characters in the string can be represented by a
single byte, i.e., the string does not contain any multi-byte character.
Those characters are likely ASCII characters, but may be a part of broken
UTF-8 sequence, so the term 'ASCII' is not sufficient.
2024-01-18 22:50:39 +09:00
Yukihiro "Matz" Matsumoto
fb8bc1954b
string.c: improve performance of chars2bytes/bytes2chars; ref #6143
2024-01-11 18:23:50 +09:00
Yukihiro "Matz" Matsumoto
f646228dbe
string.c (str_index_str_by_char): simplify using str_index_str()
...
Instead of its own version of quick search, now we use str_index_str()
and adjust character position. This change makes searching 4 times
faster in some cases; ref #6143
2024-01-11 12:23:06 +09:00
Yukihiro "Matz" Matsumoto
e42f3b36f9
string.c (chars2bytes): simplify the condition to detect break
2024-01-11 11:49:49 +09:00
Yukihiro "Matz" Matsumoto
787439455c
string.c: remove the macro BYTES_ALIGN_CHECK which is no longer used
2024-01-10 17:31:04 +09:00
Yukihiro "Matz" Matsumoto
c2f148e15d
string.c (mrb_memsearch_qs): reduce the scope of local variables
2024-01-10 16:21:39 +09:00
Yukihiro "Matz" Matsumoto
31f2d93657
string.c (bytes2chars): skip calling mrb_utf8len() if possible
...
If (ch < 0x80) the length of the character (in bytes) should be 1, so we
don't have to call mrb_utf8len().
2024-01-10 15:36:07 +09:00
Yukihiro "Matz" Matsumoto
4c859e754d
string.c (bytes2chars): skip scanning if the string is ASCII only
2024-01-10 14:40:39 +09:00
Yukihiro "Matz" Matsumoto
df0a5e838d
string.c (chars2bytes): use early return
2024-01-10 12:41:28 +09:00
Yukihiro "Matz" Matsumoto
e39e4ea26d
string.c (chars2bytes): small refactoring
2024-01-10 11:09:47 +09:00
Yukihiro "Matz" Matsumoto
1d243bc58b
string.c (bytes2chars): takes a string object instead of char*
2024-01-10 10:53:26 +09:00
Yukihiro "Matz" Matsumoto
59a1d74937
string.c: inline str_range_to_bytes
2024-01-09 18:22:38 +09:00
Yukihiro "Matz" Matsumoto
9135f0991b
string.c: avoid RSTRING_CHAR_LEN() if possible
...
Current code scan the string twice (once from RSTRING_CHAR_LEN, and once
from chars2bytes), but those scans are not necessary. Just point the end
of the string.
2024-01-09 11:44:12 +09:00
Yukihiro "Matz" Matsumoto
f3ebef1172
mruby-string (chars2bytes): reduce the scope of local variables
2024-01-09 11:00:44 +09:00
Yukihiro "Matz" Matsumoto
f1d01a6107
string.c (mrb_utf8len): should return 1 for invalid chars; ref #6143
2024-01-09 10:39:03 +09:00
Yukihiro "Matz" Matsumoto
64a4bf0e28
string.c: avoid infinite loop; fix #6143
...
`mrb_utf8len` returns 0 for invalid characters.
2024-01-09 10:37:52 +09:00
Yukihiro "Matz" Matsumoto
a5e83075d4
string.c: reduce the scope of a local variable
2024-01-09 08:22:26 +09:00
Yukihiro "Matz" Matsumoto
be3b93ecb9
array.c (ary_expand_capa): rename a conflicting local variable
2024-01-06 14:33:50 +09:00
Yukihiro "Matz" Matsumoto
d47f1b4df3
array.c (ary_expand_capa): remove unnecessary condition check
2024-01-06 14:32:54 +09:00
dearblue
519a2cbd59
Fixed when combined mrb_fiber_resume() and Fiber#transfer
...
For example, the following code was crashing.
```c
#include <mruby.h>
#include <mruby/compile.h>
#include <mruby/proc.h>
int
main(int argc, char *argv[])
{
mrb_state *mrb = mrb_open();
mrb_value fiber = mrb_load_string(mrb, "Fiber.new { Fiber.new { 12345.6789 }.transfer }");
mrb_value res = mrb_fiber_resume(mrb, fiber, 0, NULL);
mrb_p(mrb, res);
mrb_close(mrb);
return 0;
}
```
2024-01-02 21:34:44 +09:00
Yukihiro "Matz" Matsumoto
a8b82bfae5
Merge pull request #6128 from dearblue/fiber-end
...
Integrates the sequence when a fiber is terminated by `OP_RETURN`
2023-12-27 22:24:01 +09:00
Yukihiro "Matz" Matsumoto
e51c20888b
Merge pull request #6127 from dearblue/catch_handler_find
...
Changed parameters for `catch_handler_find()`
2023-12-27 22:22:12 +09:00
Yukihiro "Matz" Matsumoto
1ac4148020
Merge pull request #6126 from dearblue/block-return
...
Fixed return value of `OP_RETURN_BLK` called directly under C function
2023-12-27 22:19:36 +09:00
Yukihiro "Matz" Matsumoto
074374e28d
Merge pull request #6125 from dearblue/cross-c
...
Allow `OP_RETURN_BLK` to cross C boundaries
2023-12-27 22:18:06 +09:00
dearblue
dba1dcdd25
Integrates the sequence when a fiber is terminated by OP_RETURN
...
In the `ensure` block while executing `fiber.transfer`, keep `fiber->cxt->prev` to be `NULL`.
2023-12-24 15:45:15 +09:00
dearblue
dc09000f01
Fixed return value of OP_RETURN_BLK called directly under C function
...
```ruby
def cross; Class.new { return 1 }; end; p cross'
# => #<Class:0x8245cf170> # without this patch
# => 1 # with this patch
```
2023-12-24 13:56:25 +09:00
dearblue
d41a2612f4
Allow OP_RETURN_BLK to cross C boundaries
...
The restriction was introduced in commit b563bcb7ff to resolve https://github.com/mruby/mruby/issues/3462 .
Subsequently, the `RBreak` object, introduced by mruby 1.3.0, allowed crossing the C boundary.
```ruby
def cross; Class.new { proc { return }.call }; end; cross
# => unexpected return (LocalJumpError) # without this patch
# => nothing raised # with this patch
```
2023-12-24 13:56:25 +09:00
dearblue
6a9671eac7
Changed parameters for catch_handler_find()
...
- Removed `mrb` and `ci` parameters.
- Added `irep` parameter.
The caller must guarantee that `irep->clen > 0`.
2023-12-23 23:02:48 +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
fa75865a33
Merge pull request #6121 from dearblue/separate-breaks
...
Separate unwinding process for `break` / `return`
2023-12-22 16:12:12 +09:00
Yukihiro "Matz" Matsumoto
97b522d778
src/fmt_fp.c: change condition order for memory safety
2023-12-22 15:35:21 +09:00
Yukihiro "Matz" Matsumoto
34c5d96e86
allof.c: mrb_default_allocf() definition in the separate file
...
So that the user can define their own version of mrb_default_alloc
function to override memory allocation of mruby.
2023-12-21 15:28:04 +09:00
dearblue
859f1b3002
Separate unwinding process for break / return
2023-12-20 21:54:53 +09:00
Yukihiro "Matz" Matsumoto
992bd49344
Merge pull request #6116 from dearblue/send-branch
...
Improve branching in the execution part of the `OP_SEND` block
2023-12-18 12:17:39 +09:00
Yukihiro "Matz" Matsumoto
e8a36235d8
Merge pull request #6115 from dearblue/loop-inclusion
...
Replace `for` and `CHECKPOINT` block comprehensions
2023-12-18 12:16:38 +09:00
dearblue
990e18ad59
Improve branching in the execution part of the OP_SEND block
...
The `MRB_METHOD_CFUNC_P()` macro contains several branches, which will be replaced by simple branches.
2023-12-15 21:46:00 +09:00
dearblue
7144eab350
Replace for and CHECKPOINT block comprehensions
...
I think it will make the eyes less tired for a process flow.
2023-12-15 21:46:00 +09:00
dearblue
e9904ddb2a
Move L_RAISE and L_BREAK blocks to OP_RAISEIF
...
`OP_RAISEIF` should be easier to relate than `OP_RETURN`.
2023-12-15 21:46:00 +09:00
Yukihiro "Matz" Matsumoto
5311d1aa1b
Merge pull request #6106 from dearblue/fiber-limits-ease
...
Ease fiber limitations
2023-12-13 16:10:42 +09:00
Yukihiro "Matz" Matsumoto
ae8dcb82ba
vm.c: CINFO_SKIP should not be called with prev_jmp == NULL
...
We have added assertion to ensure.
2023-12-12 16:49:11 +09:00
dearblue
38c7936c94
Remove unreachable code in OP_R_BREAK
...
Termination of fiber by `break` results in a `LocalJumpError`, so the indicated code will not be executed.
2023-12-11 21:25:08 +09:00
dearblue
73c8330cbd
RBreak remembers the CI location
...
It is now possible to specify return destination directly.
This allows callinfo to distinguish between calls to the same proc object.
At the same time, the `Kernel#catch` method is adjusted.
By removing the previously required double lambda object, the REnv object is no longer created as well.
2023-12-07 21:33:14 +09:00
Yukihiro "Matz" Matsumoto
5a258f0872
Merge pull request #6109 from dearblue/fix-6108
...
Needs `cipop()` before crossing the C boundary
2023-12-06 15:57:16 +09:00
Yukihiro "Matz" Matsumoto
9c2af6aaed
load.c: replace mrbc_ prefix by mrb_ccontext
2023-12-06 15:29:02 +09:00
dearblue
ca9e8d91e4
Needs cipop() before crossing the C boundary
...
fix #6108
2023-12-05 22:03:38 +09:00