Commit Graph

86 Commits

Author SHA1 Message Date
John Bampton f7c5c00d6e 🔒 Fix missing HTTPS on links 2020-12-19 17:36:39 +10:00
Yukihiro "Matz" Matsumoto 5134031e18 Use mrb_int_value() instead of mrb_fixnum_value().
Where fixnum overflow can happen.
2020-10-12 18:20:05 +09:00
Yukihiro "Matz" Matsumoto 3e71359d7a Update mruby-random gem to support 32 bit platforms.
`sizeof(rand_state)` had been bigger than `sizeof(void*)*3`. Changed
random number generator to `Xorshift96` on 32 bit platforms.
2020-10-12 18:20:04 +09:00
Yukihiro "Matz" Matsumoto 2b188ed8a1 Reorganize Integer system.
- 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-12 18:19:54 +09:00
dearblue 80fe9838d2 Integrate Fixnum class into Integer class
* 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-12 16:21:44 +09:00
Yukihiro "Matz" Matsumoto 44a07393f4 Use xoshiro128++ instead of xorshift96/128. 2020-10-12 16:21:41 +09:00
Yukihiro "Matz" Matsumoto 0b22bf4a89 Fix rand_real to return random number [0,1) not [0,1]. 2020-10-12 16:21:41 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `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-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto 67d92c48b5 Avoid breaking the result array by side-effect in C++. 2020-10-12 16:21:31 +09:00
Yukihiro "Matz" Matsumoto 2a366ffba8 Use functions that take symbols to reduce string litrals in C. 2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto eddd324979 Add MRB_SYM() for inline symbols. 2020-10-12 16:20:41 +09:00
Rory OConnell 3cf48713a2 Work around more MSC optimzer bugs 2020-06-29 14:25:59 -07:00
Rory OConnell b1017b2651 Reduce scope of volatile keyword for MSC bug 2020-06-26 21:44:31 -07:00
Rory OConnell b8d896e56a Narrower scope working around MSC bug 2020-06-26 21:16:17 -07:00
Rory OConnell db296e9593 work around MSC optimization generating non functional code 2020-06-26 15:13:04 -07: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
KOBAYASHI Shuji 7993b87235 Fix build of mruby-random on 32-bit mode 2019-08-27 10:48:25 +09:00
KOBAYASHI Shuji 7178a5e7d3 Fix Array#sample with MRB_INT32
Array index became potentially negative because `uint32_t` is cast to
`mrb_int`.
2019-08-26 20:23:46 +09:00
KOBAYASHI Shuji b9350f908f Remove unused random.h 2019-08-26 18:08:32 +09:00
Yukihiro "Matz" Matsumoto 866a9e6481 Use MRB_TT_ISTRUCT for Random to reduce memory.
When the size of Xorshift128 seed (`sizeof(uint32)*4`) is bigger than
ISTRUCT_DATA_SIZE, `Random` uses Xorshift96 instead.
2019-07-24 10:48:00 +09:00
Yukihiro "Matz" Matsumoto f99e9963b2 Switch random generator from Mersenne Twister to Xorshit128.
Now `rand` can be used with `MRB_WITHOUT_FLOAT`; ref #4576
2019-07-22 15:49:59 +09:00
dearblue c96b517ea2 Error needed/conflicts configuration
The purpose is to clarify the error if there is a needed/conflicts
configuration at compile time.
2019-07-14 00:29:17 +09:00
KOBAYASHI Shuji 2ae727ac3a Add Array#sample test
And simplify tests for `Array#shuffle` and `Array#shuffle!`.
2019-04-17 21:04:46 +09:00
KOBAYASHI Shuji d53eb8a377 Fix missing assertions in mruby-random test 2019-04-15 19:03:39 +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
dearblue 366848996a Clear terminated space 2018-09-07 22:32:34 +09:00
Christopher Aue 2fadddcd20 Replaced tabs with spaces 2017-08-09 21:56:27 +02:00
Yukihiro "Matz" Matsumoto f26d00d9e8 Embed small size array elements in the heap.
It reduces the memory consumption and sometimes improve the
performance as well.  For example, the consumed memory size
of `bench/bm_ao_render.rb` is reduced from 1.2GB to 1GB, and
its total execution time become 18.795 sec from 22.229 sec.
2017-07-27 16:13:06 +09:00
Clayton Smith a8ccda5692 Fetch arguments earlier to avoid a crash. 2017-02-02 16:35:59 -05:00
Bouke van der Bijl c7262be0ae Fix segfault in Array#sample 2016-11-23 11:21:14 -05:00
Nobuyoshi Nakada 6511bfd79a Removed trailing spaces 2016-09-28 12:29:41 +09:00
Yukihiro "Matz" Matsumoto b3236b2a71 mruby-random: fixed typos 2016-08-30 10:52:44 +09:00
Yukihiro "Matz" Matsumoto fa76bbeb07 mruby-random: add reporting URL since we modified the source 2016-08-30 09:03:14 +09:00
Yukihiro "Matz" Matsumoto af4567bb41 update copyright notice and license description for mt19937ar.[ch]
despite the fact original authors agreed to distribute their work
under MIT license, it does not mean mt19937ar.[ch] became the work
of mruby developers. To clarify, we updated copyright and license
notice of the source files.
2016-08-08 12:38:21 +09:00
Yukihiro "Matz" Matsumoto 8a74e68552 mruby-random: fixed wrong fixnum conversion 2016-01-21 03:31:08 +09:00
Yasuhiro Matsumoto f0205e1182 rename include blocker 2015-12-25 13:43:01 +09:00
Yukihiro "Matz" Matsumoto 5c405dea3d include changed from by quotes ("") to by brackets (<>); close #3032 2015-11-27 17:48:23 +09:00
Yukihiro "Matz" Matsumoto 48c5321dca constify pointer from RARRAY_PTR to detect potential write barrier bugs.
if you see compiler errors due to this commit, you'd better to use array-modifying
functions, e.g. mrb_ary_set() or mrb_ary_push(), otherwise you might see nasty
GC bugs in the future.  if you are sure what you are doing, replace `RARRAY_PTR(ary)`
by `mrb_ary_ptr(ary)->ptr`. but be warned.
2014-09-12 12:42:39 +09:00
take_cheeze b3d0585fe5 Add API mrb_data_init to initialize MRB_TT_DATA tagged instance. 2014-08-20 22:42:35 +09:00
Yukihiro "Matz" Matsumoto 61ce5892cc remove spaces after open parens 2014-07-12 20:36:45 +09:00
Santa Zhang 17ecbaa23d add a few const qualifier 2014-06-25 07:53:23 +09:00
kyab 203740bac5 Pacify MSVC warnings for random.c 2014-05-10 23:50:57 +09:00
Nobuyoshi Nakada ab67c57f65 remove trailing spaces 2014-04-30 09:50:14 +09:00
take_cheeze c73f8d4def move summary of mrbgems in default gembox to its spec 2014-03-17 00:34:24 +09:00
take_cheeze bbb7ba46b2 don't use of anonymous unions 2014-03-11 22:01:00 +09:00
ksss 49a048c544 set bit field for mrb_bool 2014-03-10 13:14:07 +00:00
take_cheeze 77fba20480 reduce mrb_open calls in mrbgem test 2014-03-10 04:45:28 +09:00
Yukihiro "Matz" Matsumoto 6a23be7805 add data_type check to mruby-random 2014-03-09 01:22:53 +09:00
Yukihiro "Matz" Matsumoto 9a89a82048 refactoring mruby-random 2014-03-09 01:21:57 +09:00
Yukihiro "Matz" Matsumoto ae65c7da58 implement Array#sample in mruby-random gem 2014-03-09 01:03:34 +09:00