Commit Graph

14772 Commits

Author SHA1 Message Date
John Bampton 2bb6eeb7c0 Makefile/Rakefile add target/task for pre-commit install 2023-02-01 13:14:23 +10:00
Yukihiro "Matz" Matsumoto d41ea96c2a string.c: fix boundary check in String#bytesplice
It should be able to append to the receiver.
2023-01-29 17:10:15 +09:00
Yukihiro "Matz" Matsumoto a2e2e83012 string.c: move String#bytesplice to the core 2023-01-28 16:43:40 +09:00
Yukihiro "Matz" Matsumoto 12e232c006 mruby-string-ext/string.rb: add test for String#bytesplice 2023-01-28 16:41:40 +09:00
Yukihiro "Matz" Matsumoto 52746479a3 mruby-string-ext/string.c: new method String#byteslice 2023-01-27 23:22:02 +09:00
Yukihiro "Matz" Matsumoto 7b27346386 mruby-os-memsize/memsize.c: avoid mrb_get_args() 2023-01-26 11:14:10 +09:00
Yukihiro "Matz" Matsumoto 78bbf75981 mruby-random/random.c: avoid mrb_get_args() 2023-01-26 11:13:48 +09:00
Yukihiro "Matz" Matsumoto 4e85e855cf numeric.c: avoid mrb_get_args() if possible 2023-01-25 14:10:43 +09:00
Yukihiro "Matz" Matsumoto 4e5be5a288 array.c: avoid slower mrb_get_args() if possible 2023-01-25 14:10:03 +09:00
Yukihiro "Matz" Matsumoto 37da677cc8 numeric.c (mrb_int_pow): avoid unnecessary calls to mrb_get_args() 2023-01-24 15:25:06 +09:00
Yukihiro "Matz" Matsumoto d1449c2622 array.c (mrb_ary_times): avoid multiple calls to mrb_get_args() 2023-01-24 15:23:30 +09:00
Yukihiro "Matz" Matsumoto d9bf3235d2 mruby-math/math.c: avoid mrb_get_args() if possible
When a method takes single argument, we can use lighter `mrb_get_arg1()`
instead of `mrb_get_args()`.
2023-01-24 09:15:20 +09:00
Yukihiro "Matz" Matsumoto aefc5befbd mruby-io/io.c: fix issues with gets; fix #5913
- gets with RS multiple times
- gets with RS with limit
- gets with limit bigger than buffer size
2023-01-23 07:30:40 +09:00
Yukihiro "Matz" Matsumoto be5266fbe6 mruby-io/test: test gets with RS multiple times; ref #5913 2023-01-23 07:26:40 +09:00
Yukihiro "Matz" Matsumoto 4d5aadfc84 class.c (create_method_value): refactor mrb_method_t creation 2023-01-23 00:17:32 +09:00
Yukihiro "Matz" Matsumoto 079244c36a src/class.c: add new function mrb_vm_find_method
The function skips `cp` dereference, and improve performance of method
calls slightly.
2023-01-23 00:17:32 +09:00
Yukihiro "Matz" Matsumoto 6b0efd43da NEWS: copy entries from doc/mruby3.2.md 2023-01-23 00:17:32 +09:00
Yukihiro "Matz" Matsumoto 2e9f62b12c Merge pull request #5914 from dearblue/doc/mruby3.2.md
Update mruby3.2.md for changes behavior of `mrb_vm_run()`
2023-01-22 22:49:57 +09:00
Yukihiro "Matz" Matsumoto 3c02c517ca Merge pull request #5915 from dearblue/doc/mruby3.2.md.1
Update mruby3.2.md for new `mruby-data` gem
2023-01-22 22:49:05 +09:00
dearblue 998ef1711a Update mruby3.2.md for new mruby-data gem 2023-01-22 20:52:09 +09:00
dearblue a223778ee8 Update mruby3.2.md for changes behavior of mrb_vm_run() 2023-01-22 20:45:57 +09:00
Yukihiro "Matz" Matsumoto 882bb0662a Merge pull request #5912 from dearblue/io-popen
Replaced `NO_IO_POPEN` with `MRB_NO_IO_POPEN`
2023-01-22 13:37:39 +09:00
dearblue b0e537c05c Replaced NO_IO_POPEN with MRB_NO_IO_POPEN
ref. commit 9deb52c7b2
2023-01-22 09:20:10 +09:00
Yukihiro "Matz" Matsumoto 97fe582d41 Merge pull request #5911 from dearblue/eval+binding
Fixed `Kernel#.eval` crash when given a custom defined `Binding` instance
2023-01-20 22:44:28 +09:00
dearblue 36f822d9af Fixed Kernel#.eval crash when given a custom defined Binding instance
```console
% bin/mruby -e 'class Binding; end; eval "1", Binding.new'
zsh: segmentation fault (core dumped)  bin/mruby -e 'class Binding; end; eval "1", Binding.new'
```
2023-01-20 21:26:21 +09:00
Yukihiro "Matz" Matsumoto 3a7e138c05 mruby/internal.h: add mrb_env_new to the internal function header 2023-01-18 10:37:48 +09:00
Yukihiro "Matz" Matsumoto e6cf932d38 fixup! mruby/internal.h: add codedump functions to the internal function header 2023-01-18 10:37:48 +09:00
Yukihiro "Matz" Matsumoto 55eea005c8 mruby/internal.h: add codedump functions to the internal function header
ref #5906
2023-01-18 10:37:48 +09:00
Yukihiro "Matz" Matsumoto 3639feb047 Merge pull request #5908 from dearblue/env-unshare.2
Make `mrb_env_unshare()` call in `mrb_vm_run()`
2023-01-18 08:05:00 +09:00
Yukihiro "Matz" Matsumoto 63597cbbd1 Merge pull request #5910 from mruby/dependabot/github_actions/github/super-linter-4.10.1
build(deps): bump github/super-linter from 4.10.0 to 4.10.1
2023-01-18 07:53:11 +09:00
Yukihiro "Matz" Matsumoto faa6a5cb4f Merge pull request #5906 from AlexDenisov/codedump-to-file
Add ability to dump bytecode into an arbitrary file
2023-01-18 07:37:12 +09:00
AlexDenisov e15288e460 Add ability to dump bytecode into an arbitrary file 2023-01-17 19:01:55 +01:00
dependabot[bot] 823b8e4148 build(deps): bump github/super-linter from 4.10.0 to 4.10.1
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.10.0 to 4.10.1.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.10.0...v4.10.1)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-17 14:01:22 +00:00
Yukihiro "Matz" Matsumoto 9deb52c7b2 mruby-io/io.c: allow disabling popen
When `MRB_NO_IO_POPEN` is defined (or iPhone is target), `IO#popen`
will be disabled.
2023-01-17 18:25:23 +09:00
Yukihiro "Matz" Matsumoto 6b87aae757 doc/guides/compile.md: update compilation example
Show usage of multiple command-line options to `mruby-config`.
2023-01-17 18:23:29 +09:00
Yukihiro "Matz" Matsumoto 10768c1191 LEGAL: add entries for non-MIT licensed files. 2023-01-17 18:23:29 +09:00
Yukihiro "Matz" Matsumoto 2c261503b5 doc/internal/boxing.md: remove an extra double quote sign. 2023-01-16 19:01:11 +09:00
Yukihiro "Matz" Matsumoto 7a6d03f869 vm.c: transferred fiber termination should kick root fiber; fix #5907 2023-01-16 18:25:50 +09:00
Yukihiro "Matz" Matsumoto 3f6fd994f0 README.md: mruby is not Ruby 3.x compatible (for syntax at least)
With pattern matching as an exception.
2023-01-16 14:39:47 +09:00
dearblue 365c151df0 Make mrb_env_unshare() call in mrb_vm_run()
Move the detachment of the "env" object, now done by `mrb_top_run()` by #5904, to `mrb_vm_run()`.
This is because `mrb_vm_run()` can remove `mrb_env_unshare()` which is called from `bin/mirb`.

