summaryrefslogtreecommitdiffhomepage
path: root/src
AgeCommit message (Collapse)Author
2021-04-19Merge pull request #5415 from dearblue/unwind-mrb_protectYukihiro "Matz" Matsumoto
Introducing the `mrb_protect_raw()` API function
2021-04-19Introducing the `mrb_protect_raw()` API functiondearblue
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()`.
2021-04-19backtrace.c: remove `MRB_API` from internal functions.Yukihiro "Matz" Matsumoto
- `mrb_exc_backtrace` to implement `Exception#backtrace` - `mrb_get_backtrace` to implement `#caller`
2021-04-19backtrace.c: small refactoring in `mrb_exc_backtrace()`; ref #5394Yukihiro "Matz" Matsumoto
- add comment for unpacking - avoid saving the symbol in a local variable
2021-04-19backtrace.c: pedantic check for empty backtrace; ref #5394Yukihiro "Matz" Matsumoto
2021-04-19backtrace.c: should skip first (innermost) frame w/out position; #5394Yukihiro "Matz" Matsumoto
Otherwise we suffer `(unknown):0:` errors.
2021-04-16feat(CI): add the GitHub Super LinterJohn Bampton
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
2021-04-13Fix incorrect prototype on declaration of mrb_protect_atexitRyan Lopopolo
`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.
2021-04-10Rename some internal functions; ref #5401Yukihiro "Matz" Matsumoto
2021-04-09Merge pull request #5400 from jbampton/fix-spellingYukihiro "Matz" Matsumoto
chore: fix spelling
2021-04-09Merge pull request #5401 from dearblue/mcallYukihiro "Matz" Matsumoto
Reorganize `mcall()` in `mruby-method`
2021-04-04Making a proc object static for a method with static irepdearblue
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.
2021-04-03Reorganize `mcall()` in `mruby-method`.dearblue
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) ```
2021-04-03Make `mrb_exec_irep()` allow non-VM to enter.dearblue
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()`.
2021-04-03chore: fix spellingJohn Bampton
2021-04-03Fix build failures with `enable_debug` and `enable_cxx_abi`dearblue
Under C++, there is no implicit conversion from `int` to `enum`, which caused a compilation error.
2021-04-01vm.c: change the default error message for undefined `super` method.Yukihiro "Matz" Matsumoto
- (old) `undefined method 'foo'` - (new) `no superclass method 'foo'`
2021-03-31backtrace.c: change `missing-lineno` to `0` for cosmetic reason; #5394Yukihiro "Matz" Matsumoto
2021-03-31Merge pull request #5394 from fundamental/partial-backtraceYukihiro "Matz" Matsumoto
Add support for partial backtraces
2021-03-31vm.c: resolve `int` and `mrb_int` mixture.Yukihiro "Matz" Matsumoto
2021-03-30mrbc: Dump debug info with -g optionfundamental
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.
2021-03-30Add support for partial backtracesfundamental
When debug information is omitted within ireps, show that a stack frame existed rather than silently hiding it.
2021-03-29src/vm.c: calling C function may raise global jumps; fix #5391Yukihiro "Matz" Matsumoto
2021-03-29Revert "Fix `SIGSEGV` with mruby-method + mruby-catch"revert-5391-throwYukihiro "Matz" Matsumoto
2021-03-29Merge pull request #5391 from dearblue/throwYukihiro "Matz" Matsumoto
Fix `SIGSEGV` with mruby-method + mruby-catch
2021-03-28numeric.c: function renaming.Yukihiro "Matz" Matsumoto
- `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.
2021-03-27Fix `SIGSEGV` with mruby-method + mruby-catchdearblue
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
2021-03-19complex.c: overhaul complex operators.Yukihiro "Matz" Matsumoto
- 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
2021-03-19rational.c: overhaul rational operators.Yukihiro "Matz" Matsumoto
- 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
2021-03-19numeric.c: avoid integer overflow; close #5384Yukihiro "Matz" Matsumoto
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.
2021-03-19`Float#divmod` with zero should cause `ZeroDivisionError`; #5384Yukihiro "Matz" Matsumoto
2021-03-18`Float::NAN/0` should be `Float::NAN`; ref a0b3378b3KOBAYASHI Shuji
#### 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 ```
2021-03-18numeric.c: float zero division should be infinity with sign kept; fix #5382Yukihiro "Matz" Matsumoto
2021-03-17hash.c: `Hash#shift` to return `nil` when a hash is empty.Yukihiro "Matz" Matsumoto
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]
2021-03-17range.c: fixed a begin-less ranges issue.Yukihiro "Matz" Matsumoto
2021-03-12codegen.c: fixed a typo.Yukihiro "Matz" Matsumoto
2021-03-12codegen.c: no integer overflow error in `codegen`; close #5376Yukihiro "Matz" Matsumoto
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`).
2021-03-09Merge pull request #5375 from artichoke/mrb_cmp-presym-op-maroYukihiro "Matz" Matsumoto
bug(presym): Fix mrb_cmp declaration of <=> symbol for funcall
2021-03-07bug(presym): Fix mrb_cmp declaration of <=> symbol for funcallRyan Lopopolo
2021-03-08ISO C99 doesn't support unnamed unions; fix #5354Yukihiro "Matz" Matsumoto
2021-03-05Fix load 64-bit integer from mrb format; fix #5369KOBAYASHI Shuji
2021-03-01dump.c: remove operator_table if `MRB_NO_STDIO` is defined.Yukihiro "Matz" Matsumoto
2021-02-28Remove periods from error messages according to the convention.Yukihiro "Matz" Matsumoto
2021-02-27state.c: remove `stdint.h` inclusion.Yukihiro "Matz" Matsumoto
Fixes C++03 compilation.
2021-02-26state.c: check irep reference count overflow.Yukihiro "Matz" Matsumoto
2021-02-22Added other methods for `Binding`dearblue
- 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.
2021-02-22Adjustment of the current HEAD and bindings, and separationdearblue
Make changes to make `Binding` work. At the same time, it separates `Binding#eval`, which depends on `mruby-eval`, from `mruby-binding-core`.
2021-02-22print.c: fix a compilation errors with `MRB_NO_STDIO`; fix #5361Yukihiro "Matz" Matsumoto
2021-02-19Check `MRB_TT_*` before object allocation; ref #5352Yukihiro "Matz" Matsumoto
2021-02-18Merge pull request #5352 from ↵Yukihiro "Matz" Matsumoto
shuujii/fix-type-tag-that-set-to-NilClass-and-FalseClass Fix type tag that set to `NilClass` and `FalseClass`