Commit Graph

271 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 9174b18f34 Rename mrb_num_args_error to mrb_argnum_error; ref #4863 2020-01-01 22:37:14 +09:00
KOBAYASHI Shuji 81de1f159c Add mrb_num_args_error() for "wrong number of arguments" error
To unify the style of messages.
2019-12-12 11:45:58 +09:00
KOBAYASHI Shuji 04baaab311 Fix argument specs to Kernel 2019-11-15 19:07:42 +09:00
Yukihiro "Matz" Matsumoto 079aff1779 Revert a76dc04 to resolve #4820 2019-11-13 21:06:26 +09:00
Yukihiro "Matz" Matsumoto 1f5a7f2f49 Freeze strings from nil.to_s, true.to_s, false.to_s.
This is an experimental changes in Ruby 2.7.
2019-10-04 16:02:50 +09:00
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 57d7fe94a9 Add a macro mrb_frozen_p that points to MRB_FROZEN_P. 2019-09-14 23:21:44 +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 7675fcb5d3 Fix Module#dup to frozen module
Before this patch:

  $ bin/mruby -e 'p Module.new.freeze.dup.frozen?'  #=> true

After this patch (same as Ruby):

  $ bin/mruby -e 'p Module.new.freeze.dup.frozen?'  #=> false
2019-07-20 22:41:57 +09:00
KOBAYASHI Shuji 4b83fe8b04 Remove Kernel#global_variables from core
This method is defined in `mruby-metaprog` gem.
2019-06-07 22:02:43 +09:00
KOBAYASHI Shuji 6fb5979d29 Move Kernel#equal? to BasicObject` 2019-05-18 20:57:54 +09:00
KOBAYASHI Shuji 8fa3995a1a Singleton class of frozen object should be frozen
Before this patch:

  p (class << Object.new.freeze; self end).frozen?                #=> false
  sc = class << (o=Object.new); self end; o.freeze; p sc.frozen?  #=> false

After this patch / Ruby:

  p (class << Object.new.freeze; self end).frozen?                #=> true
  sc = class << (o=Object.new); self end; o.freeze; p sc.frozen?  #=> true
2019-04-25 19:48:40 +09:00
KOBAYASHI Shuji 7b0ebed033 Use mrb_immediate_p() in mrb_obj_freeze() and mrb_obj_frozen() 2019-04-10 19:19:53 +09:00
Yukihiro "Matz" Matsumoto c2660b8111 Fix missing MRB_API prefix for functions below; clse #4267
Functions to add prototypes to headers:
* mrb_ary_splice()
* mrb_notimplement()
* mrb_vformat()
* mrb_cstr_to_dbl()
* mrb_cstr_to_inum()

Functions to be made `static` (`MRB_API` was not needed):
* mrb_mod_module_function()
* mrb_obj_hash()
* mrb_str_len_to_inum()

Functions to remove `MRB_API` from definitions (referenced from within `libmruby`):
* mrb_mod_cv_defined()
* mrb_mod_cv_get()
* mrb_f_send()
2019-03-26 10:23:52 +09:00
Yukihiro "Matz" Matsumoto cca19532c5 Remove Kernel#class_defined? which is not available in CRuby; #3829 2019-01-03 11:34:35 +09:00
Yukihiro "Matz" Matsumoto ff08856fe3 Remove implicit conversion using to_str method; fix #3854
We have added internal convenience method `__to_str` which
does string type check.

The issue #3854 was fixed but fundamental flaw of lack of stack
depth check along with fibers still remains. Use `MRB_GC_FIXED_ARENA`
for workaround.
2018-11-19 12:05:46 +09:00
Yukihiro "Matz" Matsumoto afca99a40b Remove implicit conversion using to_int method.
The ISO standard does not include implicit type conversion using
`to_int`. This implicit conversion often causes vulnerability.
There will be no more attacks like #4120.

