| Age | Commit message (Collapse) | Author |
|
Commit d0f60182af9114f6840d993d74f492e483302805 introduced an exception as a limitation of mruby.
Subsequent CRuby-2.7 has changed its behavior to raise an exception.
ref: https://github.com/ruby/ruby/commit/55b7ba368696033f2e89b77cbcd4a05dec97b139
|
|
|
|
So that `mruby -e 'a'` does not print backtrace history, i.e.
```
% mruby -e 'a'
-e:1: undefined method 'a' (NoMethodError)
```
Instead of
```
% mruby -e 'a'
trace (most recent call last):
[1] -e:1
-e:1: undefined method 'a' (NoMethodError)
```
|
|
Consistent number conversion function names:
* `mrb_value` to immediate (C) value
* `mrb_int()` -> `mrb_as_int()`
* `mrb_to_flo()` -> `mrb_as_float()`
* `mrb_value` to `mrb_value` (converted)
* `mrb_to_int()'
* `mrb_Integer()` - removed
* `mrb_Float()` -> `mrb_to_float`
Consistent function name (avoid `_flo` suffix):
* `mrb_div_flo()` -> `mrb_div_float`
|
|
Replaces the magic number `7` except in `src/gc.c`.
|
|
|
|
- `_raw` does not describe the nature of the function
- the function protect errors during C function execution
|
|
The purpose is two-fold:
1. to be able to specify a pointer directly when user data is used
When using `mrb_protect()`, it is necessary to allocate objects by `mrb_obj_cptr()` function when using user data.
Adding `mrb_protect_raw()` will make it simpler to reimplement `mrbgems/mruby-error`.
2. to correctly unwind callinfo when an exception is raised from a C function defined as a method (the main topic)
If a method call is made directly under `mrb_protect()` and a C function is called, control is returned from `mrb_protect()` if an exception occurs there.
In this case, callinfo is not restored, so it is out of sync.
Moreover, returning to mruby VM (`mrb_vm_exec()` function) in this state will indicate `ci->pc` of C function which is equal to `NULL`, and subsequent `JUMP` will cause `SIGSEGV`.
Following is an example that actually causes `SIGSEGV`:
- `crash.c`
```c
#include <mruby.h>
#include <mruby/compile.h>
#include <mruby/error.h>
static mrb_value
level1_body(mrb_state *mrb, mrb_value self)
{
return mrb_funcall(mrb, self, "level2", 0);
}
static mrb_value
level1(mrb_state *mrb, mrb_value self)
{
return mrb_protect(mrb, level1_body, self, NULL);
}
static mrb_value
level2(mrb_state *mrb, mrb_value self)
{
mrb_raise(mrb, E_RUNTIME_ERROR, "error!");
return mrb_nil_value();
}
int
main(int argc, char *argv[])
{
mrb_state *mrb = mrb_open();
mrb_define_method(mrb, mrb->object_class, "level1", level1, MRB_ARGS_NONE());
mrb_define_method(mrb, mrb->object_class, "level2", level2, MRB_ARGS_NONE());
mrb_p(mrb, mrb_load_string(mrb, "p level1"));
mrb_close(mrb);
return 0;
}
```
- compile & run
```console
% `bin/mruby-config --cc --cflags --ldflags` crash.c `bin/mruby-config --libs`
% ./a.out
zsh: segmentation fault (core dumped) ./a.out
```
After applying this patch, it will print exception object and exit normally.
The `mrb_protect()`, `mrb_ensure()` and `mrb_rescue_exceptions()` in `mrbgems/mruby-error` have been rewritten using `mrb_protect_raw()`.
|
|
|
|
Use `mrb_exec_irep()`. If possible, re-entry into the VM will be suppressed.
Note that due to the effect of being a tail-call, the backtrace of `Method#call` will be lost, and it will look as if the target method was called directly.
This change fixes the problem of infinite loops when redefining methods that make block calls using `mruby-method`.
```console
% bin/mruby -e 'mm = method(:proc); define_method(:proc, ->(*a, &b) { mm.call(*a, &b) }); p proc { 1 }'
trace (most recent call last):
[257] -e:1
[256] -e:1:in proc
[255] -e:1:in proc
...SNIP...
[1] -e:1:in proc
-e:1:in proc: stack level too deep (SystemStackError)
```
|
|
Change the old `mrb_exec_irep()` as-is to static `mrb_exec_irep_vm()`.
Extract the VM entry part from the old `exec_irep()` in `mruby-eval/src/eval.c` and make it the core of the new `mrb_exec_irep()`.
|
|
- (old) `undefined method 'foo'`
- (new) `no superclass method 'foo'`
|
|
|
|
|
|
|
|
Fix `SIGSEGV` with mruby-method + mruby-catch
|
|
- `mrb_num_div_int(mrb,x,y)` -> `mrb_div_int(mrb,x,y)`
- `mrb_num_div_flo(mrb,x,y)` -> `mrb_div_flo(x,y)`
They are internal function not supposed to be used outside of the core.
|
|
Previously, the following code would cause a `SIGSEGV`.
```ruby
mm = method(:throw)
define_method(:throw, ->(*args) { mm.call(*args) })
catch { |tag| throw tag }
```
I think the reason is in the `mrb_yield_with_class()` function:
- Even if a C function is called, `CI_ACC_SKIP` is used
- `cipop()` is not done if globally jumping from a C function
|
|
Add new pool value type `IREP_TT_BIGINT` and generate integer overflow
error in the VM. In the future, `mruby` will support `Bignum` for
integers bigger than `mrb_int` (probably using `mpz`).
|
|
- Added to `mruby-binding-core`
- `Binding#local_variable_defined?`
- `Binding#local_variable_get`
- `Binding#local_variable_set`
- `Binding#local_variables`
- `Binding#receiver`
- `Binding#source_location`
- `Binding#inspect`
- Added to `mruby-proc-binding`
- `Proc#binding`
The reason for separating `Proc#binding` is that core-mrbgems has a method that returns a closure object to minimize possible problems with being able to manipulate internal variables.
By separating it as different mrbgem, each user can judge this problem and incorporate it arbitrarily.
|
|
|
|
|
|
We have introduced following new instructions.
* `OP_LAMBDA16`
* `OP_BLOCK16`
* `OP_METHOD16`
* `OP_EXEC16`
Each instruction uses 16 bits operand for `reps` index. Since new
instructions are added, `mruby/c` VM should be updated.
Due to new instructions, dump format compatibility is lost, we have
increased `RITE_BINARY_MAJOR_VER`.
In addition, we have decreased the size of `refcnt` in `mrb_irep` from
`uint32_t` to `uint16_t`, which is reasonably big enough.
|
|
Remove unnecessary `ci0` variables; ref #5272
|
|
|
|
The following macros will be removed:
- `ENSURE_STACK_INIT_SIZE`
- `RESCUE_STACK_INIT_SIZE`
- `MRB_ECALL_DEPTH_MAX`
|
|
|
|
|
|
This reverts commit dc51d89ac22acc60b9bfeed87115863565b74085.
|
|
|
|
Instead of including `mruby/presym.h` everywhere, we provided the
fallback `mruby/presym.inc` under `include/mruby` directory, and specify
`-I<build-dir>/include` before `-I<top-dir>/include` in `presym.rake`.
So even when someone drops `-I<build-dir>/include` in compiler options,
it just compiles without failure.
|
|
https://github.com/shuujii/mruby into shuujii-avoid-including-presym.inc-in-existing-header-files
|
|
When I `#call` the "proc" object created by the `mrb_proc_new_cfunc()` function from Ruby space, the return value did not go into the correct stack position.
This can destroy the calling variable.
This issue is now caused by #5272. sorry.
|
|
Addressed an issue where existing programs linking `libmruby.a` could only
be built by adding `<build-dir>/include` to compiler's include path.
|
|
This enhances self-containment.
- Changed the `mrb_callinfo::pc` field to point to itself.
Previously it indicated the return destination of the previous call level.
`mrb_callinfo::pc` will now hold the address to its own `proc->body.irep->iseq`.
- Removed `mrb_callinfo::err` field.
This is because `mrb_callinfo::pc - 1` is semantically the same as the previous `err`.
- The `pc0` and `pc_save` variables in `mrb_vm_exec()` are no longer needed and have been deleted.
- It removes the argument because `cipush()` doesn't need to save the previous `pc`.
|
|
This enhances self-containment.
Previously `mrb_context::stack` had the current call level stack, but now it owns it.
The `mrb_context::stack` field, which is no longer needed, will be removed.
|
|
If there is `env`, `env->c` means `target_class`.
|
|
But you still cannot cross C function boundary.
|
|
Negative integer `>-65535` had wrong value, e,g, `p(-40550)` printed
`4294926746` since Nov. 2020, sigh.
|
|
|
|
|
|
|
|
Follow commit 7150c6753933f12a2ba63769fb7b3a44cfcddd3d .
|
|
Jump target address is `operand (16bit)` + `address of next instruction`.
In addition, `ilen` was made `uint32_t` so that `iseq` length limitation
of 65536 is removed. Only jump target address should be within signed
16bit (-32768 .. 32767).
|
|
| 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.
|
|
|
|
|
|
### ASAN report (`MRB_INT32`)
```console
$ bin/mruby -ve '-0x40000000'
mruby 3.0.0preview (2020-10-16)
00001 NODE_SCOPE:
00001 NODE_BEGIN:
00001 NODE_NEGATE:
00001 NODE_INT 40000000 base 16
irep 0x6070000001e0 nregs=2 nlocals=1 pools=0 syms=0 reps=0 iseq=9
file: -e
/mruby/src/codedump.c:173:49: runtime error: left shift of 49152 by 16 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /mruby/src/codedump.c:173:49 in
1 000 OP_LOADI32 R1 -1073741824
1 006 OP_RETURN R1
1 008 OP_STOP
/mruby/src/vm.c:1138:7: runtime error: left shift of 49152 by 16 places cannot be represented in type 'mrb_int' (aka 'int')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /mruby/src/vm.c:1138:7 in
```
|
|
|
|
To be also able to build mruby without presym in the future. However,
`MRB_QSYM` has been removed and changed as follows:
### Example
| Type | Symbol | Previous Style | New Style |
|---------------------------|--------|------------------|----------------|
| Operator | & | MRB_QSYM(and) | MRB_OPSYM(and) |
| Class Variable | @@foo | MRB_QSYM(00_foo) | MRB_CVSYM(foo) |
| Instance Variable | @foo | MRB_QSYM(0_foo) | MRB_IVSYM(foo) |
| Method with Bang | foo! | MRB_QSYM(foo_b) | MRB_SYM_B(foo) |
| Method with Question mark | foo? | MRB_QSYM(foo_p) | MRB_SYM_Q(foo) |
| Mmethod with Equal | foo= | MRB_QSYM(foo_e) | MRB_SYM_E(foo) |
This change makes it possible to define, for example, `MRB_IVSYM(foo)` as
`mrb_intern_lit(mrb, "@" "foo")`, which is useful if we support building
without presym in the future.
|