Also, even if the mruby VM is already running, either of the following conditions should be used to detach "env":
  - If the `stack_keep` variable is 0.
  - If the stack length of "env" is longer than `irep->nlocals`.

The reason for the change is that the stack beyond `irep->nlocals` is used inside the called method, and previously it was possible to reference and manipulate the state inside the method via "env".

    env stack       |                           |

    main stack      | top |  m1  |    m2    |
                          |<--------------->|
                            operable via env stack (including self)

If the problematic block is called from the `m2` method above, it is possible to replace `self` in `m1` and `m2` as well as the internal variables.

This change may cause compatibility problems, but I believe it is better to make `MRB_API`, `mrb_vm_run()` safe.
If a dangerous procedure is absolutely necessary, `mrb_vm_exec()` can still be called as before.
2023-01-15 18:16:42 +09:00
Yukihiro "Matz" Matsumoto a96a9f2c2b mruby-fiber/fiber.c: detect resume/transfer mixture; fix #5905
Also, transferred fibers should kick the root fiber at termination.
2023-01-12 07:23:35 +09:00
Yukihiro "Matz" Matsumoto 9211bf0950 mruby-fiber/test: Fiber#transfer should not be mixed with Fiber#resume
ref #5905

The original tests failed with CRuby.
2023-01-11 18:19:07 +09:00
Yukihiro "Matz" Matsumoto d9145b8621 mruby-test/drive.c: add string type check 2023-01-11 10:43:11 +09:00
Yukihiro "Matz" Matsumoto 00339b3aa8 Merge pull request #5904 from dearblue/env-unshare-on-top-run
Call `mrb_env_unshare()` in `mrb_top_run()` if necessary
2023-01-10 18:22:43 +09:00
Yukihiro "Matz" Matsumoto 1bba8cf53b mruby-dir: remove files needed for an independent gem 2023-01-10 10:53:15 +09:00
Yukihiro "Matz" Matsumoto a800988239 mruby-set: remove files needed for an independent gem 2023-01-10 10:51:23 +09:00
dearblue c101261f45 Call mrb_env_unshare() in mrb_top_run() if necessary
This is to keep the local variables of the previously created blocks consistent in case the `mrbc_context` passed to `mrb_load_exec()` is `NULL` or different.
Switching between `mrbc_context` pointers that are non `NULL` can be done safely by calling `mrbc_cleanup_local_variables()`.

