aboutsummaryrefslogtreecommitdiffstats
path: root/random.c
Commit message (Collapse)AuthorAgeFilesLines
* OpenBSD has getentropy, but no sys/random.hKazuhiro NISHIYAMA2021-01-181-1/+3
| | | | | | | | | | | | | https://man.openbsd.org/getentropy Try to fix https://rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20210118T023008Z.fail.html.gz ``` compiling random.c random.c:53:11: fatal error: 'sys/random.h' file not found # include <sys/random.h> ^~~~~~~~~~~~~~ 1 error generated. ```
* random generator update for Mac proposalDavid CARLIER2021-01-171-2/+18
| | | | | using getentropy for seeding, reading 256 bytes at a time to avoid the EIO errno since this is the maximum.
* Include missing AvailabilityMacros.hNobuyoshi Nakada2021-01-171-0/+4
|
* Remove possibility of using same seedsNobuyoshi Nakada2021-01-101-2/+2
|
* Random instance methodszverok2020-12-211-0/+7
|
* Deprecate Random::DEFAULTBenoit Daloze2020-12-141-0/+2
| | | | * Closes [Feature #17351].
* Remove references to Random::DEFAULT in the documentationBenoit Daloze2020-12-141-8/+6
| | | | | * Random::DEFAULT is no longer a Random instance, and referencing it is more confusing than helpful. Related to [Feature #17351]
* ractor local storage C-APIKoichi Sasada2020-12-011-11/+22
| | | | | | | | | | | | | | | | | | | | | | 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.
* Use opaque struct pointer than voidNobuyoshi Nakada2020-11-271-2/+2
|
* mark default_randKoichi Sasada2020-11-271-0/+7
| | | | default_rand can points a Bignum seed, so it should be marked.
* per-ractor Random::DEFAULTKoichi Sasada2020-11-271-37/+32
| | | | | | | | | | 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]
* [DOC] Mersenne Twister isn't cryptographically secure [ci skip]Nobuyoshi Nakada2020-11-271-1/+2
|
* rb_const_set sets the class path nowNobuyoshi Nakada2020-10-091-1/+0
|
* Added `rb_random_base_init`Nobuyoshi Nakada2020-09-071-1/+8
| | | | To enclose the initialization of Random::Base part.
* Added WITH_REAL macrosNobuyoshi Nakada2020-09-071-1/+1
| | | | | | Added `WITH_REAL` versions to `RB_RANDOM_INTERFACE` macros. Also these macros including "without real" versions no longer contain the terminator (semicolon and comma).
* Added `get_real` interfaceNobuyoshi Nakada2020-09-071-0/+1
|
* Added rb_int_pair_to_realNobuyoshi Nakada2020-09-071-0/+6
|
* separate rb_random_tNobuyoshi Nakada2020-09-071-120/+230
| | | | | | | | | | | | * 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.
* Random::BaseNobuyoshi Nakada2020-09-071-6/+13
| | | | | * random.c (InitVM_Random): introduce abstract super class Random::Base.
* RARRAY_AREF: convert into an inline function卜部昌平2020-08-151-0/+1
| | | | | | 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.
* rand_range: do not goto into a branch卜部昌平2020-06-291-1/+1
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Fixed constant initializerNobuyoshi Nakada2020-05-041-1/+1
| | | | | An expression using `static const` value seems not considered as `static const` by Visual C.
* Make int-pair-to-real conversion more portableNobuyoshi Nakada2020-05-041-5/+16
| | | | And utilize more bits even if DBL_MANT_DIG > 53.
* Disable deprecation error on mingwNobuyoshi Nakada2020-04-081-0/+2
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-2/+1
| | | Split ruby.h
* Ensure seed data to be clearedNobuyoshi Nakada2020-01-101-23/+14
| | | | To prevent from leaking the seed data.
* Fill siphash salt directly with random dataNobuyoshi Nakada2020-01-101-0/+6
| | | | | Expanding less random data with MT is not needed when it succeeded.
* Renamed `init_seed` as `init_hash_salt` tooNobuyoshi Nakada2020-01-091-2/+2
|
* Renamed `seed` as `hash_salt`Nobuyoshi Nakada2020-01-091-8/+8
| | | | | The role of this is a so-called "salt" but not "seed", rename to get rid of confusion with other "seed" of PRNG.
* Also clear MT to initialize the siphash seedNobuyoshi Nakada2020-01-091-0/+1
|
* decouple internal.h headers卜部昌平2019-12-261-18/+32
| | | | | | | | | | | | | | | | | | 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).
* add several __has_something macro卜部昌平2019-12-261-1/+1
| | | | | | | 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().
* rand(beginless_range) raise Errno::EDOM instead of TypeErrorKazuhiro NISHIYAMA2019-12-151-2/+4
| | | | | | | | | | | | | | | | | | | | | 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) ```
* Adjusted spaces [ci skip]Nobuyoshi Nakada2019-09-271-2/+2
|
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-5/+5
| | | | | | 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.
* * expand tabs.git2019-06-041-1/+1
|
* random_mt_typeNobuyoshi Nakada2019-06-041-8/+8
| | | | | * random.c: renamed random_data_type as random_mt_type, and append "MT" to `wrap_struct_name`, respecting the implementation.
* random.c: unify syscall with getrandomnobu2019-02-101-34/+14
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2019-02-101-15/+15
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: use getrandom() if available.glass2019-02-101-0/+26
| | | | | | 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
* Split mt19937.cnobu2019-02-071-158/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix Random.urandom in a chroot on OpenBSDnobu2019-01-031-0/+5
| | | | | | | | [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
* suppress integer overflow warningsshyouhei2018-11-131-0/+1
| | | | | | | | | | | | | * 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
* blacklist UBSAN's unsigned integer overflowshyouhei2018-11-071-0/+3
| | | | | | | | | | | | 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
* * expand tabs.svn2018-10-301-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* use RARRAY_AREF() instead of RARRAY_CONST_PTR().ko12018-10-301-5/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: prefixed fill_random_bytesnobu2018-09-111-1/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* add new instruction attribute called leafshyouhei2018-09-111-1/+1
| | | | | | | | | | | 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