Commit Graph

14044 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 714e8a57af bigint.c: avoid default allocation.
The digit space would be allocated on demand.
2022-07-19 00:52:54 +09:00
Yukihiro "Matz" Matsumoto 04ec65b87a mruby-numeric-ext/numeric.rb: add reference description.
- zero?
- nonzero?
- positive?
- negative?
2022-07-18 15:46:47 +09:00
Yukihiro "Matz" Matsumoto 56af812b98 mruby-numeric-ext/numeric.rb: bit predicates are implemented in Ruby now. 2022-07-18 12:59:10 +09:00
Yukihiro "Matz" Matsumoto a3f2470907 Merge pull request #5749 from dearblue/patch-5565
Corrected the number of registers in the `Class#new` method
2022-07-18 09:26:34 +09:00
Yukihiro "Matz" Matsumoto 0e530dbb63 numeric.c: fix smallint op bigint error in bitwise logical operators. 2022-07-18 08:29:52 +09:00
Yukihiro "Matz" Matsumoto 2d749f5275 mruby-compar-ext/compar.rb (clamp): update document; ref #5748 2022-07-17 18:53:55 +09:00
Yukihiro "Matz" Matsumoto 33bf027d79 mruby-compar-ext/compar.rb (clamp): support endless/beginless range.
Ref #5748
2022-07-17 18:52:59 +09:00
dearblue c621d3cb95 Corrected the number of registers in the Class#new method
`OP_SEND R4 :allocate 0` requires an an invisible `nil` block to `R5`.
If `R5` is not allocated, this can lead to unexpected results due to buffer overflow.
This problem is caused by #5565.

ref. commit 33792c2a02
2022-07-17 10:38:53 +09:00
Yukihiro "Matz" Matsumoto b1bfa1d5c8 mruby-compar-ext/compar.rb (clamp): should take ranges too; fix #5748 2022-07-17 07:49:34 +09:00
Yukihiro "Matz" Matsumoto 53f131d8f1 bigint.c: remove unnecessary break in for loop. 2022-07-16 12:26:08 +09:00
Yukihiro "Matz" Matsumoto 4f737b8afb bigint.c: adjust integer types to remove warnings. 2022-07-15 18:37:45 +09:00
Yukihiro "Matz" Matsumoto 275684cf07 bigint.c: update header commend description. 2022-07-15 18:36:47 +09:00
Yukihiro "Matz" Matsumoto 30f6ad314d bigint.c (mpz_get_str): stringify multiple digits at once.
Instead of dividing by 10, 10000 (32 bit) or 100000000 (64 bit), for
example (Karatsuba method?).
2022-07-15 13:45:17 +09:00
Yukihiro "Matz" Matsumoto d9e0f3328b bigint.c (mpz_get_str): avoid bigint division for performance. 2022-07-15 13:45:17 +09:00
Yukihiro "Matz" Matsumoto f1f8221bf3 Merge pull request #5747 from dearblue/errno-summary
Added summary for `mrbgems/mruby-errno`
2022-07-15 13:45:09 +09:00
Yukihiro "Matz" Matsumoto 1d8f4bc775 Merge pull request #5746 from dearblue/cleanup-errno
Delete unnecessary files in `mrbgems/mruby-errno`
2022-07-15 13:44:35 +09:00
Yukihiro "Matz" Matsumoto ec688b34ec Merge pull request #5745 from dearblue/neg-errno
Allow negative `errno` to be handled as well
2022-07-15 13:43:33 +09:00
Yukihiro "Matz" Matsumoto 74a3e2353b Merge pull request #5744 from dearblue/checkout-ignore
Ignore git checkout if nil commit-hash
2022-07-14 23:49:39 +09:00
dearblue b012ebfa79 Ignore git checkout if nil commit-hash
If there is no `.lock` file and no commit hash specified, avoid `git checkout --detach`.
This behavior will be the same as up to mruby-3.1.

ref. #5638
2022-07-14 21:58:20 +09:00
dearblue bd98b71668 Added summary for mrbgems/mruby-errno 2022-07-14 21:55:15 +09:00
dearblue a74b0fb62b Delete unnecessary files in mrbgems/mruby-errno
This is because it has been integrated into the mruby repository.
2022-07-14 21:53:03 +09:00
dearblue 66b72430e6 Allow negative errno to be handled as well 2022-07-14 21:49:44 +09:00
Yukihiro "Matz" Matsumoto 7733f6b246 Merge pull request #5743 from dearblue/dummy-errno
Define `Errno::EXXX` when needed
2022-07-12 18:16:28 +09:00
Yukihiro "Matz" Matsumoto 37c2f080f0 numeric.c (int_to_s): should not bypass base range check. 2022-07-12 14:48:36 +09:00
Yukihiro "Matz" Matsumoto bae11ef689 complex.c (mrb_complex_copy): allow copying of complex numbers. 2022-07-11 11:25:31 +09:00
Yukihiro "Matz" Matsumoto 67f47c9b42 rational.c (mrb_rational_copy): allow copying of rational numbers. 2022-07-11 11:19:22 +09:00
Yukihiro "Matz" Matsumoto 3ebb55b75f bigint.c (mrb_bint_copy): allow dup operation for bigints. 2022-07-11 11:02:27 +09:00
Yukihiro "Matz" Matsumoto 95610a292b bigint.c (lzb): use __builtin_clz() if available. 2022-07-11 08:01:52 +09:00
Yukihiro "Matz" Matsumoto 3046440b5a bigint.c (mpz_set_int): remove an unused local variable. 2022-07-11 08:01:18 +09:00
dearblue c14e26d79e Define Errno::EXXX when needed
If the `Errno::EXXX` class is defined minimally when needed, it will save about 17 KiB of RAM in a 32-bit environment.
Define the singular methods `.const_defined?`, `.const_missing` and `.constants` in the `Errno` module and act as if there are classes that have not yet been defined.

