* random.c (fill_random_bytes_syscall): get rid of blocking when
no entropy is available. based on the patch by mame in
[ruby-core:70114]. [Bug #11395]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This follows the behavior of fill_random_bytes_urandom and fixes
the following failures I encountered on my old machine:
1) Error:
TestSecureRandom#test_s_random_bytes_without_openssl:
NotImplementedError: No random device
$RUBYDIR/lib/securerandom.rb:66:in `gen_random'
$RUBYDIR/lib/securerandom.rb:94:in `random_bytes'
$RUBYDIR/test/test_securerandom.rb:12:in `test_s_random_bytes'
$RUBYDIR/test/test_securerandom.rb:97:in `block in test_s_random_bytes_without_openssl'
$RUBYDIR/lib/tmpdir.rb:88:in `mktmpdir'
$RUBYDIR/test/test_securerandom.rb:85:in `test_s_random_bytes_without_openssl'
2) Error:
TestSecureRandom#test_s_urlsafe_base64:
NotImplementedError: No random device
$RUBYDIR/lib/securerandom.rb:66:in `gen_random'
$RUBYDIR/lib/securerandom.rb:94:in `random_bytes'
$RUBYDIR/lib/securerandom.rb:164:in `urlsafe_base64'
$RUBYDIR/test/test_securerandom.rb:131:in `block in test_s_urlsafe_base64'
$RUBYDIR/test/test_securerandom.rb:130:in `times'
$RUBYDIR/test/test_securerandom.rb:130:in `test_s_urlsafe_base64'
3) Error:
TestSecureRandom#test_uuid:
NotImplementedError: No random device
$RUBYDIR/lib/securerandom.rb:66:in `gen_random'
$RUBYDIR/lib/securerandom.rb:94:in `random_bytes'
$RUBYDIR/lib/securerandom.rb:230:in `uuid'
$RUBYDIR/test/test_securerandom.rb:160:in `test_uuid'
* random.c (fill_random_bytes_syscall): return -1 for error
* random.c (fill_random_bytes): try urandom on syscall failure
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (fill_random_bytes_syscall): try getrandom system call
on Linux if supported by the kernel.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (fill_random_bytes): separate into functions by system
call and by direct read of urandom device.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (fill_random_bytes): separate non-raced and raced
conditions, on Windows.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (fill_random_bytes): release the handle in the static
variable, not a local variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* include/ruby/ruby.h (rb_data_object_alloc_warning): enable only
if __builtin_choose_expr works with __builtin_constant_p so that
warnings will be suppressed if klass is 0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* include/ruby/ruby.h (rb_data_object_alloc_warning): enable only
if __builtin_choose_expr works with __builtin_constant_p so that
warnings will be suppressed if klass is 0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
if the requested size is 0. AIX returns -1 for 0-byte read from
/dev/urandom, while other UNIX returns 0. With this change,
Random.raw_seed(0) consistently retuns "" in any UNIX.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (fill_random_bytes): use ATOMIC_SIZE_CAS to suppress a
strict-aliasing warning by gcc 4.9 for mingw.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (rand_random_number): raise ArgumentError for invalid
argument like as SecureRandom.random_number.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (rand_random_number): allow negative argument as it is
allowed by SecureRandom.random_number.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (rand_random_number): add a method to return a random
number like SecureRandom to Random::Formatter.
* lib/securerandom.rb (random_bytes): move to Random::Formatter,
the base method of the module.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (rand_random): use PRIsVALUE to format an error
message.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (random_raw_seed): extract platform dependent random
seed initialization function as a new method Random.raw_seed.
* lib/securerandom.rb (SecureRandom): use Random.raw_seed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
use 0 for rb_data_type_t::reserved instead of NULL, since its type
may be changed in the future and possibly not a pointer type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c (fill_random_seed): fix type to cast. this may or may
not suppress warnings by icc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RARRAY_RAWPTR(ary) returns (const VALUE *) type pointer and
usecase of this macro is not acquire raw pointer, but acquire
read-only pointer. So we rename to better name.
RSTRUCT_RAWPTR() is also renamed to RSTRUCT_CONST_PTR()
(I expect that nobody use it).
* array.c, compile.c, cont.c, enumerator.c, gc.c, proc.c, random.c,
string.c, struct.c, thread.c, vm_eval.c, vm_insnhelper.c:
catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: Use uint32_t for elements of seed.
(make_seed_value): Use rb_integer_unpack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
random.c:410:32: error: implicit conversion loses integer precision:
'size_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
This cast doesn't cause a problem because len is not bigger than
MT_MAX_STATE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* bignum.c (rb_integer_unpack): Support INTEGER_PACK_FORCE_BIGNUM.
* random.c (int_pair_to_real_inclusive): Use
INTEGER_PACK_FORCE_BIGNUM to use rb_big_mul instead of rb_funcall.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e