In addition, we have added internal convenience method `__to_int` which
does type check and conversion (from floats).
2018-11-19 11:28:51 +09:00
Yukihiro "Matz" Matsumoto b80e0ef742 Move Kernel#send to mruby-metaprog gem.
But `BasicObject#__send__` is still available from the core.
2018-09-01 11:20:30 +09:00
Yukihiro "Matz" Matsumoto 593c12a5cd Avoid NoMethodError exception from mrb_func_basic_p. 2018-09-01 11:18:12 +09:00
Yukihiro "Matz" Matsumoto e471d37ca5 Separate meta-programming features to mruby-metaprog gem.
We assume meta-programming is less used in embedded environments.
We have moved following methods:

 * Kernel module
   global_variables, local_variables, singleton_class,
   instance_variables, instance_variables_defined?, instance_variable_get,
   instance_variable_set, methods, private_methods, public_methods,
   protected_methods, singleton_methods, define_singleton_methods

 * Module class
   class_variables, class_variables_defined?, class_variable_get,
   class_variable_set, remove_class_variable, included_modules,
   instance_methods, remove_method, method_removed, constants

 * Module class methods
   constants, nesting

Note:
Following meta-programming methods are kept in the core:

 * Module class
   alias_method, undef_method, ancestors, const_defined?, const_get,
   const_set, remove_const, method_defined?, define_method

 * Toplevel object
   define_method

`mruby-metaprog` gem is linked by default (specified in default.gembox).
When it is removed, it will save 40KB (stripped:8KB) on x86-64
environment last time I measured.
2018-08-30 22:30:36 +09:00
Yukihiro "Matz" Matsumoto 9409a2ff6d Rename ambiguous function names.
`mrb_iv_p` -> `mrb_iv_name_sym_p`
`mrb_iv_check` -> `mrb_iv_name_sym_check`
2018-08-25 09:17:46 +09:00
Yukihiro "Matz" Matsumoto fd086833ff Reorganize flags values for classes; fix #3975
Renamed flag macro names as well:
`MRB_FLAG_IS_FROZEN` -> `MRB_FL_OBJ_FROZEN`
`MRB_FLAG_IS_PREPENDED` -> `MRB_FL_CLASS_IS_PREPENDED`
`MRB_FLAG_IS_ORIGIN` -> `MRB_FL_CLASS_IS_ORIGIN`
`MRB_FLAG_IS_INHERITED` -> `MRB_FL_CLASS_IS_INHERITED`
2018-08-25 09:13:09 +09:00
Yukihiro "Matz" Matsumoto 8c9e712784 Keyword argument implemented. 2018-07-30 22:58:01 +09:00
Yukihiro "Matz" Matsumoto 891839b976 New bytecode implementation of mruby VM. 2018-07-30 22:57:54 +09:00
Yukihiro "Matz" Matsumoto 55edae0226 Allow Object#clone to copy frozen status only; fix #4036
Copying all flags from the original object may overwrite the clone's
flags e.g. the embedded flag.
2018-06-07 16:17:00 +09:00
Yukihiro "Matz" Matsumoto f408143c28 The clone method should copy object status (e.g. frozen) too; #4030 2018-06-01 22:39:40 +09:00
Yukihiro "Matz" Matsumoto b64ce17852 Should not call initialize_copy for TT_ICLASS; fix #4027
Since `TT_ICLASS` is a internal object that should never be revealed
to Ruby world.
2018-05-30 17:05:40 +09:00
Yukihiro "Matz" Matsumoto 1dddc2f712 Clear __classname__ of duped class/module; ref #4027 2018-05-30 17:05:05 +09:00
Yukihiro "Matz" Matsumoto 6999e45742 Do not include object string representation in NoMethodError message.
This information is not mandatory but causes a lot of problems in the
past due to infinite recursion by redefining `to_str`, `inspect` etc.
2017-12-23 15:15:03 +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 de2363a9f0 Merge branch 'mrb_without_float' of https://github.com/pandax381/mruby into pandax381-mrb_without_float 2017-11-04 11:49:25 +09:00
Yukihiro "Matz" Matsumoto 388d26d770 Reimplement block_given?; ref #3841
Make `block_given?` to search for the top of the scope first.
The top of the scope means either:

