62 Commits

Author SHA1 Message Date
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
cubicdaiya 80d8170959 remove unused variable
GLOBAL_RAND_SEED_KEY is no longer used.
2014-03-05 17:19:26 +09:00
mattn d59b738b43 Fix #1793 2014-03-04 22:25:25 +09:00
Tatsuya Matsumoto d496ba7e25 fix a memory leak in mruby-random. 2014-03-02 22:18:02 +09:00
cubicdaiya 67de10bfcb use C style comments instead of C++ style comments
According to CONTRIBUTING.md,

Don't use C++ style comments

 /* This is the prefered comment style */

Use C++ style comments only for temporary comment e.g. commenting out some code lines.
2014-03-01 03:31:45 +09:00
chasonr 7c9ff7c8ff Implement default Random instance.
Previously, the default random number generator was implemented using static
storage.  This storage is common to all instances of mruby in a process, and
use of the default random number generator in one instance will perturb the
default random number generator in other instances.  It is also not thread
safe.

With this change, the default random number generator is defined as
Random::DEFAULT, as it is in CRuby.
2014-02-25 00:06:31 -05:00
take_cheeze f863025bd6 use 'd' format spec to get Random object 2014-02-21 17:36:58 +09:00
take_cheeze d345134fb8 use mrb_intern_lit in mruby-random 2014-02-21 17:07:48 +09:00
cubicdaiya 3d716f2376 Give the type 'void' to functions have no argument.
According to the C standard,
it is desirable to give the type 'void'
to functions have no argument.
2014-02-14 19:47:15 +09:00
cremno aa655b9ee1 remove superfluous includes
- reduce compile time by a little bit (full-core: ~0.7s for me)
- thanks to 'include-what-you-use' for some help
- include Standard C header files before any other (coding style)
2014-01-07 17:56:30 +01:00
Yukihiro "Matz" Matsumoto 9c6398a444 rename mrb_intern2() to mrb_intern(); huge API incompatibility; close #1513 2013-11-29 08:47:28 +09:00
bggd 86c80139ab Changed a variable declaration to top of block 2013-11-13 22:35:25 +09:00
Yukihiro "Matz" Matsumoto 1910798f47 small style fix 2013-11-03 08:34:36 +09:00
Emiliano Lesende 80d8b5e2e7 Added support for Random as an argument to shuffle and shuffle!. Refactored random gem to use DATA instance type and hold mt_state inside the DATA_PTR instead of in an instance variable. 2013-11-02 12:07:34 -03:00
Emiliano Lesende d8cc37cdf9 Added shuffle and shuffle! to the Array class in the Random gem. 2013-11-01 11:44:40 -03:00
Yukihiro "Matz" Matsumoto b225e4cc82 redesign mruby/data.h API; use DATA_PTR() for raw data pointer, DATA_GET_PTR() to type safe retrieval (TypeError will be raised), DATA_CHECK_GET_PTR() to get nil if type mismatched 2013-08-15 01:33:36 +09:00
Tomoyuki Sahara 116f75a8ce "spec.author" is better for single-author gems.
"spec.author=" expects a String represents a single author.
"spec.authors=" expects an Array which is a list of multiple authors.

http://guides.rubygems.org/specification-reference/
2013-07-23 10:09:24 +09:00
Jun Hiroe e8b31f286b Replace mrb_intern() with mrb_intern2() in random.c 2013-07-14 01:09:38 +09:00
kimu_shu e720782f81 Add MRB_WORD_BOXING mode (represent mrb_value as a word) 2013-05-26 10:09:17 +09:00
Yukihiro "Matz" Matsumoto 22469f3be1 use mrb_free to free random state 2013-04-29 09:13:30 +09:00
Yukihiro "Matz" Matsumoto 975d52d804 fix memory leaks in mruby-random 2013-04-29 09:11:38 +09:00
Yukihiro "Matz" Matsumoto 30d580ecbc rename every ARGS_XXX to MRB_ARGS_XXX; ref #1206 2013-04-25 09:47:36 +09:00
MATSUMOTO Ryosuke d2c88fe850 Change mruby-random License to MIT
refs: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/license.html
2013-04-08 16:55:05 +09:00
Yukihiro "Matz" Matsumoto 75f5535c4f rename DATA API: mrb_get_datatype -> mrb_data_get_ptr; mrb_check_datatype -> mrb_data_check_and_get 2013-04-04 04:30:39 +09:00
Carson McDonald 61a8a61828 Use mrb_check_datatype directly to avoid warning. 2013-03-27 09:44:16 -04:00