summaryrefslogtreecommitdiffhomepage
path: root/src/class.c
AgeCommit message (Collapse)Author
2020-10-12Restore old function names for compatibility; ref #5070Yukihiro "Matz" Matsumoto
- `mrb_check_intern()` to return `mrb_value` - `mrb_intern_check()` to return `mrb_sym` [NEW] Other new functions: - `mrb_intern_check_cstr()` - `mrb_intern_check_str()`
2020-10-12Update `mrb_get_args()` keyword argument support [incompatible]Yukihiro "Matz" Matsumoto
* `mrb_kwargs` structure reordered (`values` and `rest` come last) * take symbols instead of C `char*`
2020-10-12Silence warnings from implicit integer conversions.Yukihiro "Matz" Matsumoto
Caused from combination of `mrb_int`, `int` and `size_t`..
2020-10-12Replace the implementation of method tables in classes/modules.Yukihiro "Matz" Matsumoto
They are basically the copy of instance variable tables. On my Linux box, memory consumption of `mrbtest` measured by `valgrind` is: - old: 17,683,830 bytes - new: 14,283,749 bytes
2020-10-12Reorganize `Integer` system.Yukihiro "Matz" Matsumoto
- Integrate `Fixnum` and `Integer` - Remove `Integral` - `int / int -> int` - Replace `mrb_fixnum()` to `mrb_int()` - Replace `mrb_fixnum_value()` to `mrb_int_value()`. - Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12Change the return type of `mrb_check_intern()` and friends.Yukihiro "Matz" Matsumoto
They used to return `mrb_value` but now return `mrb_sym` for consistency with other `intern` functions. If symbols are not defined, `check` functions return `0`, instead of `nil` in the past. It causes API incompatibility but I believe few people use those functions out of the core, and those changes are very easy to handle, hopefully.
2020-10-12Rename `MRB_TT_FIXNUM` to `MRB_TT_INTEGER`.Yukihiro "Matz" Matsumoto
We still have `#define MRB_TT_FIXNUM MRB_TT_INTEGER` for compatibility.
2020-10-12Integrate `Fixnum` class into `Integer` classdearblue
* The `Fixnum` constant is now an alias for the `Integer` class. * Remove `struct mrb_state::fixnum_class` member. If necessary, use `struct mrb_state::integer_class` instead.
2020-10-12Rename float configuration option names.Yukihiro "Matz" Matsumoto
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT` - `MRB_USE_FLOAT` => `MRB_USE_FLOAT32` The former is to use `USE_XXX` naming convention. The latter is to make sure `float` is 32bit float and not floating point number in general.
2020-10-12Add assertion we can pack function pointers in `mrb_method_t`.Yukihiro "Matz" Matsumoto
If this assertion fails, you have to define `MRB_USE_METHOD_T_STRUCT`.
2020-10-12Adjust PR #5060 to the latest `mruby3` branch.Yukihiro "Matz" Matsumoto
2020-10-12Remove `mc_clear_by_id`.Yukihiro "Matz" Matsumoto
Clearing all method cache using `memset` is faster than conditional clear by method id.
2020-10-12Use `memset()` to clear method cache.Yukihiro "Matz" Matsumoto
2020-10-12Enable method cache by default.Yukihiro "Matz" Matsumoto
Introduced `MRB_NO_METHOD_CACHE` which is inverse of `MRB_METHOD_CACHE` that should be enabled intestinally. In addition, the default cache is made bigger (128 -> 256).
2020-10-12Constify `irep` struct for `Class#new`.Yukihiro "Matz" Matsumoto
2020-10-12Generate C struct from `irep` instead of binary dump.Yukihiro "Matz" Matsumoto
2020-10-12Constify `irep` members.Yukihiro "Matz" Matsumoto
- `pool` - `syms` - `reps`
2020-10-12Use functions that take symbols to reduce string litrals in C.Yukihiro "Matz" Matsumoto
2020-10-12Provide functions that take symbols instead of `const char*`.Yukihiro "Matz" Matsumoto
- mrb_define_class_id - mrb_define_module_id - mrb_define_method_id - mrb_define_singleton_method_id - mrb_define_module_function_id - mrb_define_const_id - mrb_undef_method_id - mrb_undef_class_method_id - mrb_class_defined_id - mrb_class_get_id - mrb_class_defined_under_id - mrb_class_get_under_id - mrb_module_get_id - mrb_module_get_under_id - mrb_define_class_under_id - mrb_define_module_under_id - mrb_exc_get_id
2020-10-12Add functions that take symbols as arguments.Yukihiro "Matz" Matsumoto
- :
2020-10-12Add `MRB_SYM()` for inline symbols.Yukihiro "Matz" Matsumoto
2020-09-25Prohibit string changes by "s"/"z" specifier of `mrb_get_args()`dearblue
- The `s` specifier is a string pointer obtained without performing `mrb_str_modify()`, so it cannot be changed. - The `z` specifier cannot be changed because it is a string pointer obtained by `RSTRING_CSTR()` which returns `const char *`.
2020-07-19Use `c` specifier for `mrb_get_args`.Yukihiro "Matz" Matsumoto
2020-07-19Add new specifier `c` to `mrb_get_args`.Yukihiro "Matz" Matsumoto
`C` retrieves a `mrb_value` that refers a class/module. `c` retrieves a `struct RClass*` pointer to a class/module.
2020-06-20Move definition of `BasicObject#!=` to `mrblib`.Yukihiro "Matz" Matsumoto
C implementation used `mrb_funcall()` that bypassed many optimization.
2020-06-20Add `mrb_get_arg1()` that retrieves single (and only) argument.Yukihiro "Matz" Matsumoto
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one argument. And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
2020-04-29Makes `mrb_any_to_s()` accept an object whose class is `NULL`dearblue
When using `mrb_any_to_s()` for debugging purposes, giving an object whose class is `NULL` no longer causes a SIGSEGV and no crash. This is achieved by making `mrb_class_name()` and `mrb_str_cat_cstr()` null safe.
2020-04-22Add new function `mrb_singleton_class_ptr()`; ref #4973Yukihiro "Matz" Matsumoto
The difference between `mrb_singleton_class` and `mrb_singleton_class_ptr`: - `mrb_singleton_class_ptr` returns `struct RClass*`. - `mrb_singleton_class_ptr` returns `NULL` on immediate values where `mrb_singleton_class` raises exceptions.
2020-01-10Fixed wrong condition in #4926 fix.Yukihiro "Matz" Matsumoto
2020-01-10Fixed wrong condition for copying arguments on stack; fix #4926Yukihiro "Matz" Matsumoto
This bug was introduced in 694089f to address #4832
2020-01-02Call `va_end()` before returndearblue
The behavior when returning from a function without `va_end()` is undefined.
2020-01-01Integrate `i` and `arg_i` in `mrb_get_args()`dearblue
The behavior of these two variables is the same.
2019-12-25Fix potentially use of wrong method cacheKOBAYASHI Shuji
#### Example (with `MRB_METHOD_CACHE`) ```ruby GC.start c = Class.new p c #=> #<Class:0x7fd6a180e790> c.new #=> cache `c.new` c = nil GC.start #=> `c` is GCed r = Range.dup p r #=> #<Class:0x7fd6a180e790> # [same pointer as `c`] r.new(2, 3) #=> ArgumentError: 'initialize': # wrong number of arguments (2 for 0) # [`c.new` is called instead of `r.new`] ``` #### Cause An entry of method cache is identified by class pointer and method id. However, reusing memory after GC may create a class with the same pointer as the cached class. #### Treatment Cleared method caches of the class when the class is GCed.
2019-12-14Remove module only methods from classdearblue
The `#prepend_features` and `#module_function` methods are not haves for class objects.
2019-12-09Fix `mrb_get_argv()` to return array pointer every time; fix #4832Yukihiro "Matz" Matsumoto
2019-12-07Fix keyword arguments not be obtained with `mrb_get_args()`; Fix #4754dearblue
If ":" is after "|" and there is no "?" or "*", the keyword argument could not be obtained and it was not initialized with `undef`. For example: "|oo:"
2019-11-16Revert "Implement Ruby2.7's frozen strings from `Symbol#to_s`"KOBAYASHI Shuji
This feature was reverted from Ruby 2.7.
2019-10-20Use `mrb_str_cat_str` instead of `mrb_str_concat` if possibleKOBAYASHI Shuji
2019-10-19Fix that `Module#to_s` may return frozen string; ref 08eafe2KOBAYASHI Shuji
2019-10-13Refactor `mrb_class_name_class`KOBAYASHI Shuji
- Use `mrb_sym_name_len` instead of `mrb_sym_name` (class name should not be escaped). - Avoid `mrb_str_dup` (it is unnecessary to be shared string because it is changed).
2019-10-08Implement Ruby2.7's frozen strings from `Module#name`KOBAYASHI Shuji
2019-10-06Get keyword arguments with `mrb_get_args()`dearblue
Keyword arguments can now be retrieved with the `:` specifier and `mrb_kwargs` data. For the interface, I referred to CRuby's `rb_get_kwargs()`. For implementation, I referred to `OP_KARG` or etc.
2019-10-04Implement Ruby2.7's frozen strings from `Symbol#to_s`.Yukihiro "Matz" Matsumoto
2019-09-26Use type predicate macros instead of `mrb_type` if possibleKOBAYASHI Shuji
For efficiency with `MRB_WORD_BOXING` (implement type predicate macros for all `enum mrb_vtype`).
2019-09-25Rename symbol-to-string functions; close #4684Yukihiro "Matz" Matsumoto
* mrb_sym2name -> mrb_sym_name * mrb_sym2name_len -> mrb_sym_name_len * mrb_sym2str -> mrb_sym_str
2019-09-18Fix `super` from aliased methods to work correctly; fix #4718Yukihiro "Matz" Matsumoto
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-16Shrink `mrb_get_args()`dearblue
As a side effect, all specifiers now accept the `!` modifier.
2019-09-16Cache argv first in each specifiers for `mrb_get_args()`; ref #3090dearblue
In terms of specifiers, argv is never referenced after a method call as shown in #3090. Reduction of object code can be expected. If you need to refer to argv after a method call in the same loop, update argv after the method call.
2019-09-16Raise `ArgumentError` by `aspec` check; ref #4688Yukihiro "Matz" Matsumoto
This is partial `aspec` check that only checks `MRB_ARGS_NONE()`.
2019-09-14Use `%C` to `mrb_name_error` in `mrb_method_search`; ref 5890c7d5KOBAYASHI Shuji