* the top method body
* the enclosing class body
* the top-level

The special case is the method defined by `define_method` with a
block as in #3841. In cases like this, the method body (given by
a block) is not considered as the top of the scope. You need to use
`&block` in the block parameter if you want to know if a block is
given to the method.

This commit also changes the behavior of `MRB_PROC_SCOPE` flag.
Now it is only set if the `proc` is either a class body or a method
body defined in Ruby. It is no longer set for a block that given to
`define_method`.
2017-11-04 11:20:04 +09:00
Yukihiro "Matz" Matsumoto ab27abe083 The bidx saved in env may be useless; fix #3841
When `block_given?` is called from a block given to `define_method`
as a method body, the `bidx` may not be within `env` saved closure.
In this case, it causes heap buffer overflow.
2017-11-04 03:01:37 +09:00
YAMAMOTO Masaya 625f9f6fa3 Merge branch 'master' of github.com:mruby/mruby 2017-11-04 01:23:12 +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
YAMAMOTO Masaya acdc2d1f24 Add MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
Tomasz Dąbrowski 0e0c96096d fix: src\kernel.c(861): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Yukihiro "Matz" Matsumoto 3acaa44a70 Restructure irep->outer chain; fix #3804
Instead of `irep -> proc` chain, we use `irep -> irep` chain to
avoid GC bugs like #3804. We added `target_class` reference to
`mrb_irep` struct. That means one more word consumption per `irep`.
2017-09-04 06:51:31 +09:00
Yukihiro "Matz" Matsumoto 7b88c1a8e5 Now local_variables works when for closures; fix #3710 2017-08-02 07:44:58 +09:00
Yukihiro "Matz" Matsumoto a18904a4c2 Use "$!" specifier of mrb_get_args. 2017-07-12 14:49:55 +09:00
Yukihiro "Matz" Matsumoto 877e16501c No longer need to copy argv from mrb_get_args; ref #3722 2017-06-27 22:47:26 +09:00
Yukihiro "Matz" Matsumoto c41e262667 Add write barrier to protect singleton class from GC; fix #3717 2017-06-22 01:20:22 +09:00
Yukihiro "Matz" Matsumoto a8bf3742c6 Fixed a bug that make a loop in singleton_class clone; fix #3687 2017-06-02 13:25:15 +09:00
Yukihiro "Matz" Matsumoto 9644ad51b4 Simplify backtrace mechanism; fix #3633 #3634 #3644
Instead of preserving a backtrace in `mrb_state`, `mrb_exc_set`
keeps packed backtrace in an exception object. `#backtrace` unpacks
it to an array of strings.
2017-05-23 23:50:42 +09:00
Yukihiro "Matz" Matsumoto 5513fcee22 Keep reference to mrb_context from env; fix #3619 2017-04-22 14:35:36 +09:00
Clayton Smith de96994233 Check if sc->mt is initialized before copying it. 2017-04-18 11:18:58 -04:00
Yukihiro "Matz" Matsumoto e5b61d34f6 Fixed possible SEGV in Kernel#block_given?; ref #3593 2017-04-06 10:07:53 +09:00
Yukihiro "Matz" Matsumoto a7b0ab3769 Save block argument position in e->cioff; fix #3593 2017-04-05 22:30:39 +09:00
Yukihiro "Matz" Matsumoto f5632f2f12 Restrict recursion levels in method_missing(); fix #3556
Note this is a temporary fix. Error message generation
(including `inspect`) should be deferred until its use.
2017-04-03 10:50:31 +09:00
Yukihiro "Matz" Matsumoto b2916f1b5c Avoid mrb_check_string_type() in raising exception; fix #3506
The change may reduce flexibility, but I believe no one wants
that level of flexibility here.
2017-03-18 02:34:56 +09:00