summaryrefslogtreecommitdiff
path: root/random.c
AgeCommit message (Collapse)Author
2021-01-10Remove possibility of using same seedsNobuyoshi Nakada
2020-12-21Random instance methodszverok
Notes: Merged: https://github.com/ruby/ruby/pull/3966
2020-12-14Deprecate Random::DEFAULTBenoit Daloze
* Closes [Feature #17351].
2020-12-14Remove references to Random::DEFAULT in the documentationBenoit Daloze
* Random::DEFAULT is no longer a Random instance, and referencing it is more confusing than helpful. Related to [Feature #17351]
2020-12-01ractor local storage C-APIKoichi Sasada
To manage ractor-local data for C extension, the following APIs are defined. * rb_ractor_local_storage_value_newkey * rb_ractor_local_storage_value * rb_ractor_local_storage_value_set * rb_ractor_local_storage_ptr_newkey * rb_ractor_local_storage_ptr * rb_ractor_local_storage_ptr_set At first, you need to create a key of storage by rb_ractor_local_(value|ptr)_newkey(). For ptr storage, it accepts the type of storage, how to mark and how to free with ractor's lifetime. rb_ractor_local_storage_value/set are used to access a VALUE and rb_ractor_local_storage_ptr/set are used to access a pointer. random.c uses this API. Notes: Merged: https://github.com/ruby/ruby/pull/3822
2020-11-27Use opaque struct pointer than voidNobuyoshi Nakada
2020-11-27mark default_randKoichi Sasada
default_rand can points a Bignum seed, so it should be marked.
2020-11-27per-ractor Random::DEFAULTKoichi Sasada
Random generators are not Ractor-safe, so we need to prepare per-ractor default random genearators. This patch set `Random::DEFAULT = Randm` (not a Random instance, but the Random class) and singleton methods like `Random.rand()` use a per-ractor random generator. [Feature #17322] Notes: Merged: https://github.com/ruby/ruby/pull/3813
2020-11-27[DOC] Mersenne Twister isn't cryptographically secure [ci skip]Nobuyoshi Nakada
2020-10-09rb_const_set sets the class path nowNobuyoshi Nakada
2020-09-07Added `rb_random_base_init`Nobuyoshi Nakada
To enclose the initialization of Random::Base part. Notes: Merged: https://github.com/ruby/ruby/pull/3024
2020-09-07Added WITH_REAL macrosNobuyoshi Nakada
Added `WITH_REAL` versions to `RB_RANDOM_INTERFACE` macros. Also these macros including "without real" versions no longer contain the terminator (semicolon and comma). Notes: Merged: https://github.com/ruby/ruby/pull/3024
2020-09-07Added `get_real` interfaceNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3024
2020-09-07Added rb_int_pair_to_realNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3024
2020-09-07separate rb_random_tNobuyoshi Nakada
* random.c: separate abstract rb_random_t and rb_random_mt_t for Mersenne Twister implementation. * include/ruby/random.h: the interface for extensions of Random class. * DLL imported symbol reference is not constant on Windows. * check if properly initialized. Notes: Merged: https://github.com/ruby/ruby/pull/3024
2020-09-07Random::BaseNobuyoshi Nakada
* random.c (InitVM_Random): introduce abstract super class Random::Base. Notes: Merged: https://github.com/ruby/ruby/pull/3024
2020-08-15RARRAY_AREF: convert into an inline function卜部昌平
RARRAY_AREF has been a macro for reasons. We might not be able to change that for public APIs, but why not relax the situation internally to make it an inline function. Notes: Merged: https://github.com/ruby/ruby/pull/3419
2020-06-29rand_range: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-04Fixed constant initializerNobuyoshi Nakada
An expression using `static const` value seems not considered as `static const` by Visual C.
2020-05-04Make int-pair-to-real conversion more portableNobuyoshi Nakada
And utilize more bits even if DBL_MANT_DIG > 53.
2020-04-08Disable deprecation error on mingwNobuyoshi Nakada
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-01-10Ensure seed data to be clearedNobuyoshi Nakada
To prevent from leaking the seed data. Notes: Merged: https://github.com/ruby/ruby/pull/2826
2020-01-10Fill siphash salt directly with random dataNobuyoshi Nakada
Expanding less random data with MT is not needed when it succeeded. Notes: Merged: https://github.com/ruby/ruby/pull/2826
2020-01-09Renamed `init_seed` as `init_hash_salt` tooNobuyoshi Nakada
2020-01-09Renamed `seed` as `hash_salt`Nobuyoshi Nakada
The role of this is a so-called "salt" but not "seed", rename to get rid of confusion with other "seed" of PRNG. Notes: Merged: https://github.com/ruby/ruby/pull/2825
2020-01-09Also clear MT to initialize the siphash seedNobuyoshi Nakada
2019-12-26decouple internal.h headers卜部昌平
Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26add several __has_something macro卜部昌平
With these macros implemented we can write codes just like we can assume the compiler being clang. MSC_VERSION_SINCE is defined to implement those macros, but turned out to be handy for other places. The -fdeclspec compiler flag is necessary for clang to properly handle __has_declspec(). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-15rand(beginless_range) raise Errno::EDOM instead of TypeErrorKazuhiro NISHIYAMA
same as `rand(endless_range)` Before: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 2: from -e:1:in `<main>' 1: from -e:1:in `rand' -e:1:in `-': nil can't be coerced into Integer (TypeError) ``` After: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 1: from -e:1:in `<main>' -e:1:in `rand': Numerical argument out of domain (Errno::EDOM) ```
2019-09-27Adjusted spaces [ci skip]Nobuyoshi Nakada
2019-08-29drop-in type check for rb_define_singleton_method卜部昌平
We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
2019-06-04* expand tabs.git
2019-06-04random_mt_typeNobuyoshi Nakada
* random.c: renamed random_data_type as random_mt_type, and append "MT" to `wrap_struct_name`, respecting the implementation.
2019-02-10random.c: unify syscall with getrandomnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-10* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-10random.c: use getrandom() if available.glass
getrandom() is supported by glibc 2.25 or later. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07Split mt19937.cnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-03Fix Random.urandom in a chroot on OpenBSDnobu
[ruby-core:90850] [Bug #15494] From: jeremyevans0 (Jeremy Evans) <merch-redmine@jeremyevans.net> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-13suppress integer overflow warningsshyouhei
* random.c: annotate rb_hash_start with NO_SANITIZE (seed.key.hash + h overflows and that seems intentional) * bignum.c: avoid (size_t)-- * cont.c: ditto * util.c: ditto * vm_insnhelper.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-07blacklist UBSAN's unsigned integer overflowshyouhei
Integer overflow for unsigned types are fully defined in C. They are not always problematic (but not always OK). These functions in this changeset intentionally utilizes that behaviour. Blacklist from UBSAN checks for better output. See also: https://travis-ci.org/ruby/ruby/jobs/451624829 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30use RARRAY_AREF() instead of RARRAY_CONST_PTR().ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11random.c: prefixed fill_random_bytesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11add new instruction attribute called leafshyouhei
An instruction is leaf if it has no rb_funcall inside. In order to check this property, we introduce stack canary which is a random number collected at runtime. Stack top is always filled with this number and checked for stack smashing operations, when VM_CHECK_MODE. [GH-1947] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-04random.c: fix up r64596nobu
* random.c (fill_random_bytes_syscall): check if the version macro is defined, for very old Mac OS X development tools. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-04avoid fork-unsafe arc4random implementationsshyouhei
Some old implementaions of arc4random_buf(3) were ARC4 based, or unsafe when forked, or both. Resort to /dev/urandom for those known problematic cases. Fix [Bug #15039] Patch from Thomas Hurst <tom@hur.st> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-31random.c: SecRandomCopyBytesnobu
* random.c (fill_random_bytes_syscall): use SecRandomCopyBytes in Security framework on macOS 10.7 or later. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e