Yukihiro "Matz" Matsumoto
24dcd252f8
Merge pull request #5439 from dearblue/opcode.md
...
Enclose the table contents of `opcode.md` as code
2021-05-02 20:41:43 +09:00
Yukihiro "Matz" Matsumoto
4626348e47
array.c: mrb_ary_shift_m should be static.
2021-05-02 20:30:41 +09:00
dearblue
3e5ff7543a
Enclose the table contents of opcode.md as code
2021-05-02 20:06:16 +09:00
Yukihiro "Matz" Matsumoto
14c13bb4d2
symbol.c: remove mrb_sym_static_p() function that no one use.
2021-05-02 17:57:34 +09:00
Yukihiro "Matz" Matsumoto
8f362eaf8a
io.rb,print.rb: puts to expand array arguments.
...
As CRuby behaves.
2021-05-01 00:00:14 +09:00
Yukihiro "Matz" Matsumoto
519dc3d19c
Merge pull request #5432 from shuujii/fix-typo-in-mrbgems-mruby-io-mrblib-io.rb
...
Fix typo in `mrbgems/mruby-io/mrblib/io.rb`; ref cb55e7eca
2021-04-29 11:17:41 +09:00
KOBAYASHI Shuji
a633f0f9f6
Fix typo in mrbgems/mruby-io/mrblib/io.rb; ref cb55e7eca
2021-04-29 09:27:12 +09:00
Yukihiro "Matz" Matsumoto
2ad5d4f53d
string.c: add a new method String#center.
2021-04-28 21:44:19 +09:00
Yukihiro "Matz" Matsumoto
e5e5acefaf
string.{c,rb}: fix type of return values from some methods as Ruby3.0
...
When the receiver is the instance of subclass of `String`.
- `String#each_char`
- `String#each_line`
- `String#partition`
2021-04-28 21:41:01 +09:00
Yukihiro "Matz" Matsumoto
6666b4fa62
doc/opcode.md: stop reversed link syntax check from markdownlint.
2021-04-28 21:37:06 +09:00
Yukihiro "Matz" Matsumoto
cb55e7eca9
io.rb: reimplement IO#each_char.
...
It used to be an alias to `IO#each_byte` but those methods should have
behave differently.
2021-04-28 21:37:05 +09:00
Yukihiro "Matz" Matsumoto
aff3743c12
array.rb: Array#uniq to return always Array.
...
Even called for subclass of `Array`, according to new Ruby3.0 behavior.
Other methods of `Array` behave as Ruby3.0 from the first hand.
2021-04-28 17:45:19 +09:00
Yukihiro "Matz" Matsumoto
9f77232b71
array.c: update Array#shift to take optional argument; close #5428
2021-04-27 16:37:24 +09:00
Yukihiro "Matz" Matsumoto
2e165b9e20
Merge pull request #5425 from dearblue/exc_to_s
...
Fix symbol leak in `exc_to_s()`
2021-04-26 23:13:22 +09:00
Yukihiro "Matz" Matsumoto
f22535045a
mruby.c: specify file names for libraries set by -r; fix #5427
2021-04-26 19:00:49 +09:00
Yukihiro "Matz" Matsumoto
14bd07f831
backtrace.c: skip innermost frame only when the method is in C; #5394
2021-04-26 16:46:44 +09:00
Yukihiro "Matz" Matsumoto
b937463706
Merge pull request #5424 from dearblue/new_iseq
...
Fix annotations for inline iseq of `Class.new` [ci skip]
2021-04-26 14:29:46 +09:00
Yukihiro "Matz" Matsumoto
2ead8a0520
Merge pull request #5423 from dearblue/gc-red
...
Introduce `MRB_GC_RED`
2021-04-26 07:29:08 +09:00
Yukihiro "Matz" Matsumoto
8cd51578fb
build_config/no-float.rb: unify two build configurations; #5421
...
- stop cross building
- add more gems for tests
- add `bintest`
2021-04-26 07:25:21 +09:00
Yukihiro "Matz" Matsumoto
767577efb1
Merge pull request #5422 from dearblue/binding1
...
Avoid ill-advised `goto`
2021-04-25 14:36:17 +09:00
dearblue
c0cd004b21
Fix symbol leak in exc_to_s()
2021-04-25 10:49:33 +09:00
dearblue
8f66dd278b
Fix annotations for inline iseq of Class.new [ci skip]
2021-04-24 21:31:50 +09:00
Yukihiro "Matz" Matsumoto
4d249c28d9
Skip tests that use Float inside; ref #5421
2021-04-24 12:04:08 +09:00
Yukihiro "Matz" Matsumoto
f46b4056f8
numeric.c: remove duplicated definitions; #5421
...
Following functions are defined in `mrblib/numeric.c`:
- `Integer#ceil`
- `Integer#floor`
- `Integer#round`
- `Integer#truncate`
2021-04-24 11:56:50 +09:00
Yukihiro "Matz" Matsumoto
4b4622f711
time.c: fixable_time_t_p is not used with MRB_NO_FLOAT; #5421
2021-04-24 11:38:56 +09:00
Yukihiro "Matz" Matsumoto
237f3339bf
random.c: refactoring; #5421
...
- `Random.rand` with `MRB_NO_FLOAT` behaves as `Random.rand(100)`
- `Random.rand(i)` where `i<0` raises `ArgumentError`
2021-04-24 11:15:53 +09:00
Yukihiro "Matz" Matsumoto
2e49a25740
build_config/nofloat.rb: build configuration with MRB_NO_FLOAT; #5421
2021-04-24 10:54:42 +09:00
dearblue
94c5c8f44c
Introduce MRB_GC_RED
...
Replaces the magic number `7` except in `src/gc.c`.
2021-04-24 10:31:21 +09:00
Yukihiro "Matz" Matsumoto
90a59efbec
numeric.c: fix errors from MRB_NO_FLOAT; close #5421
2021-04-24 10:23:40 +09:00
dearblue
b18fd23cef
Avoid ill-advised goto
...
ref #5362
2021-04-23 22:54:12 +09:00
Yukihiro "Matz" Matsumoto
39dc7b7901
vm.c: fix errors with MRB_NO_FLOAT; fix #5421
2021-04-23 11:28:17 +09:00
Yukihiro "Matz" Matsumoto
dc88a87f9b
time.c: time_t may be unsigned on some platforms.
2021-04-23 07:53:17 +09:00
Yukihiro "Matz" Matsumoto
1a82bab1b0
error.h: rename mrb_protect_raw to mrb_protect_error; #5415
...
- `_raw` does not describe the nature of the function
- the function protect errors during C function execution
2021-04-22 17:01:33 +09:00
Yukihiro "Matz" Matsumoto
91c4ac8d66
numeric.c: update error messages in int_pow; ref #5420
2021-04-21 22:08:07 +09:00
Yukihiro "Matz" Matsumoto
5cf1de5b31
numeric.c: fix int_pow to detect integer overflow; fix #5420
2021-04-21 22:05:52 +09:00
Yukihiro "Matz" Matsumoto
2268405fe6
test/math.rb: 10**30 could cause integer overflow; ref #5420
2021-04-21 22:04:20 +09:00
Yukihiro "Matz" Matsumoto
bf11f87599
Merge pull request #5419 from shuujii/remove-unused-struct-in-include-mruby-variable.h
...
Remove unused struct in `include/mruby/variable.h`
2021-04-20 17:41:26 +09:00
Yukihiro "Matz" Matsumoto
bd66115257
Merge pull request #5418 from shuujii/remove-unused--include-in-complex.c-and-rational.c
...
Remove unused `#include` in `complex.c` and `rational.c`
2021-04-20 17:41:01 +09:00
Yukihiro "Matz" Matsumoto
ca744e77c4
Merge pull request #5417 from shuujii/remove-MRB_API-from-mrb_get_backtrace-definition
...
Remove `MRB_API` from `mrb_get_backtrace` definition
2021-04-20 17:40:33 +09:00
KOBAYASHI Shuji
903fbd767a
Remove unused struct in include/mruby/variable.h
2021-04-20 16:53:11 +09:00
KOBAYASHI Shuji
c6911c54e5
Remove unused #include in complex.c and rational.c
2021-04-20 16:42:40 +09:00
KOBAYASHI Shuji
0d8b025d9b
Remove MRB_API from mrb_get_backtrace definition
2021-04-20 16:07:48 +09:00
Yukihiro "Matz" Matsumoto
ff366b65eb
Merge pull request #5415 from dearblue/unwind-mrb_protect
...
Introducing the `mrb_protect_raw()` API function
2021-04-19 22:34:20 +09:00
dearblue
891e852286
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()`.
2021-04-19 22:11:57 +09:00
Yukihiro "Matz" Matsumoto
9d362f2c27
backtrace.c: remove MRB_API from internal functions.
...
- `mrb_exc_backtrace` to implement `Exception#backtrace`
- `mrb_get_backtrace` to implement `#caller`
2021-04-19 15:49:51 +09:00
Yukihiro "Matz" Matsumoto
13eba43100
backtrace.c: small refactoring in mrb_exc_backtrace(); ref #5394
...
- add comment for unpacking
- avoid saving the symbol in a local variable
2021-04-19 15:49:51 +09:00
Yukihiro "Matz" Matsumoto
2275e76262
backtrace.c: pedantic check for empty backtrace; ref #5394
2021-04-19 15:49:50 +09:00
Yukihiro "Matz" Matsumoto
85808e50b0
backtrace.c: should skip first (innermost) frame w/out position; #5394
...
Otherwise we suffer `(unknown):0:` errors.
2021-04-19 15:49:50 +09:00
Yukihiro "Matz" Matsumoto
049ec9056e
time.c: add integer boundary check for year.
...
On configurations where `sizeof(mrb_int) > sizeof(int)`.
2021-04-19 15:49:50 +09:00
Yukihiro "Matz" Matsumoto
713fb53bbf
Merge pull request #5414 from shuujii/mRubyPresym-no-longer-needs-RakeDSL
...
`MRuby::Presym` no longer needs `Rake::DSL`
2021-04-18 08:24:15 +09:00