Граф коммитов

345 Коммитов

Автор SHA1 Сообщение Дата
nobu d009cebf0f random.c: no local copy of the seed
* random.c (make_seed_value): append leading-zero-guard and get
  rid of making a local copy of the seed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-13 15:16:57 +00:00
nobu 79850a0829 random.c: fill_random_seed size
* random.c (fill_random_seed): move the seed size to an argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-13 15:16:56 +00:00
nobu 678c39dc44 random.c: clear buf
* random.c (random_seed): clear temporary buffer explicitly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-13 14:56:32 +00:00
nobu 15fbd05e4e random.c: reuse bits
* random.c (random_ulong_limited): reduce calling bytes methods by
  reusing dropped bits.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-10 06:46:09 +00:00
nobu b402cc7161 random.c: use bytes
* random.c (obj_random_bytes): base on bytes method instead of
  rand method, not to call toplevel rand method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-10 05:57:11 +00:00
nobu a6b221f238 random.c: compare by rb_equal
* random.c (random_equal): compare seeds by rb_equal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-09 16:25:53 +00:00
nobu 8610bd032a random.c: consitify
* random.c (init_by_array): consitify initializing keys.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-09 04:27:12 +00:00
nobu ad949e8f31 random.c: seed conversion
* random.c (rand_init): random_seed() always returns an Integer,
  no conversion for it.

* random.c (random_init, rb_f_srand): convert the given seed to an
  Integer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-09 03:52:09 +00:00
nobu ed5b985650 random.c: optimize int_pair_to_real_inclusive
* random.c (int_pair_to_real_inclusive): optimize to multiply
  without Bignum.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-07 07:22:14 +00:00
nobu 091d88ab4b random.c: split random_int32
* random.c (random_int32): split the cases of rb_random_t and
  other objects.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-07 06:21:00 +00:00
nobu 1a696e35c8 random.c: unnecessary declarations
* random.c (random_ulong_limited, random_ulong_limited_big):
  remove unnecessary extern declarations.  rb_num_negative_p is
  declared in internal.h now.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-07 02:59:32 +00:00
nobu c0f920093e random.c: fill_random_bytes_syscall function
* random.c (fill_random_bytes_syscall): turned into a static
  function, to be inlined probably, so that it is unavailable if
  it is a preprocessor macro.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 07:18:34 +00:00
nobu a331eeb529 random.c: refactor
* random.c (rand_random, rb_f_rand): refactor, split condition
  expressions, and return in the precedence.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 07:18:33 +00:00
nobu 3377db6b32 random.c: use rb_check_to_int
* random.c (rand_range, rand_random): use rb_check_to_int instead
  of rb_check_to_integer with the same conversion method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 06:52:37 +00:00
nobu 0e303494d0 random.c: prefer rb_check_arity
* random.c: use rb_check_arity instead of rb_scan_args for simple
  optional arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 06:52:36 +00:00
nobu c92c82184c random.c: sipseed_keys_t
* random.c (sipseed): separate type of keys to reduce use of the
  magic number.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 06:52:35 +00:00
nobu 72c4fc7283 random.c: default seed mark
* random.c (Init_Random_default): since seed is marked by
  random_mark, no needs to mark itself as a global variable.
  allocate Random instance before making the seed value, to get
  rid of the potential risk of GC during the allocation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 06:29:56 +00:00
nobu 80c9b6646e random.c: return value is not GCed
* random.c (rand_init): since seed is the return value, no needs
  to be volatile to prevent from GC.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 06:29:55 +00:00
nobu e1ce20cf9b random.c: use uint32_t
* random.c (struct MT, next_state): use uint32_t for the state
  vector.

* random.c (init_by_array, rand_init): ditto for initializing
  keys.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-05 15:00:05 +00:00
nobu 4a066896af random.c: use arc4random_buf
* random.c (fill_random_bytes_syscall): use arc4random_buf if
  available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-05 01:49:35 +00:00
usa 62b6e90d58 * cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4
support leftovers.
  [fix GH-1328] patched by @cremno


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-01 11:42:41 +00:00
akr 169b867fbf * random.c (limited_rand): Add a specialized path for the limit fits in 32 bit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-24 12:30:20 +00:00
ko1 2f5b8f0529 * *.c (*_memsize): do not check ptr.
NULL checking is finished Before call of memsize functions.
  See r52979.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09 00:38:32 +00:00
nobu 4a1b9786dc random.c: fix filling size
* random.c (fill_random_seed): fix the size to be filled, not the
  size of element, but the whole size of array.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-05 00:23:36 +00:00
nobu 24dcb1285d explicit_bzero.c: needs windows.h
* missing/explicit_bzero.c, random.c (explicit_bzero):
  SecureZeroMemory() needs windows.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-01 03:52:20 +00:00
