3760 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 056cda72be mruby-bin-mirb: fix multi-line input issue; fix #5922
Bison changed the message for the end-of-file error. `mirb` should
be updated for the new message.
2023-02-07 17:43:14 +09:00
Yukihiro "Matz" Matsumoto 762ca43c16 mruby-bin-mirb: add bintest for multi-line input; ref #5922 2023-02-07 17:42:56 +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
dearblue b0e537c05c Replaced NO_IO_POPEN with MRB_NO_IO_POPEN
ref. commit 9deb52c7b2
2023-01-22 09:20:10 +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 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 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
Yukihiro "Matz" Matsumoto e45e57fe22 mruby-io: update ISO section numbers 2023-01-07 16:39:59 +09:00
Yukihiro "Matz" Matsumoto fadb39a096 mruby-io/io.c: remove unused method _bufread 2023-01-06 08:52:02 +09:00
Yukihiro "Matz" Matsumoto 412b1f0fb3 mruby-io/io.c: implement IO#readlines in C 2023-01-06 08:51:21 +09:00
Yukihiro "Matz" Matsumoto 7827808d3b mruby-io/io.c: remove Ruby implementation of IO#gets 2023-01-05 23:54:46 +09:00
Yukihiro "Matz" Matsumoto 9797138aca mruby-io/io.c: rename io_read_buf_noraise to io_read_buf 2023-01-05 19:50:17 +09:00
Yukihiro "Matz" Matsumoto 714cc254c0 mruby-io/io.c: remove unused function io_read_buf() 2023-01-05 19:50:16 +09:00
Yukihiro "Matz" Matsumoto cd01f1173a mruby-io/io.c: implement IO#gets in C
In addition, reimplement `IO#readline` using `IO#gets`.
2023-01-05 19:50:16 +09:00
Yukihiro "Matz" Matsumoto b7147bbd8d mruby-io/io.c: implement IO#getbyte in C
In addition, reimplement `IO#readbyte` using `IO#getbyte`.
2023-01-05 19:50:16 +09:00
Yukihiro "Matz" Matsumoto eec546a9cf mruby-io/io.c: implement IO#getc in C
In addition, reimplement `IO#readchar` using `IO#getc`.
2023-01-05 19:50:16 +09:00
Yukihiro "Matz" Matsumoto 6e7322a3fe mruby-io/io.c (eof_error): a new function to raise EOFError exception 2023-01-05 19:50:15 +09:00
Yukihiro "Matz" Matsumoto 40039d93ab mruby-io/io.c: implement IO#getline in C 2023-01-05 19:50:15 +09:00
Yukihiro "Matz" Matsumoto a9c98ab855 mruby-io/io.c: implement IO#read in C 2023-01-05 19:50:15 +09:00
Yukihiro "Matz" Matsumoto 99dffb6daf mruby-io/io.c: use RSTR_SET_LEN() instead of mrb_str_resize()
since the latter may shrink allocated buffer, and may cause repeated
allocations.
2023-01-05 19:50:14 +09:00
Yukihiro "Matz" Matsumoto 1bc0be3e43 mruby-io/io.c: implement IO#eof? in C 2023-01-05 19:50:14 +09:00
Yukihiro "Matz" Matsumoto 9e808512d5 mruby-io/io.c: remove duplicated initializations after io_alloc() 2023-01-05 19:50:14 +09:00
Yukihiro "Matz" Matsumoto 2b90937a2e mruby-io/io.c: add ISO section comments 2023-01-05 19:50:14 +09:00
Yukihiro "Matz" Matsumoto d57540118b mruby-io/io.c: rename _common functions 2023-01-05 19:50:13 +09:00
Yukihiro "Matz" Matsumoto 51dca6eda8 mruby-io/io.c: rename receiver names from self to io in this file 2023-01-02 10:01:09 +09:00
Yukihiro "Matz" Matsumoto 0e25448a20 mruby-io/io.c (io_check_readable): hide internal method in backtraces 2023-01-02 10:01:08 +09:00
Yukihiro "Matz" Matsumoto 7cc6a720f3 mruby-io/io.c: implement IO#readchar in C 2023-01-02 10:01:08 +09:00
Yukihiro "Matz" Matsumoto 10a5edd978 mruby-io/io.c: implement IO#getbyte in C 2023-01-02 10:01:08 +09:00
dearblue 72ab1821de Avoid IOError when returning from Dir.open
Ignore `IOError` if `Dir#close` was done in the block.
2023-01-01 17:40:50 +09:00
Yukihiro "Matz" Matsumoto 0c9798373a mruby-io/io.c (fptr_finalize): close stdin/out/err as well
if not during the termination process.
2022-12-31 17:53:20 +09:00
Yukihiro "Matz" Matsumoto 965997d91b mruby-io/io.c: implement IO#flush in C 2022-12-31 10:39:05 +09:00
Yukihiro "Matz" Matsumoto 0628669790 mruby-data/data.c (to_s): add class name in string representation 2022-12-31 07:51:09 +09:00
Yukihiro "Matz" Matsumoto b79563af60 mruby-io/test: remove test for internal IO#_read_buf 2022-12-30 13:59:21 +09:00
Yukihiro "Matz" Matsumoto a68b1200c2 mruby-io/test: test IO#ungetc 2022-12-30 13:59:01 +09:00
Yukihiro "Matz" Matsumoto 26f458baab mruby-io/io.c: implement IO#ungetc in C 2022-12-30 13:59:01 +09:00
Yukihiro "Matz" Matsumoto 99a4c1f703 mruby-io/io.c (io_buf): protect @buf from modification
Users may re-assign `@buf` using `instance_variable_set` for example.
2022-12-30 13:59:00 +09:00
Yukihiro "Matz" Matsumoto 9a6a251460 mruby-io/io.c (io_bufread_m): remove unnecessary checks 2022-12-30 13:59:00 +09:00