Commit Graph

93 Commits

Author SHA1 Message Date
KOBAYASHI Shuji feaf80d899 Use type predicate macros instead of mrb_type if possible
For efficiency with `MRB_WORD_BOXING` (implement type predicate macros for
all `enum mrb_vtype`).
2019-09-26 22:23:27 +09:00
Yukihiro "Matz" Matsumoto ca2d47c20f Fix super from aliased methods to work correctly; fix #4718
We needed to preserve the original method name somewhere. We kept it in
the `env` structure pointed from aliased methods. #1457 and #1531 tried
to address this issue. But this patch is more memory efficient.

Limitation: this fix does not support `super` from methods defined by
`define_method`. This limitation may be addressed in the future, but
it's low priority.
2019-09-18 10:31:28 +09:00
dearblue 099a4f3969 Entrust "no block given" error to mrb_get_args()
Some error messages will be changed.
2019-09-16 20:29:58 +09:00
dearblue 279c21b816 Prohibit changes to iseq in principle 2019-08-18 15:00:32 +09:00
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in
my environment than before the introduction of new specifiers/modifiers
(5116789a) with this change.

  ------------+-------------------+-------------------+--------
   BINARY     | BEFORE (5116789a) |   AFTER (This PR) |  RATIO
  ------------+-------------------+-------------------+--------
   mruby      |      593416 bytes |      593208 bytes | -0.04%
   libmruby.a |      769048 bytes |      767264 bytes | -0.23%
  ------------+-------------------+-------------------+--------

BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613,
so I put it back.
2019-08-05 13:18:50 +09:00
KOBAYASHI Shuji 271a91c648 Remove unused mrb_proc_cfunc_p() 2019-04-06 16:32:27 +09:00
KOBAYASHI Shuji ed41bbb199 Use mrb_proc_arity instead of Proc#arity call in Method#arity 2019-04-04 22:17:26 +09:00
KOBAYASHI Shuji 10a8e0f105 Fix arguments spec in src/proc.c 2019-03-24 20:55:04 +09:00
Yukihiro "Matz" Matsumoto 0419f07915 Add NULL checks for mrb->ci and proc->upeer; #4024 2018-11-02 14:57:03 +09:00
Yukihiro "Matz" Matsumoto 891839b976 New bytecode implementation of mruby VM. 2018-07-30 22:57:54 +09:00
Yukihiro "Matz" Matsumoto 100f0e6759 Do not need to take target_class from the upper proc.
Since it is already set in `mrb_proc_new()`.
2017-12-20 19:37:26 +09:00
Yukihiro "Matz" Matsumoto 8f2c62407c Add MRB_METHOD_TABLE_INLINE option.
Now the method tables (in classes/modules and caches) keeps C function
pointers without wrapping in `struct RProc` objects. For the sake of
portability, `mrb_method_t` is represented by the struct and union, but
if the most significant bit of the pointer is not used by the platform,
`mrb_method_t` should be packed in `uintptr_t` to reduce memory usage.