kosaki 86af9bba63 * random.c (InitVM_Random): move Random::DEFAULT initialization
bits to Init_Random_default.
* random.c (Init_Random_default): renamed from Init_Rndom2.
* random.c (Init_RandomSeedCore): renamed from Init_Random.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30 20:32:42 +00:00
kosaki 99c05fb38e * random.c (Init_RandomSeed): move all Random::DEFAULT
construction bits to Init_RandomSeed2. Random::DEFAULT
  and Ruby internal hashes are no longer shared their seed.
* random.c (Init_RandomSeed2): ditto. And, kill evil
  rb_obj_reveal() stuff.
* random.c (init_hashseed): add MT argument.
* random.c: (init_siphash): ditto.
* test/ruby/test_rand.rb (TestRand#test_default_seed): new
  test for Random::DEFAULT::seed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30 20:31:31 +00:00
kosaki 052535be3e * random.c (init_hashseed, init_siphash): extract initialize
functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30 20:31:11 +00:00
kosaki 12e059b18c * random.c (init_randomseed): remove "initial" argument. It never
be used from outside of this function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30 20:29:37 +00:00
kosaki f7bd7d6f1f * random.c: random_raw_seed don't use GRND_NONBLOCK. GRND_NONBLOCK
mean the result might not have an enough cryptic strength and
  easy predictable. That's no good for SecureRandom.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30 20:27:11 +00:00
kosaki dea685c783 * missing/explicit_bzero.c: new file. define explicit_bzero.
* common.mk: add a rule for explicit.o.
* configure.in: detect explicit_bzero and memset_s.
* include/ruby/missing.h: add explicit_bzero.
* random.c (init_randomseed): use explicit_bzero() instead of
  memset(). memset could be eliminated by compiler optimization.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30 20:26:13 +00:00
nobu 503752b14c random.c: comment [ci skip]
* random.c (fill_random_bytes_urandom): fix comment typos.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 05:51:44 +00:00
kosaki 0751bc3fad Revert r52180
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 05:46:21 +00:00
kosaki 6c060b2b58 * random.c (fill_random_bytes_urandom): add a comment why using
O_NONBLOCK and O_NOCTTY.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 05:43:08 +00:00
kosaki 47f0a8f9d0 * random.c (fill_random_bytes_syscall): don't use GRND_NONBLOCK.
It is meaningless. If SYS_getrandom(GRND_NONBLOCK) return
  EAGAIN, we eventually call fill_random_bytes_urandom() and
  it block such as SYS_getrandom() without GRND_NONBLOCK.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 05:42:37 +00:00
kosaki a4c6ad1d19 * random.c (fill_random_bytes_syscall): use ATOMIC_SET() for
updating try_syscall.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 05:42:08 +00:00
nobu e02186f526 random.c: get rid of blocking
* 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
2015-07-25 12:03:50 +00:00
kazu b091903c5c fix compile error with clang
* random.c (fill_random_bytes_syscall): fix compile error with
  clang. [ruby-core:69931] [Bug #11343]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-14 15:01:39 +00:00
kazu 4f66d02c97 * random.c (fill_random_bytes_syscall): fix compile error.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07 09:21:11 +00:00
normal 50c0a20025 random.c: fix failures on old Linux
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
2015-07-07 07:46:29 +00:00
nobu bcd96d92f3 random.c: try getrandom
* 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
2015-07-07 06:26:06 +00:00
nobu e96955e8f6 random.c: separate fill_random_bytes
* 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
2015-07-07 06:25:55 +00:00
nobu f9c2adf310 random.c: refactor
* 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
2015-06-25 06:32:23 +00:00
nobu 5e132260c4 random.c: fix handle to release
* 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
2015-03-19 01:31:03 +00:00
nobu c7988fd29d ruby.h: suppress false warnings
* 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
2015-03-16 07:49:27 +00:00
nobu 5d09df3273 ruby.h: suppress false warnings
* 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
2015-03-16 07:47:48 +00:00
odaira 270630c628 * random.c (random_raw_seed): Avoid calling fill_random_bytes()
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
2015-03-04 23:44:59 +00:00
nobu 3bc9d1d0f4 random.c: suppress a warning
* 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
2015-02-15 03:23:36 +00:00
nobu 10a9807030 random.c: ArgumentError for invalid argument
* 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
2015-02-14 05:40:10 +00:00
nobu dd09b5bf1d random.c: allow negative argument to random_number
* 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
2015-02-14 04:11:26 +00:00
nobu b1adbd14e5 random.c: rand_random_number
* 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
2015-02-14 03:20:04 +00:00
nobu 03af53f559 random.c: use PRIsVALUE
* 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
2015-02-14 03:02:05 +00:00
nobu eeeb7ae8c0 random.c: Random.raw_seed
* 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
2015-02-14 03:01:36 +00:00
nobu e580a631be use 0 for reserved
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
2014-12-01 06:38:04 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
nobu 90173785a8 random.c: fix casts
* 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
2014-07-09 14:51:26 +00:00
nobu 876bfc6b4e Init functions don't need ID caches
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-03 03:38:10 +00:00
akr 3c99764bcd * internal.h: Rename macro names: RBIGNUM_FOO to BIGNUM_FOO.
(BIGNUM_EMBED_LEN_NUMBITS): Renamed from RBIGNUM_EMBED_LEN_NUMBITS.
  (BIGNUM_EMBED_LEN_MAX): Renamed from RBIGNUM_EMBED_LEN_MAX.
  (BIGNUM_SIGN_BIT): Renamed from RBIGNUM_SIGN_BIT.
  (BIGNUM_SIGN): Renamed from RBIGNUM_SIGN.
  (BIGNUM_SET_SIGN): Renamed from RBIGNUM_SET_SIGN.
  (BIGNUM_POSITIVE_P): Renamed from RBIGNUM_POSITIVE_P.
  (BIGNUM_NEGATIVE_P): Renamed from RBIGNUM_NEGATIVE_P.
  (BIGNUM_EMBED_FLAG): Renamed from RBIGNUM_EMBED_FLAG.
  (BIGNUM_EMBED_LEN_MASK): Renamed from RBIGNUM_EMBED_LEN_MASK.
  (BIGNUM_EMBED_LEN_SHIFT): Renamed from RBIGNUM_EMBED_LEN_SHIFT.
  (BIGNUM_LEN): Renamed from RBIGNUM_LEN.
  (RBIGNUM_DIGITS): Renamed from RBIGNUM_DIGITS.
  (BIGNUM_LENINT): Renamed from RBIGNUM_LENINT.

* bignum.c: Follow the above change.

* gc.c: Ditto.

* marshal.c: Ditto.

* math.c: Ditto.

* numeric.c: Ditto.

* random.c: Ditto.

* rational.c: Ditto.

* sprintf.c: Ditto.

* ext/-test-/bignum/bigzero.c: Ditto.

* ext/-test-/bignum/intpack.c: Ditto.

* ext/bigdecimal/bigdecimal.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-15 21:17:34 +00:00
akr ced9ad5ab5 * random.c (rand_init): Make it possible to specify arbitrary array
for init_genrand().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-20 11:05:38 +00:00
ko1 c5e08b764e * add RUBY_TYPED_FREE_IMMEDIATELY to data types which only use
safe functions during garbage collection such as xfree().
  On default, T_DATA objects are freed at same points as fianlizers.
  This approach protects issues such as reported by [ruby-dev:35578].
  However, freeing T_DATA objects immediately helps heap usage.
  Most of T_DATA (in other words, most of dfree functions) are safe.
  However, we turned off RUBY_TYPED_FREE_IMMEDIATELY by default
  for safety.
* cont.c: ditto.
* dir.c: ditto.
* encoding.c: ditto.
* enumerator.c: ditto.
* error.c: ditto.
* file.c: ditto.
* gc.c: ditto.
* io.c: ditto.
* iseq.c: ditto.
* marshal.c: ditto.
* parse.y: ditto.
* proc.c: ditto.
* process.c: ditto.
* random.c: ditto.
* thread.c: ditto.
* time.c: ditto.
* transcode.c: ditto.
* variable.c: ditto.
* vm.c: ditto.
* vm_backtrace.c: ditto.
* vm_trace.c: ditto.
* ext/bigdecimal/bigdecimal.c: ditto.
* ext/objspace/objspace.c: ditto.
* ext/stringio/stringio.c: ditto.
* ext/strscan/strscan.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 11:16:54 +00:00
mame e7f484d469 * random.c (make_seed_value): a local array declaration was accessed
out of scope.  Coverity Scan found this bug.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-02 12:41:08 +00:00
ko1 dc626dbab3 * include/ruby/ruby.h: rename RARRAY_RAWPTR() to RARRAY_CONST_PTR().
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
2013-09-25 08:24:34 +00:00
nobu 26feae3958 random.c: coerce before check negative
* random.c (rb_random_ulong_limited): coerce before check negative.
  [Fixes GH-379]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-13 13:13:02 +00:00
ko1 8741a39777 * random.c (random_load): use RARRAY_RAWPTR() instead of
RARRAY_PTR() because there is no new reference.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-07 04:20:56 +00:00
shugo 1f828497d1 * safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4.  $SAFE=4 is now obsolete.
  [ruby-core:55222] [Feature #8468]

* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
  Kernel#untrusted?, untrust, and trust are now deprecated.
  Their behavior is same as tainted?, taint, and untaint,
  respectively.

* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
  and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
  respectively.

* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
  ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
  ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
  ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
  ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
  ext/socket/socket.c, ext/socket/udpsocket.c,
  ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
  ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
  load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
  safe.c, string.c, thread.c, transcode.c, variable.c,
  vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
  $SAFE=4.

* test/dl/test_dl2.rb, test/erb/test_erb.rb,
  test/readline/test_readline.rb,
  test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
  test/ruby/test_array.rb, test/ruby/test_dir.rb,
  test/ruby/test_encoding.rb, test/ruby/test_env.rb,
  test/ruby/test_eval.rb, test/ruby/test_exception.rb,
  test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
  test/ruby/test_io.rb, test/ruby/test_method.rb,
  test/ruby/test_module.rb, test/ruby/test_object.rb,
  test/ruby/test_pack.rb, test/ruby/test_rand.rb,
  test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
  test/ruby/test_struct.rb, test/ruby/test_thread.rb,
  test/ruby/test_time.rb: remove tests for $SAFE=4.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 14:20:51 +00:00
akr e39523b77b * random.c (rand_int): Use rb_big_uminus.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-11 22:33:01 +00:00
akr 0c9a719d77 * internal.h (INTEGER_PACK_NEGATIVE): Defined.
(rb_integer_unpack): sign argument removed.

* bignum.c (rb_integer_unpack): sign argument removed.
  Non-negative integers generated by default.
  INTEGER_PACK_NEGATIVE flag is used to generate non-positive integers.

* pack.c (pack_unpack): Follow the above change.

* random.c (int_pair_to_real_inclusive): Ditto.
  (make_seed_value): Ditto.
  (mt_state): Ditto.
  (limited_big_rand): Ditto.

* marshal.c (r_object0): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-11 21:39:55 +00:00
akr 0e8caa7d0f * bignum.c (rb_integer_pack): Returns sign instead of words.
(absint_numwords_generic): Follow the above change.
  (big2str_base_powerof2): Follow the above change.

* internal.h: Ditto.

* hash.c (rb_hash): Ditto.

* pack.c (pack_pack): Ditto.

* random.c (int_pair_to_real_inclusive): Ditto.
  (rand_init): Ditto.
  (random_load): Ditto.
  (limited_big_rand): Ditto.

* time.c (v2w_bignum): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-10 10:37:39 +00:00
akr f5ad120b97 * bignum.c (rb_absint_numwords): Renamed from rb_absint_size_in_word.
* internal.h (rb_absint_numwords): Follow the above change.

* pack.c (pack_pack): Ditto.

* random.c (rand_init): Ditto.
  (limited_big_rand): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-09 07:53:20 +00:00
akr 837392b452 * bignum.c (rb_integer_pack): numwords_allocated argument removed.
* internal.h (rb_integer_pack): Follow the above change.

* hash.c (rb_hash): Ditto.

* time.c (v2w_bignum): Ditto.

* pack.c (pack_pack): Ditto.

* random.c (int_pair_to_real_inclusive): Ditto.
  (rand_init): Ditto.
  (random_load): Ditto.
  (limited_big_rand): Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-09 05:53:00 +00:00
charliesome 6c5000b5f1 * random.c (limited_big_rand): declare rnd, lim and mask as uint32_t
to avoid 64 bit to 32 bit shorten warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 10:33:05 +00:00
akr 14140eb16b * random.c: Unused RBignum internal accessing macros removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 10:07:05 +00:00
akr a76abae51d * random.c (limited_big_rand): The argument, limit, is changed to
VALUE.  Use rb_integer_pack and rb_integer_unpack.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 10:05:37 +00:00
akr 483cbff8dc * random.c (make_seed_value): Fix the length given for
rb_integer_unpack.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 08:15:51 +00:00
akr d35616e694 * bignum.c (rb_integer_unpack): Don't use rb_funcall if possible.
* 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
2013-06-08 07:40:03 +00:00
akr 8a1609040e * random.c (rand_init): Add a cast to fix clang compile error:
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
2013-06-08 07:01:19 +00:00
akr ccce83c454 * random.c (rand_init): Use rb_integer_pack.
(roomof): Removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 06:46:45 +00:00
akr 0056591f50 * internal.h (INTEGER_PACK_FORCE_BIGNUM): New flag constant.
* 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
2013-06-08 06:00:04 +00:00
akr 6b5be413bb * random.c (int_pair_to_real_inclusive): Use rb_funcall instead of
rb_big_mul because rb_integer_unpack can return a Fixnum.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 03:01:33 +00:00
akr 8ca1e1238e * random.c (int_pair_to_real_inclusive): Use rb_integer_pack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 02:18:14 +00:00
akr 479b17ed12 * random.c (int_pair_to_real_inclusive): Use rb_integer_unpack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 00:50:40 +00:00
akr 9ebd008f32 * random.c (random_load): Use rb_integer_pack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-07 23:12:55 +00:00
akr b0f14c8b58 * random.c (numberof): Removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-07 21:16:12 +00:00
akr 8bc16423cc * random.c: include internal.h.
(mt_state): Use rb_integer_unpack.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-07 21:01:42 +00:00
akr 99638b5d1f * random.c (int_pair_to_real_inclusive): Add a cast to BDIGIT.
(random_load): Fix shift width for fixnums.
  Re-implement bignum extraction without ifdefs.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-05 11:07:05 +00:00
ko1 4f401816ff * gc.c: support RGENGC. [ruby-trunk - Feature #8339]
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
2013-05-13 18:07:47 +00:00
ko1 83aba04862 * include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
  This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
  This function reveal interal (hidden) object by rb_obj_hide().
  Note that do not change class before and after hiding.
  Only permitted example is:
  klass = RBASIC_CLASS(obj);
  rb_obj_hide(obj);
  ....
  rb_obj_reveal(obj, klass);
  TODO: API design. rb_obj_reveal() should be replaced with others.
  TODO: modify constified variables using cast may be harmful for
  compiler's analysis and optimizaton.
  Any idea to prohibt inserting RBasic::klass directly?
  If rename RBasic::klass and force to use RBASIC_CLASS(obj),
  then all codes such as `RBASIC(obj)->klass' will be
  compilation error. Is it acceptable? (We have similar
  experience at Ruby 1.9,
  for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
  object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
  without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
  file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
  parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
  string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
  Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
  ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 10:49:11 +00:00
zzak 4813d8713c * random.c: Document Random::DEFAULT by @eLobato [Fixes GH-304]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 01:07:50 +00:00
kosaki 798ff850e4 * configure.in: check struct timeval exist or not.
* include/ruby/missing.h (struct timeval): check HAVE_STRUCT_TIMEVAL
  properly. and don't include sys/time.h if struct timeval exist.

* file.c: include sys/time.h explicitly.
* random.c: ditto.
* thread_pthread.c: ditto.
* time.c: ditto.
* ext/date/date_strftime.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-16 05:06:47 +00:00
nobu d64c926eba random.c: increase limit for generic rand
* random.c (rb_random_ulong_limited): limit is inclusive, but generic
  rand method should return a number less than it, so increase for the
  difference.  [ruby-core:52779] [Bug #7935]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-24 06:33:49 +00:00
nobu 3f2ce6373f random.c: fix error message
* random.c (rb_random_ulong_limited): fix error message for negative
  value.  [ruby-dev:47061] [Bug #7903]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-22 03:46:47 +00:00
zzak ec72030317 * random.c: Document range argument for Kernel#rand.
[ruby-core:51794] [Bug #7770]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-03 01:25:57 +00:00
nobu 4d73f95068 random.c, rational.c: make marshal methods private
* random.c (Init_Random), rational.c (Init_Rational): make marshal
  methods private.  [Feature #6539]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-03 10:10:14 +00:00
nobu 2ce1fbeb59 random.c: BYTE_ORDER
* random.c (BYTE_ORDER): define using configured WORDS_BIGENDIAN.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-09 14:05:11 +00:00
nobu 525cb66467 siphash
* random.c (rb_memhash): use siphash.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-09 07:12:00 +00:00
nari c3a46d6aca * include/ruby/ruby.h: add C APIs.
VALUE rb_newobj_of(VALUE klass, VALUE flags)
  #define NEWOBJ_OF(obj,type,klass,flags)
  These allow to change a allocation strategy depending on klass
  or flags.

* gc.c: ditto

* array.c: use new C API.
* bignum.c: ditto
* class.c: ditto
* complex.c: ditto
* ext/socket/ancdata.c: ditto
* ext/socket/option.c: ditto
* hash.c: ditto
* io.c: ditto
* marshal.c: ditto
* numeric.c: ditto
* object.c: ditto
* random.c: ditto
* range.c: ditto
* rational.c: ditto
* re.c: ditto
* string.c: ditto
* struct.c: ditto
  [Feature #7177][Feature #7047]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-20 06:57:51 +00:00
nobu 7f8e558464 random.c: rb_random_ulong_limited
* random.c (rb_random_ulong_limited): new function to return a random
  value from 0 upto limit as unsigned long, simillary to
  rb_genrand_ulong_limited but with arbitrary RNG object.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-09 08:59:03 +00:00
ko1 b3b5e626ad * include/ruby/ruby.h: introduce flonum technique for
64bit CPU environment (sizeof(double) == sizeof(VALUE)).
  flonum technique enables to avoid double object creation
  if the double value d is in range about between
  1.72723e-77 < |d| <= 1.15792e+77 or 0.0.
  flonum Float value is immediate and their lowest two bits
  are b10.
  If flonum is activated, then USE_FLONUM macro is 1.
  I'll write detailed in this technique on
  https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/Flonum_tech
* benchmark/bmx_temp.rb: add an benchmark for simple
  Float calculation.
* gc.c (id2ref, rb_obj_id): add flonum Float support.
* include/ruby/intern.h: move decl of rb_float_new(double)
  to include/ruby/ruby.h.
* insns.def, vm.c, vm_insnhelper.c: add flonum optimization
  and simplify source code.
* vm_insnhelper.h (FLONUM_2_P): added.
* marshal.c: support flonum output.
* numeric.c (rb_float_new_in_heap): added.
* parse.y: support flonum.
* random.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-23 07:22:40 +00:00
nobu 1abd3d4e38 random.c: refine error message
* random.c (rb_random_real): refine error message.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-20 08:20:56 +00:00
nobu 0b0dea752c random.c: check initialize and load
* random.c (random_init, random_load): cannot initialize frozen object
  again, nor with tainted/untrusted object.  [Bug #6540]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 04:36:54 +00:00
kosaki a57cbd7b27 * random.c (rb_random_int32): get rid of "warning: constant 0x100000000
is so big it is long" warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-19 21:49:52 +00:00
nobu 2073258a7d obj_init_copy
* object.c (rb_obj_init_copy): should check if trusted too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-05 11:13:18 +00:00
drbrain 42a9234cc4 * random.c (random_init): Clarify that the default seed is
Random.new_seed, not zero.  Based on patch by Roger Pack.
	  [ruby-trunk - Bug #6313]
	* random.c (rb_f_srand):  ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-19 00:35:32 +00:00
marcandre 7316302483 * include/ruby/intern.h: Add rb_check_arity, rb_error_arity [#6085]
* array.c: Use rb_check_arity / rb_error_arity

* class.c: ditto

* enumerator.c: ditto

* eval.c: ditto

* file.c: ditto

* hash.c: ditto

* numeric.c: ditto

* proc.c: ditto

* process.c: ditto

* random.c: ditto

* re.c: ditto

* signal.c: ditto

* string.c: ditto

* struct.c: ditto

* transcode.c: ditto

* vm_eval.c: ditto

* vm_insnhelper.c: ditto & implementation of rb_error_arity

* test/ruby/test_arity.rb: tests for above

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-14 21:10:34 +00:00
nobu 42437780d6 * random.c (Init_Random): removed rb_Random_DEFAULT and register as
mark-object instead of global variable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-11 22:04:13 +00:00
nobu b87f2fe1e4 * random.c (random_s_rand): ensure default PRNG is re-initialized
after fork.  patched by Eric Wong.  [ruby-core:41209][Bug #5661]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-11 22:03:36 +00:00
mrkn 923bff74b1 * random.c: remove a duplicated comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-02-18 14:28:42 +00:00
akr da74bc7552 * process.c (ruby_setsid): use rb_cloexec_open.
(rb_daemon): ditto.

* ruby.c (load_file_internal): ditto.

* file.c (rb_file_s_truncate): ditto.
  (file_load_ok): ditto.

* random.c (fill_random_seed): ditto.

* ext/pty/pty.c (chfunc): ditto.
  (get_device_once): ditto.

* ext/io/console/console.c (console_dev): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-29 04:01:54 +00:00
akr b574a4d4a1 * include/ruby/intern.h (rb_fd_set_cloexec): declared.
* io.c (rb_fd_set_cloexec): new function.
  (ruby_dup): call rb_fd_set_cloexec to set close-on-exec flag.
  (rb_sysopen_internal): ditto.
  (rb_pipe): ditto.
  (io_reopen): ditto.
  (io_cntl): ditto.

* process.c (rb_f_exec): change the default :close_others option to
  true.
  (rb_f_system): ditto.
  (move_fds_to_avoid_crash): call rb_fd_set_cloexec to set
  close-on-exec flag.
  (ruby_setsid): ditto.
  (rb_daemon): ditto.

* thread_pthread.c (rb_thread_create_timer_thread): call
  rb_fd_set_cloexec to set close-on-exec flag.

* ruby.c (load_file_internal): ditto.

* file.c (rb_file_s_truncate): ditto.
  (file_load_ok): ditto.

* random.c (fill_random_seed): ditto.

* ext/pty/pty.c (chfunc): ditto.
  (get_device_once): ditto.

* ext/openssl/ossl_bio.c (ossl_obj2bio): ditto.

* ext/socket/init.c (rsock_socket): ditto.
  (rsock_s_accept_nonblock): ditto.
  (rsock_s_accept): ditto.

* ext/socket/socket.c (rsock_sock_s_socketpair): ditto.

* ext/socket/ancdata.c (discard_cmsg): ditto.
  (make_io_for_unix_rights): ditto.

* ext/socket/unixsocket.c (unix_recv_io): ditto.

* ext/io/console/console.c (console_dev): ditto.

[ruby-core:38140] [Feature #5041]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-22 09:58:15 +00:00
drbrain f365f19054 * random.c: Improve documentation of Random. Patch by Gregory
Parkhurst.  [Ruby 1.9 - Bug #5410]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-05 23:54:33 +00:00
drbrain 9654a4c985 * random.c (Init_Random): Add a top-level comment for Random. Patch
by Brett Bim.  [Ruby 1.9 - Bug #5403]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-04 20:48:34 +00:00
nobu 8e6e8e6288 * use RB_TYPE_P which is optimized for constant types, instead of
comparison with TYPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-09-29 11:07:45 +00:00
akr b41ccc4a9c * include/ruby/intern.h (rb_update_max_fd): declaration moved from
internal.h.

* file.c: ditto.

* io.c: call rb_update_max_fd for each new fds.

* process.c: ditto.

* random.c: ditto.

* ruby.c: ditto.

* ext/io/console/console.c: ditto.

* ext/openssl/ossl_bio.c: ditto.

* ext/pty/pty.c: ditto.

* ext/socket/init.c: ditto.

* ext/socket/socket.c: ditto.

* ext/socket/ancdata.c: ditto.

* ext/socket/unixsocket.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-20 13:26:10 +00:00
marcandre 3f5e567a47 * random.c: Documentation fix for Random#bytes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-27 15:42:37 +00:00
nobu 3a47cf3395 * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-15 11:55:52 +00:00
naruse 63f39fcb40 * random.c (random_rand): remove unused variables.
* struct.c (rb_struct_define_without_accessor): ditto.

* strftime.c (rb_strftime_with_timespec): ditto.

* sprintf.c: ditto.

* time.c (time_asctime): remove useless GetTimeval().

* thread_pthread.c: cast to (void *) for %p.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-25 07:56:42 +00:00
sorah b5909efd13 * random.c (rb_f_rand, random_s_rand): RDocs for them.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-24 23:25:11 +00:00
mrkn 2aeb3b47ee * random.c (random_s_rand, Init_Random): Random.rand should behave as
Random::DEFAULT.rand rather than Kernel#rand.
* random.c (rand_range, random_rand): rand_range function extracted
  from random_rand function.
* random.c (rb_f_rand): accept a Range argument as Random#rand
  [ruby-dev:43427] #4605

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-24 22:27:39 +00:00
naruse 0efb462a50 * random.c (rb_f_srand): fix rdoc: srand(0)'s 0 is a seed.
[ruby-core:35833] fixes #4590

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-20 16:31:25 +00:00
nobu be7e8ca772 * random.c (random_rand): suppress a warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-05 20:17:36 +00:00
akr 0c232beb9c * random.c: parenthesize macro arguments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-12-25 04:08:22 +00:00
nobu 99aaee351e * random.c (random_rand): get rid of overflow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-20 03:04:59 +00:00
naruse 25eebc3ad5 * random.c (rand_init): This checks the value is in 32bit or not,
so use int32_t, not int.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-04 01:24:01 +00:00
naruse b259e449d1 * random.c (rand_init): remove useless assignment.
* re.c (update_char_offset): remove unused variable.

* re.c (read_escaped_byte): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-04 01:23:58 +00:00
naruse 493f721854 * random.c (rb_genrand_ulong_limited): renamed from
rb_rand_internal and now this is public API.

* include/ruby/ruby.h (rb_genrand_ulong_limited): added.

* bignum.c (big_sparse_p): use rb_genrand_ulong_limited.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-09-10 05:44:54 +00:00
nobu 0eb31be681 * random.c (rb_random_int32): suppress warning on LP64 platforms.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-26 07:41:55 +00:00
nobu 8554e16355 * array.c (rb_ary_{shuffle_bang,sample}): use Random class object.
* random.c (try_get_rnd): use default_rand for Random as same as
  singleton methods.

* random.c (rb_random_real): check the range of result.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-25 22:30:03 +00:00
shyouhei 2531892cbc reverted to r29091; r29092 breaks test-all
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-25 12:14:38 +00:00
nobu 00dcf07ebc * random.c (rb_random_int32): fixed typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-25 11:22:55 +00:00
nobu fd1022c065 * random.c (rb_random_real): check the range of result.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-25 09:31:46 +00:00
nobu ae6a9009dc * array.c (rb_ary_{shuffle_bang,sample}): use Random class object.
* random.c (try_get_rnd): use default_rand for Random as same as
  singleton methods.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-25 09:00:17 +00:00
nobu 2f6c0e3be3 * array.c (rb_ary_shuffle_bang, rb_ary_sample): add optional
argument random.  [ruby-dev:41923] [EXPERIMENTAL]

* random.c (rb_random_{int32,real,bytes}): fallback to normal
  method invocation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-23 22:07:39 +00:00
nobu a4c0f7dfae * random.c (Init_Random): add Random::DEFAULT.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-03 12:16:06 +00:00
naruse 7175a9073e * class.c, compile.c, dir.c, file.c, iseq.c, parse.y, random.c:
clean unused-value warnings.

* cont.c, process.c, vm_exec.h: clean cast warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-27 07:13:43 +00:00
nobu 79dfc605ff * random.c (DEFAULT_SEED_LEN): suppress a warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-19 05:45:14 +00:00
nobu 25b9eb5e57 * include/ruby/ruby.h (rb_data_type_t): restructured. [ruby-dev:41862]
add parent member.

* error.c (rb_typeddata_inherited_p): new function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-18 07:31:54 +00:00
nobu 52aa6ab21d * process.c (rb_fork_err): suppress gcc 4.4 warnings.
* random.c (fill_random_seed): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-13 12:28:37 +00:00
nobu a43852a3a4 * random.c (random_rand): add the result of random to the
beginning of range, not the opposite.  [ruby-dev:41415]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-26 11:19:30 +00:00
nobu 93bbd7869c * random.c (random_rand): subtraction method of non-numeric can
return Float, and add the result of random to the beginning of
  range, not the opposite.  [ruby-dev:41410]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-26 03:08:07 +00:00
marcandre 7729de4d91 * array.c: Documentation: change => in call-seq to ->.
Harmonize "#=>" in examples. [ruby-core:30206]

* bignum.c: ditto

* class.c: ditto

* compar.c: ditto

* cont.c: ditto

* dir.c: ditto

* encoding.c: ditto

* enum.c: ditto

* enumerator.c: ditto

* error.c: ditto

* eval.c: ditto

* file.c: ditto

* gc.c: ditto

* io.c: ditto

* load.c: ditto

* marshal.c: ditto

* math.c: ditto

* numeric.c: ditto

* object.c: ditto

* pack.c: ditto

* proc.c: ditto

* process.c: ditto

* random.c: ditto

* range.c: ditto

* re.c: ditto

* ruby.c: ditto

* signal.c: ditto

* sprintf.c: ditto

* string.c: ditto

* struct.c: ditto

* thread.c: ditto

* time.c: ditto

* transcode.c: ditto

* variable.c: ditto

* vm_eval.c: ditto

* vm_method.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-17 21:07:33 +00:00
nobu 5d8c8b46bb * random.c (make_seed_value): fix leading-zero-guard condition on
bdigit is smaller than 32bit.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-13 06:00:49 +00:00
akr 19afeacb88 * random.c (rand_init): use the absolute value of seed to
make srand(-2**40) portable with 32bit and 64bit.
  [ruby-core:29292](2)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-12 15:16:45 +00:00
nobu f571492922 * random.c (rand_init): ignore higher bits if all they are same as
the lower sign bit.  [ruby-core:29292](2)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-07 22:22:36 +00:00
kazu 88a4bf912d fix rdoc. see r26808
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-03 14:57:20 +00:00
nobu 6decf411c6 * random.c (random_rand): raise ArgumentError on nil, as the
documentation implies.  [ruby-core:29075]

* random.c (rb_f_rand): mentioned the case of when max is nil.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-03 01:51:26 +00:00
naruse 46a4000a68 * random.c: change include order; ruby.h should be at first.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-29 00:21:20 +00:00
nobu 21c7d36573 * random.c (default_rand): removed initial buffer.
* random.c (Init_RandomSeed): initialize seed of default random.

* random.c (Init_RandomSeed2): turn the seed to Bignum object.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-15 09:33:39 +00:00
nobu d188e1a852 * random.c (next_state): no initialization here.
* random.c (default_mt): always return initialized MT.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-15 05:06:11 +00:00
naruse 1bf3ca494f * random.c (rb_reset_random_seed): set seed in this. [ruby-core:28655]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-15 03:26:29 +00:00
akr 373ed885c6 fix rdoc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-03 15:14:21 +00:00