However, if real classes are enumerated, for example by the following code, the effect is lost.

```ruby
Errno.constants.map { |id| Errno.const_get(id) }
```

But I believe that such codes are rarely written with the intention of being written.

In this patch, the `Errno::EXXX#initialize` method is no longer defined for further memory reduction.
Instead, it has been merged into the `SystemCallError#initialize` method.
2022-07-10 20:53:55 +09:00
Yukihiro "Matz" Matsumoto 04b153a3b1 bigint.c (mpz_init_set_int): unified with mpz_set_int(). 2022-07-10 08:06:55 +09:00
Yukihiro "Matz" Matsumoto 84d73ba6e8 bigint.c: small refactoring (removing extra lines and spaces). 2022-07-09 19:33:39 +09:00
Yukihiro "Matz" Matsumoto e157a84418 bigint.c (mpz_init_set_int): should avoid integer overflow.
Check MRB_INT_MIN which could overflow by negation.
2022-07-09 17:27:27 +09:00
Yukihiro "Matz" Matsumoto 48b43af37f numeric.c (mrb_div_int_value): should support integer overflow.
Especially in `MRB_INT_MIN/-1` which is bigger than MRB_INT_MAX.
2022-07-09 15:21:45 +09:00
Yukihiro "Matz" Matsumoto fa0ff7cf86 numeric.c: better error message (Float -> Integer). 2022-07-09 15:13:52 +09:00
Yukihiro "Matz" Matsumoto 7de03cbb68 numeric.c: add mrb_noreturn qualifier to error functions.
- mrb_int_zerodiv()
- mrb_int_overflow()
2022-07-09 15:12:37 +09:00
Yukihiro "Matz" Matsumoto e1980d7596 numeric.c (mrb_div_int): separate the function in two.
- mrb_div_int() does integer division in Ruby way (mdiv)
  returns mrb_int
- mrb_div_int_value() division with zero div and overflow checks.
  returns mrb_value
2022-07-09 14:38:18 +09:00
Yukihiro "Matz" Matsumoto f1275803c9 bigint.c (mpz_set): simplify memory reallocation code. 2022-07-09 14:36:17 +09:00
Yukihiro "Matz" Matsumoto a40842eb73 bigint.c (udiv): use (signed) int for loop counters.
Sometimes (xd-yd) may be negative and should be checked.
2022-07-09 10:56:02 +09:00
Yukihiro "Matz" Matsumoto a64d2bfbe6 bigint.c (mpz_mul,mpz_mdiv): return early on zero. 2022-07-09 10:47:23 +09:00
Yukihiro "Matz" Matsumoto a2f0fd81e6 numeric.c (mrb_int_mul): fix error message (Float -> Integer). 2022-07-09 10:45:44 +09:00
Yukihiro "Matz" Matsumoto 8d34981530 numeric.c: avoid mathematical operations for simple cases. 2022-07-09 10:45:11 +09:00
Yukihiro "Matz" Matsumoto 960021e519 numeric.c (cmpnum): call mrb_bigint_cmp() if v1 is bigint, not v2. 2022-07-08 21:57:05 +09:00
Yukihiro "Matz" Matsumoto 872020bb3d math.gembox: add cmath and bigint to math gembox; ref #5742 2022-07-07 15:39:36 +09:00
Yukihiro "Matz" Matsumoto b5538eded1 vm.c (OP_ENTER): need to protect kdict from GC; ref #5741 2022-07-06 14:57:06 +09:00
Yukihiro "Matz" Matsumoto 8fed80f5eb vm.c (OP_ENTER): protect kdict from GC; ref #5741 2022-07-06 14:29:14 +09:00
Yukihiro "Matz" Matsumoto 4225ae4176 vm.c (OP_ENTER): need to update ci->nk when kd is set; fix #5741 2022-07-06 13:57:12 +09:00
Yukihiro "Matz" Matsumoto 7e8a4212fb vm.c: refactor OP_ENTER code; ref #5741 2022-07-06 13:37:29 +09:00
Yukihiro "Matz" Matsumoto 82a419cde3 vm.c (mrb_ci_kdict): should return -1 when no kargs given; ref #5741 2022-07-06 13:37:20 +09:00
Yukihiro "Matz" Matsumoto 638356af03 class.c (mc_clear_by_id): clear method cache with method id specified. 2022-07-05 17:39:36 +09:00