`MRB_METHOD_TABLE_INLINE` is turned on by default for linux.
2017-11-20 18:33:41 +09:00
Yukihiro "Matz" Matsumoto 93f5f22577 Heavily refactored how lexical scope links are implemented; fix #3821
Instead of `irep` links, we added a `upper` link to `struct RProc`.
To make a space for the `upper` link, we moved `target_class` reference.
If a `Proc` does not have `env`, `target_class` is saved in an `union`
shared with `env` (if a `Proc` has env, you can tell it by `MRB_PROC_ENV_P()).
Otherwise `target_class` is referenced from `env->c`. We removed links
in `env` as well.

This change removes 2 members from `mrb_irep` struct, thus saving 2
words per method/proc/block. This also fixes potential memory leaks
due to the circular references caused by a link from `mrb_irep`.
2017-10-28 00:29:30 +09:00
Tomasz Dąbrowski b7e71e4cef fix: src\proc.c(96): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Yukihiro "Matz" Matsumoto ab99e2c293 Avoid copying over initialized procs using initialize_copy; fix #3803
It may be better to raise exceptions, but CRuby doesn't.
2017-09-01 06:51:59 +09:00
Yukihiro "Matz" Matsumoto fe3227cd5c Set the ORPHAN flag in Proc.new; fix #3798 2017-08-30 16:51:40 +09:00
Yukihiro "Matz" Matsumoto 2170fad406 Cosmetic changes (removing spaces before * in return types). 2017-08-01 16:31:18 +09:00
Yukihiro "Matz" Matsumoto 5513fcee22 Keep reference to mrb_context from env; fix #3619 2017-04-22 14:35:36 +09:00
Yukihiro "Matz" Matsumoto 045e78c844 Proc#call needs to reserve at least 2 registers; fix #3606
One for the receiver, the other for the block.
2017-04-13 11:02:02 +09:00
Yukihiro "Matz" Matsumoto 0a1f15e57c Insert mrb_field_write_barrier() for GC; fix #3534 2017-04-03 18:01:43 +09:00
ksss a68b568911 Should call initialize method if defined 2016-12-22 10:40:13 +09:00
ksss 3cba13c249 Proc shouldn't have initialize method
Fix #3356
2016-12-21 15:17:05 +09:00
Clayton Smith 1ff4b3f800 Fix segfault in mrb_proc_copy. 2016-12-02 09:36:26 -05:00
Francois Chagnon 1ec5994377 Fix calling .arity on Proc with undefined initialize
Reported by @bouk
2016-11-24 10:23:31 -05:00
Kouhei Sutou 91bd3ebd32 Remove needless MRB_API
ref #3215

If a function (such as mrb_read_irep_file()) is declared without MRB_API
in header file (such as include/mruby/dump.h), implementation of the
function in source file (such as src/load.c) should also defined without
MRB_API.

If MRB_API is mismatch, Visual C++ reports link error with C2375 error
code: https://msdn.microsoft.com/en-us/library/5k6kw95a.aspx
2016-09-25 21:47:49 +09:00
Yukihiro "Matz" Matsumoto 5c405dea3d include changed from by quotes ("") to by brackets (<>); close #3032 2015-11-27 17:48:23 +09:00
Kouhei Sutou 52db92de53 Fix a crash bug when GC is ran while creating a proc with env
mrb_proc_new_cfunc_with_env() allocates RProc with RProc::env as NULL
then allocates REnv and sets it to RProc::env of the allocated RProc. If
incremental GC is ran before "allocates REnv and sets it to RProc::env
of the allocated RProc", the allocated RProc's GC status is
"marked" (Black) and the allocated REnv's GC status is
"unmarked" (White). The next incremental GC sweeps the allocated REnv
without re-marking the allocated RProc. Because the RProc is Black and
the REnv is White.

We need to implement write barrier for the case.

We can force to cause the above situation by the following patch:

    diff --git a/src/proc.c b/src/proc.c
    index f98998f..4f4e25c 100644
    --- a/src/proc.c
    +++ b/src/proc.c
    @@ -92,6 +92,7 @@ mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t func, mrb_int argc, const
       struct REnv *e;
       int i;

    +  mrb_incremental_gc(mrb);
       p->env = e = env_new(mrb, argc);
       MRB_ENV_UNSHARE_STACK(e);
       e->stack = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value) * argc);

With this patch, "rake test" causes segmentation fault.
2015-06-29 14:39:30 +09:00
Yukihiro "Matz" Matsumoto 937b5b5462 fix Proc#curry test failure; ref #2848 2015-06-23 14:42:58 +09:00
cremno f0eaf9eaf5 fix arity of lambdas with optional arguments
From the CRuby 2.2.2 Proc#arity documentation:

If the block has optional arguments, returns -n-1, where n is the number
of mandatory arguments, with the exception for blocks that are not
lambdas and have only a finite number of optional arguments; in this
latter case, returns n.
2015-06-22 13:34:24 +02:00
Carson McDonald a797d45e90 Verify that proc_lambda is passed a proc 2015-05-22 10:34:28 -04:00
Yukihiro "Matz" Matsumoto 83992ee163 cast MRB_ENV_STACK_LEN to (mrb_int); ref #2600 2014-10-02 17:59:01 +09:00
Hiroshi Mimaki ed15477c74 Pacify MSVC warnings for numeric.c, proc.c, and symbol.c 2014-10-02 13:37:49 +09:00
Yukihiro "Matz" Matsumoto 471c43ff96 move mrb_proc_new_cfunc_with_env() to the core 2014-09-02 13:03:32 +09:00
Tatsuhiko Kubo 5fa30aeaea Fix mismatches for MRB_API declarations. 2014-08-29 01:06:22 +09:00
Yukihiro "Matz" Matsumoto 7477d0c18c revert 6c1dfc9; ref #2525 #2565 2014-08-29 01:06:22 +09:00
Yukihiro "Matz" Matsumoto 6c1dfc9566 need to add space for receiver to proc env; fix #2525 2014-08-13 23:58:32 +09:00
Yukihiro "Matz" Matsumoto 206f89e209 add MRB_API modifiers to mruby API functions 2014-08-04 00:47:08 +09:00
Tatsuhiko Kubo 5b5313ec97 use C style comments instead of C++ style comments 2014-07-13 00:24:45 +09:00
ksss 19b82944f8 Proc#arity return 0 when opcode was not OP_ENTER 2014-06-25 08:48:08 +09:00
ksss 907a299790 arity for cfunc is not implemented yet 2014-06-15 22:38:22 +09:00
ksss 1cced27a79 Proc class define before a first method
mrb_define_method setting mrb->proc_class for method proc
2014-06-15 22:34:46 +09:00
Jun Hiroe 0388e373d0 Delete unnecessary semicolon 2014-05-17 00:52:00 +09:00
Yukihiro "Matz" Matsumoto 2be348a0f1 mv opcode.h -> include/mruby/opcode.h and remove duplication from mruby-eval gem 2014-05-14 23:14:08 +09:00
Nobuyoshi Nakada 345f172bba adjust indent 2014-04-30 09:50:02 +09:00
Yukihiro "Matz" Matsumoto 2ca5bed901 make cioff in struct REnv from int to ptrdiff_t; close #2149 2014-04-29 12:25:15 +09:00
Yukihiro "Matz" Matsumoto 5138f62d6b resolve conflict 2014-04-15 10:55:46 +09:00
take_cheeze 80534b6d14 Use MRB_ENV_STACK_LEN instead of accessing flags directly to get REnv's stack length. 2014-04-01 01:13:39 +09:00
Yukihiro "Matz" Matsumoto 306b1d3c51 Merge pull request #1948 from monaka/pr-remove-unused-null-check
Remove redundant NULL checks.
2014-03-26 13:32:18 +09:00
Masaki Muranaka dcff9012e3 Remove redundant NULL checks.
mrb_malloc causes an exception when memory was empty.
2014-03-26 11:21:20 +09:00
Yukihiro "Matz" Matsumoto b4dd3564ef REnv uses obj->c as env link; no super 2014-03-25 11:50:11 +09:00