| Age | Commit message (Collapse) | Author |
|
Introducing the `mrb_protect_raw()` API function
|
|
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()`.
|
|
- `mrb_exc_backtrace` to implement `Exception#backtrace`
- `mrb_get_backtrace` to implement `#caller`
|
|
- add comment for unpacking
- avoid saving the symbol in a local variable
|
|
|
|
Otherwise we suffer `(unknown):0:` errors.
|
|
The GitHub Super Linter is a more robust and better supported
tool than the current GitHub Actions we are using.
Running these checks:
ERROR_ON_MISSING_EXEC_BIT: true
VALIDATE_BASH: true
VALIDATE_BASH_EXEC: true
VALIDATE_EDITORCONFIG: true
VALIDATE_MARKDOWN: true
VALIDATE_SHELL_SHFMT: true
VALIDATE_YAML: true
https://github.com/marketplace/actions/super-linter
https://github.com/github/super-linter
Added the GitHub Super Linter badge to the README.
Also updated the pre-commit framework and added
more documentation on pre-commit.
Added one more pre-commit check: check-executables-have-shebangs
Added one extra check for merge conflicts to our
GitHub Actions.
EditorConfig and Markdown linting.
Minor grammar and spelling fixes.
Update linter.yml
|
|
`state.c` makes a prototype declaration for the private
`mrb_protect_atexit` which is defined in `error.c`. `error.c` defines
this function with a void return type, but `state.c` defines the
prototype with an `int` return type.
This mismatch prevents mruby from compiling on stricter compilers like
emscripten.
|
|
|
|
chore: fix spelling
|
|
Reorganize `mcall()` in `mruby-method`
|
|
The following methods will be made static.
- `Class#new`
- `Proc#call`
- `Kernel#catch`
Previously, static const RProc could not be registered as a method, but this has been changed to allow it.
|
|
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()`.
|
|
|
|
Under C++, there is no implicit conversion from `int` to `enum`, which caused a compilation error.
|
|
- (old) `undefined method 'foo'`
- (new) `no superclass method 'foo'`
|
|
|
|
Add support for partial backtraces
|
|
|
|
Adds debug source information (line/file) when mrbc uses -g.
This commit results in usable backtraces for all gems when build_config
is setup with enable_debug.
|
|
When debug information is omitted within ireps, show that a stack
frame existed rather than silently hiding it.
|
|
|
|
|
|
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
|
|
- define `MRB_TT_COMPLEX`
- change object structure (`struct RComplex`)
- add memory management for `MRB_TT_COMPLEX`
- avoid operator overloading as much as possible
- as a result, performance improved a log
- should work with and without `Rational` defined
|
|
- define `MRB_TT_RATIONAL`
- change object structure (`struct RRational`)
- add memory management for `MRB_TT_RATIONAL`
- avoid operator overloading as much as possible
- implement division overloading in C
- as a result, performance improved a lot
|
|
Since `mruby` does not have `Bignum`, `Float#divmod` could overflow, so
it will return `Float` values when the divided value does not fit in
`mrb_int`. This behavior will be changed when `Bignum` is introduced to
`mruby` in the future.
|
|
|
|
#### Before this patch:
```console
$ bin/mruby -e 'p(Float::NAN/0)'
Infinity
```
#### After this patch (same as Ruby):
```console
$ bin/mruby -e 'p(Float::NAN/0)'
NaN
```
|
|
|
|
It used to be return the default value if available, but it should
ignore the default value for behavior consistency. CRuby will adopt
this behavior too in the future. [ruby-bugs:16908]
|
|
|
|
|
|
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`).
|
|
bug(presym): Fix mrb_cmp declaration of <=> symbol for funcall
|
|
|
|
|
|
|
|
|
|
|
|
Fixes C++03 compilation.
|
|
|
|
- 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.
|
|
Make changes to make `Binding` work.
At the same time, it separates `Binding#eval`, which depends on `mruby-eval`, from `mruby-binding-core`.
|
|
|
|
|
|
shuujii/fix-type-tag-that-set-to-NilClass-and-FalseClass
Fix type tag that set to `NilClass` and `FalseClass`
|