Before this patch, the result of the following code is not as expected.

```console
% cat loadstr.c
#include <mruby.h>
#include <mruby/compile.h>

int
main(int argc, char *argv[])
{
  mrb_state *mrb = mrb_open();

  mrb_load_string(
      mrb,
      "(a, b, c, d, e, f, g) = [1, 2, 3, 4, 5, 6, 7] \n"
      "$lambda = -> { p [a, b, c, d, e, f, g] }");
  mrb_load_string(mrb, "$lambda.call");

  mrb_close(mrb);

  return 0;
}

% $(bin/mruby-config --cc --cflags --ldflags) loadstr.c $(bin/mruby-config --libs) && ./a.out
[main, nil, nil, main, nil, nil, main]
```

Also, since `mrb_env_unshare()` was not used before, the internal stack of simply detached `env` objects could show invalid addresses by `stack_extend()`.
ref. https://github.com/kou/mruby-pp/commit/ef5951aca870183d8767cb61f6414240988ca35e
2023-01-09 22:47:37 +09:00
Yukihiro "Matz" Matsumoto e2ffcbab6e mruby-io/io.c: cast return pointer from malloc/realloc for C++ 2023-01-09 19:58:30 +09:00
Yukihiro "Matz" Matsumoto 8b7e240e67 mruby-io/io.c: improve code around io_cloexec_open() 2023-01-09 19:43:37 +09:00
Yukihiro "Matz" Matsumoto 91727f38de mruby-io/io.c: change the implementation of read buffers
The original implementations used plain Ruby strings referenced from
instance variable (`@buf`) as buffers. We replaced those buffers by C
structure (`struct mrb_io_buf`) referenced directly from `fptr`.

The result is significant improvement of both performance and memory
consumption. Our simple benchmarks (reading `README.md` 10,000 times)
runs 5+ times faster, and `mrbtest` test suites consumes 85% less
memory.

Recent changes on `mruby-io` is preparation for this improvement.
2023-01-09 10:18:35 +09:00