summaryrefslogtreecommitdiff
path: root/random.c
AgeCommit message (Collapse)Author
2024-11-30Remove a useless condition expressionYusuke Endoh
`len` is always at least 1 here. Notes: Merged: https://github.com/ruby/ruby/pull/12215
2024-11-29Avoid illegal pointerYusuke Endoh
When loading a crafted marshal data of Random, a pointer to an illegal address was created. I don't think there is any harm since the data is normalized before access, but just to be safe, I add a check to make it an error. Notes: Merged: https://github.com/ruby/ruby/pull/12200
2024-06-07Do not try random devices immediately twiceNobuyoshi Nakada
Do not retry `fill_random_bytes` in `Init_RandomSeedCore`, just after it failed first. In other places, `rand_init_default` and `random_seed`, no more tweeks needed once it succeeded
2024-06-07win32: Allocate the wrapper for crypt provider handle firstNobuyoshi Nakada
Also use a typed data.
2024-03-06Refactor VM root modulesJean Boussier
This `st_table` is used to both mark and pin classes defined from the C API. But `vm->mark_object_ary` already does both much more efficiently. Currently a Ruby process starts with 252 rooted classes, which uses `7224B` in an `st_table` or `2016B` in an `RArray`. So a baseline of 5kB saved, but since `mark_object_ary` is preallocated with `1024` slots but only use `405` of them, it's a net `7kB` save. `vm->mark_object_ary` is also being refactored. Prior to this changes, `mark_object_ary` was a regular `RArray`, but since this allows for references to be moved, it was marked a second time from `rb_vm_mark()` to pin these objects. This has the detrimental effect of marking these references on every minors even though it's a mostly append only list. But using a custom TypedData we can save from having to mark all the references on minor GC runs. Addtionally, immediate values are now ignored and not appended to `vm->mark_object_ary` as it's just wasted space.
2024-01-13Use STATIC_ASSERTNobuyoshi Nakada
2023-12-07Free everything at shutdownAdam Hess
when the RUBY_FREE_ON_SHUTDOWN environment variable is set, manually free memory at shutdown. Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2022-12-11[DOC] Improve Random::Formatter docszverok
* Make its usage more obvious (by providing more detailed examples); * Include mention of it into Random itself; * Small cleanups of docs. Notes: Merged: https://github.com/ruby/ruby/pull/5434
2022-11-10[Bug #19100] Add `init_int32` function to `rb_random_interface_t`Nobuyoshi Nakada
Distinguish initialization by single word from initialization by array.
2022-11-10Add version to the interface of Random extensionsNobuyoshi Nakada
2022-10-17Respect `USE_COMMON_RANDOM` macro by a command line option [ci skip]Nobuyoshi Nakada
2022-10-17Fix debug messages [ci skip]Nobuyoshi Nakada
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-01-13[DOC] Mark up the code for Kernel#rand as the same as Random#randNobuyoshi Nakada
2022-01-01Remove deprecated Random::DEFAULT [Feature #17351]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5382
2021-12-20[DOC] Add documentation for Random.rand and Random.seedChris AtLee
Notes: Merged: https://github.com/ruby/ruby/pull/5098
2021-12-16[DOC] random number by rangeNobuyoshi Nakada
2021-12-13[DOC] Add call sequences of Random using a rangeNobuyoshi Nakada
2021-12-13[DOC] Improve Random::Formatter description and exampleNobuyoshi Nakada
2021-12-10Fix stack buffer overflowNobuyoshi Nakada
https://hackerone.com/reports/1306859 Notes: Merged: https://github.com/ruby/ruby/pull/5239
2021-11-06Check the reading size rangeNobuyoshi Nakada
2021-10-27random.c: simplify Random object deallocationKazuki Yamaguchi
This is a follow-up for commit 265c0022390e ("Do not allocate ractor-local storage in dfree function during GC", 2021-02-09). The comparison with the default rb_random_mt_t is useless in the first place, since it is never equal: no actual Random object is associated with it. [Bug #17653] https://bugs.ruby-lang.org/issues/17653 Notes: Merged: https://github.com/ruby/ruby/pull/4224
2021-10-02[Win32] Prefer Cryptography Next Generation APINobuyoshi Nakada
[BCryptGenRandom] is available since Windows Vista / Windows Server 2008. Regarding [CryptGenRandom]: > This API is deprecated. New and existing software should start > using Cryptography Next Generation APIs. Microsoft may remove > this API in future releases. [BCryptGenRandom]: https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom [CryptGenRandom]: https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptgenrandom Notes: Merged: https://github.com/ruby/ruby/pull/4924
2021-09-24HCRYPTPROV is not a HANDLENobuyoshi Nakada
Even though it is called "handle" and prefixed with "H", and its value looks like a handle.
2021-09-12Using RB_FLOAT_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4821
2021-08-27Use C99-defined macros to classify a floating-point numberNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4783
2021-08-24netbsd coroutine uses assembly instead and little build fix.David Carlier
Notes: Merged: https://github.com/ruby/ruby/pull/4762
2021-06-24rand_bytes: prefer rng->get_bytes卜部昌平
Because why not. There was no use case of rng->get_bytes before this changeset. Notes: Merged: https://github.com/ruby/ruby/pull/4602
2021-05-04Fix compilation errors in FreeBSDPeter Zhu
__FreeBSD_version is defined in sys/param.h. Notes: Merged: https://github.com/ruby/ruby/pull/4457
2021-05-04Fix -Wundef warnings for patterns `#if HAVE`Benoit Daloze
* See [Feature #17752] * Using this to detect them: git grep -P 'if\s+HAVE' | grep -Pv 'HAVE_LONG_LONG|/ChangeLog|HAVE_TYPEOF' Notes: Merged: https://github.com/ruby/ruby/pull/4428
2021-03-19Include CommonCrypto/CommonCryptoError.h for old XcodeNobuyoshi Nakada
2021-03-19Use CommonRandom if availableNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4289
2021-03-04Fixed syntax error with gcc on macOSNobuyoshi Nakada
Security/Authorization.h defines AuthorizationExternalForm by using clang extension which allows variably modified types in a file scope. As we just need high-level accessors only, include Security/SecRandom.h instead.
2021-02-09Do not allocate ractor-local storage in dfree function during GCNobuyoshi Nakada
2021-01-18OpenBSD has getentropy, but no sys/random.hKazuhiro NISHIYAMA
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. ```
2021-01-17random generator update for Mac proposalDavid CARLIER
using getentropy for seeding, reading 256 bytes at a time to avoid the EIO errno since this is the maximum. Notes: Merged: https://github.com/ruby/ruby/pull/4081
2021-01-17Include missing AvailabilityMacros.hNobuyoshi Nakada
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
close