summaryrefslogtreecommitdiffhomepage
path: root/src/object.c
AgeCommit message (Collapse)Author
2022-01-05object.c: Call functions directly from `mrb_ensure_int_type()`; #5622Yukihiro "Matz" Matsumoto
2021-12-31Call functions directly from `mrb_ensure_float_type()`dearblue
ref. commit 7f40b645d2773c8f50c48ae4adf90488e164da55 Currently, the build configurations `MRB_USE_COMPLEX` and `MRB_USE_RATIONAL` are not listed in the documentation. In other words, they are hidden settings. They are defined in `mrbgems/mruby-{complex,rational}/mrbgem.rake`. So this patch assumes that it is safe to refer to these functions in core-gems directly from core functions. However, applications that link with `libmruby_core.a` will have compatibility issues. In fact, `mrbgems/mruby-bin-mrbc` links with `libmruby_core.a`, so I had to prepare a dummy function.
2021-12-31object.c: add conversion to Float from Rational, Complex; #5620Yukihiro "Matz" Matsumoto
2021-12-29object.c: move string to float conversion to `mrb_f_float`.Yukihiro "Matz" Matsumoto
2021-12-29object.c: introduce `mrb_ensure_{int,float}_type`.Yukihiro "Matz" Matsumoto
Since `mrb_to_integer` and `mrb_to_float` does not convert the object but checks types, they are named so by historical reason. We introduced properly named functions. This commit obsoletes the following functions: * mrb_to_integer() * mrb_to_int() * mrb_to_float() Use `mrb_ensure_int_type()` instead for the first 2 functions. Use `mrb_ensure_float_type()` for the last.
2021-12-29object.c: avoid implicit `to_i` and `to_f` calls.Yukihiro "Matz" Matsumoto
mruby have removed `to_int` implicit conversion, so `mrb_to_integer` should not call `to_i` for conversion.
2021-11-04hash.c: avoid `mrb_obj_id` to get the hash value if possible.Yukihiro "Matz" Matsumoto
2021-11-01object.c: fast implementation of `mrb_obj_eq`.Yukihiro "Matz" Matsumoto
For `MRB_NAN_BOXING` and `MRB_WORD_BOXING`.
2021-09-07object.c: rename `mrb_to_int` to `mrb_to_integer`.Yukihiro "Matz" Matsumoto
Consistent naming: `integer` to represent integer packed in `mrb_value` instead of `int`.
2021-09-01mruby.h: obsolete `mrb_to_str()`.Yukihiro "Matz" Matsumoto
Replace them by `mrb_ensure_string_type()`.
2021-09-01object.c: remove `mrb_convert_to_integer()' function.Yukihiro "Matz" Matsumoto
And merged to `mrb_f_integer()` which is only usage of the function.
2021-09-01mruby.h: reorganize `mrb_ensure/check` functions in headers.Yukihiro "Matz" Matsumoto
2021-06-20Use `MRB_VTYPE_FOREACH()` in `src/object.c`dearblue
2021-05-17Global renaming regarding `integer` and `float`.Yukihiro "Matz" Matsumoto
Consistent number conversion function names: * `mrb_value` to immediate (C) value * `mrb_int()` -> `mrb_as_int()` * `mrb_to_flo()` -> `mrb_as_float()` * `mrb_value` to `mrb_value` (converted) * `mrb_to_int()' * `mrb_Integer()` - removed * `mrb_Float()` -> `mrb_to_float` Consistent function name (avoid `_flo` suffix): * `mrb_div_flo()` -> `mrb_div_float`
2021-05-17Rename `mrb_flo_to_fixnum` to `mrb_float_to_integer`.Yukihiro "Matz" Matsumoto
2021-05-11Remove the obsolete term `Fixnum`.Yukihiro "Matz" Matsumoto
Except for compatibility code.
2021-03-19rational.c: overhaul rational operators.Yukihiro "Matz" Matsumoto
- define `MRB_TT_RATIONAL` - change object structure (`struct RRational`) - add memory management for `MRB_TT_RATIONAL` - avoid operator overloading as much as possible - implement division overloading in C - as a result, performance improved a lot
2021-02-14Fix type tag that set to `NilClass` and `FalseClass`KOBAYASHI Shuji
2021-01-26Revert "Minimize the changes in #5277"Yukihiro "Matz" Matsumoto
This reverts commit dc51d89ac22acc60b9bfeed87115863565b74085.
2021-01-22Minimize the changes in #5277Yukihiro "Matz" Matsumoto
Instead of including `mruby/presym.h` everywhere, we provided the fallback `mruby/presym.inc` under `include/mruby` directory, and specify `-I<build-dir>/include` before `-I<top-dir>/include` in `presym.rake`. So even when someone drops `-I<build-dir>/include` in compiler options, it just compiles without failure.
2021-01-11Avoid including `presym.inc` in existing header filesKOBAYASHI Shuji
Addressed an issue where existing programs linking `libmruby.a` could only be built by adding `<build-dir>/include` to compiler's include path.
2020-11-13Change name and usage of presym macrosKOBAYASHI Shuji
To be also able to build mruby without presym in the future. However, `MRB_QSYM` has been removed and changed as follows: ### Example | Type | Symbol | Previous Style | New Style | |---------------------------|--------|------------------|----------------| | Operator | & | MRB_QSYM(and) | MRB_OPSYM(and) | | Class Variable | @@foo | MRB_QSYM(00_foo) | MRB_CVSYM(foo) | | Instance Variable | @foo | MRB_QSYM(0_foo) | MRB_IVSYM(foo) | | Method with Bang | foo! | MRB_QSYM(foo_b) | MRB_SYM_B(foo) | | Method with Question mark | foo? | MRB_QSYM(foo_p) | MRB_SYM_Q(foo) | | Mmethod with Equal | foo= | MRB_QSYM(foo_e) | MRB_SYM_E(foo) | This change makes it possible to define, for example, `MRB_IVSYM(foo)` as `mrb_intern_lit(mrb, "@" "foo")`, which is useful if we support building without presym in the future.
2020-10-12Use `NULL` instead of `0`; close #2467Yukihiro "Matz" Matsumoto
The PR was from @cubicdaiya.
2020-10-12Restore old function names for compatibility; fix #5070Yukihiro "Matz" Matsumoto
Rename new functions: - `mrb_convert_type(mrb,val,type,tname,method)` => `mrb_type_convert(mrb,val,type,tname,method)` - `mrb_check_convert_type(mrb,val,type,tname,method)` => `mrb_type_convert_check(mrb,val,type,tname,method)` Old names are defined by macros (support `tname` drop and `char*` => `mrb_sym` conversion).
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-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-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-12Change the arguments of following implicit conversion functions:Yukihiro "Matz" Matsumoto
- `mrb_convert_type` - `mrb_check_convert_type` Those function no longer take `tname` string representation of desired type, and take method symbols instead of `const char*` names. This is incompatible change. I hope no third-party gems use those functions.
2020-10-12Use `mrb_funcall_id()` extensively.Yukihiro "Matz" Matsumoto
Except for support files e.g. `mruby-test/driver.c`, which are not target of symbol collection via `rake gensym`.
2020-07-06Avoid infinite loop when converting objects to strings.Yukihiro "Matz" Matsumoto
2020-06-20Support integer and float combination in `mrb_equal()`.Yukihiro "Matz" Matsumoto
2020-06-15Remove unused `MRB_TT_FILE`.Yukihiro "Matz" Matsumoto
2019-10-31Set `MRB_STR_ASCII` flag to some stringize methodsKOBAYASHI Shuji
- `Fixnum#to_s`, `Fixnum#inspect` - `Float#to_s`, `Float#inspect` - `NilClass#to_s`, `NilClass#inspect` - `FalseClass#to_s`, `FalseClass#inspect` - `TrueClass#to_s`, `TrueClass#inspect` - `Time#to_s`, `Time#inspect`
2019-10-20Use `mrb_str_cat_str` instead of `mrb_str_concat` if possibleKOBAYASHI Shuji
2019-10-04Freeze strings from `nil.to_s`, `true.to_s`, `false.to_s`.Yukihiro "Matz" Matsumoto
This is an experimental changes in Ruby 2.7.
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-08-05Use new specifiers/modifiers of `mrb_vfromat()`KOBAYASHI Shuji
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-05-11Use `mrb_ensure_string_type` in `mrb_to_str`KOBAYASHI Shuji
2019-03-02Do not apply `mrb_ptr()` to immediate objects; fix #4307Yukihiro "Matz" Matsumoto
2018-11-19Restore `mrb_string_type` function for compatibility.Yukihiro "Matz" Matsumoto
2018-11-19Removed `to_hash` conversion method.Yukihiro "Matz" Matsumoto
2018-11-19Removed `to_ary` conversion method.Yukihiro "Matz" Matsumoto
2018-11-19Remove implicit conversion using `to_str` method; fix #3854Yukihiro "Matz" Matsumoto
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-19Remove implicit conversion using `to_int` method.Yukihiro "Matz" Matsumoto
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-02-13Check if `to_int` returns `fixnum` value; fix #3946Yukihiro "Matz" Matsumoto
2017-10-11Add MRB_WITHOUT_FLOATYAMAMOTO Masaya
2017-09-27fix: mrbgems\mruby-kernel-ext\src\kernel.c(114): warning C4244: 'function': ↵Tomasz Dąbrowski
conversion from 'mrb_int' to 'int', possible loss of data
2017-08-18Separate `mrb_str_buf_new` and `mrb_str_new_capa`.Yukihiro "Matz" Matsumoto
`mrb_str_buf_new` is an old function that ensures capacity size of `MRB_STR_BUF_MIN_SIZE` minimum. Usually one need to use `mrb_str_new_capa` instead.
2017-05-26Add new range check macro FIXABLE_FLOAT(); ref #3652Yukihiro "Matz" Matsumoto
When MRB_INT64, valid value range of mrb_int is bigger than double, which only has 53 bits significant precision.
2017-04-11Fixed a bug in `mrb_convert_to_integer()`; fix #3581Yukihiro "Matz" Matsumoto
Did not update the result from `mrb_check_string_type()` before string-to-integer conversion.