Commit graph

229 commits

Author SHA1 Message Date
knu
8fc8d598c9 * array.c (rb_ary_collect), enum.c (enum_collect): rb_warn() is a
bit too noisy when RubyGems, so change it to rb_warning().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@39959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-27 02:10:29 +00:00
nobu
f029920531 * array.c (ary_reject_bang): should not remove elements which are
not yielded.  [Bug #2545]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@32373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-03 04:44:53 +00:00
nobu
056ee295f5 * array.c (ary_reject): fix internal function name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@32364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-01 22:34:59 +00:00
nobu
31e6b1e822 * array.c (rb_ary_reject_bang, rb_ary_delete_if): rejected
elements should be removed.  fixed [Bug #2545]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@32360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-01 22:17:46 +00:00
knu
03373b29e3 * array.c (rb_ary_collect), enum.c (enum_collect): Add
compatibility warnings for a call without a block.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@31013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-03-03 08:11:16 +00:00
knu
abe08c7810 * array.c (rb_ary_sort_by_bang): Add Array#sort_by!.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@29815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-17 09:29:49 +00:00
shyouhei
bcfcbefc26 * array.c (rb_ary_product): Use tmpary instead, to ensure marking
arrays by GC.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@28050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-28 08:51:41 +00:00
marcandre
b6ca597bd0 * array.c (rb_ary_sample): Fix infinite loop bug [ruby-core:27075]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-06 21:43:46 +00:00
marcandre
ea1b7a9577 * time.c: rdoc fix for <=>
* array.c: ditto

* bignum.c: ditto

* compar.c: ditto

* file.c: ditto

* numeric.c: ditto

* string.c: rdoc fix for <=> and casecmp

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@25523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-28 05:01:29 +00:00
nobu
3f0d0b9398 * *.[chy]: removed trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@25430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-22 01:00:18 +00:00
knu
e8b0f17319 * array.c (ary_resize_capa): Remove an unused function.
* array.c, bignum.c, dir.c, enumerator.c, gc.c, io.c, numeric.c,
  object.c, re.c, string.c, struct.c: Mixing two styles is not a
  good thing.  Stick with the K&R style in 1.8.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@23052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-23 12:07:23 +00:00
knu
f1f12658ee * array.c (Array#try_convert): New method backported from 1.9.
* hash.c (Hash#try_convert): New method backported from 1.9.

* io.c (IO#try_convert): New method backported from 1.9.

* re.c (Regexp#try_convert): New method backported from 1.9.

* string.c (String#try_convert): New method backported from 1.9.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@23018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-20 09:43:24 +00:00
nobu
2dd66361f7 * array.c (rb_ary_aset): fixed arguments evaluation order.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@21780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-26 07:00:43 +00:00
matz
76d9148d77 * array.c (ary_double_capa): a new function to expand array more
aggressively.   [ruby-core:21460]

* array.c (rb_ary_store): use ary_double_capa().

* array.c (rb_ary_splice): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@21721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-21 15:33:06 +00:00
knu
0c6fdc530b * array.c (rb_ary_nitems, rb_ary_choice): Add a deprecation
warning.

* hash.c (env_index, rb_hash_index): Simplify the deprecation
  warnings.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@20783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-16 08:15:21 +00:00
nobu
a2a9858b98 * array.c (rb_ary_join): do not repeat self in a recursive array.
[ruby-dev:37019]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@20103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-11-03 18:28:34 +00:00
knu
9ba8db842e * array.c (rb_ary_choice): Resurrect #choice. Let me think about
it for a while.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@18514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-12 05:56:10 +00:00
matz
e65c07e98b * array.c (rb_ary_sample): rename #choice to #sample. in
addition, sample takes optional argument, a la #first.

* random.c (Init_Random): always initialize seed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@18509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-12 05:08:52 +00:00
akr
8e34a3d9c0 * array.c (rb_ary_fill): don't raise even if length is negative.
[ruby-core:17483], [ruby-core:17661]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-09 12:01:08 +00:00
nobu
f712a4f497 * array.c (rb_ary_fill): check if beg is too big.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-01 04:19:47 +00:00
nobu
50ba0ce29e * array.c (rb_ary_fill): check for negative length.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-29 10:19:48 +00:00
nobu
d530436d0c * array.c (rb_ary_fill): not depend on unspecified behavior at integer
overflow.  reported by Vincenzo Iozzo <snagg AT openssl.it>.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-25 06:28:53 +00:00
nobu
3db4641b2a * array.c (rb_ary_store, rb_ary_splice): not depend on unspecified
behavior at integer overflow.

* string.c (str_buf_cat): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-20 06:42:07 +00:00
shyouhei
4a3f1dfb58 * array.c (ary_new, rb_ary_initialize, rb_ary_store,
rb_ary_aplice, rb_ary_times): integer overflows should be
  checked. based on patches from Drew Yao <ayao at apple.com>
  fixed CVE-2008-2726

* string.c (rb_str_buf_append): fixed unsafe use of alloca,
  which led memory corruption. based on a patch from Drew Yao
  <ayao at apple.com> fixed CVE-2008-2726

* sprintf.c (rb_str_format): backported from trunk.

* intern.h: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-19 23:12:46 +00:00
knu
520bf6bb34 * array.c (rb_ary_delete_if): should return enumerator if no block
is given.  [ruby-dev:34901]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-31 11:57:40 +00:00
knu
14dd72b35a * enum.c (count_i, count_iter_i): Sync with trunk.
enum.c (enum_count, count_all_i, Init_Enumerable),
  array.c (rb_ary_count): Sync with trunk.  If no argument or
  block is given, count the number of all elements.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16694 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-29 19:35:04 +00:00
knu
61fd28b3cf Fix a typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-29 13:50:59 +00:00
knu
94e9302374 * array.c (rb_ary_slice_bang): Call rb_ary_modify_check() at the
beginning. [rubyspec]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-28 07:54:44 +00:00
knu
c8b99039e6 * array.c (rb_ary_slice_bang): Return an empty array instead of
nil when pos is valid and len is adjusted from a valid value to
  zero; caught by RubySpec.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-27 11:19:35 +00:00
knu
065f538086 * array.c (rb_ary_slice_bang): Be consistent with Array#slice()
and String#slice!().  Just return nil when a negative length or
  out of boundary index is given instead of raising an exception
  via internal functions.
  (rb_ary_slice_bang): should not use rb_ary_subseq() which shares
  internal pointer.  splice modifies the receiver right after
  subseq.  [ruby-dev:34005]
  (rb_ary_slice_bang): should adjust length before making
  sub-array.

* enumerator.c (Init_Enumerator): Override
  Enumerable::Enumerator#each_with_index with #with_index.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-24 20:07:54 +00:00
nobu
0ba197f08f * array.c (flatten): check if reentered. [ruby-dev:34798]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-22 05:20:59 +00:00
matz
eb995e1120 * array.c (flatten): free memo hash table before raising exception.
[ruby-dev:34789]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-22 00:57:53 +00:00
nagai
b8424eaf02 * array.c (flatten): fix memory leak.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-21 21:38:59 +00:00
knu
d007e7d20f * array.c (rb_ary_count): Override Enumerable#count for better
performance.
  (rb_ary_nitems): Undo the backport.  Use #count {} instead.

* enumerator.c (enumerator_iter_i): Remove an unused function.
  (enumerator_with_index, enumerator_each): Remove unused
  variables.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-14 10:26:48 +00:00
nobu
56d973d728 * array.c (flatten): returns an instance of same class.
[ruby-core:16554]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-25 03:37:57 +00:00
knu
80627a281e * array.c (rb_ary_equal, rb_ary_eql, rb_ary_hash, rb_ary_cmp):
Make Array#eql?, #hash, #== and #<=> use rb_exec_recursive() and
  handle recursive data properly.

* hash.c (hash_equal, rb_hash_hash): Make Hash#eql?, #hash and #==
  use rb_exec_recursive() and handle recursive data properly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-19 11:11:25 +00:00
nobu
4ef650d064 * array.c (rb_ary_take_while, rb_ary_drop_while): removed unused
variables.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-15 04:29:48 +00:00
knu
f2dc726691 * array.c (rb_ary_flatten, rb_ary_flatten_bang): Take an optional
argument that determines the level of recursion to flatten;
  backported from 1.9.

* array.c (rb_ary_shuffle_bang, rb_ary_shuffle, rb_ary_choice,
  rb_ary_cycle, rb_ary_permutation, rb_ary_combination,
  rb_ary_product, rb_ary_take, rb_ary_take_while, rb_ary_drop,
  rb_ary_drop_while): New methods: Array#shuffle, #shuffle!,
  #choice, #cycle, #permutation, #combination, #product, #take,
  #take_while, #drop, #drop_while; backported from 1.9.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-14 11:03:42 +00:00
knu
125d830eb8 * array.c (rb_ary_collect_bang, rb_ary_select): Return an
enumerator if no block is given.

* dir.c (dir_each, dir_foreach): Return an enumerator if no block
  is given.

* enum.c (enum_partition, enum_sort_by): Ditto.

* gc.c (os_each_obj): Ditto.

* hash.c (rb_hash_delete_if, rb_hash_reject_bang, rb_hash_select,
  rb_hash_each_value, rb_hash_each_key, rb_hash_each_pair,
  env_each_key, env_each_value, env_each, env_each_pair,
  env_reject_bang, env_delete_if, env_select): Ditto.

* numeric.c (num_step, int_upto, int_downto, int_dotimes): Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-14 08:57:23 +00:00
knu
8ca8703de2 * enum.c (enum_count, enum_find_index): New methods:
Enumerable#count and #find_index; backported from 1.9.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-14 07:04:30 +00:00
knu
8202fc3bc3 * array.c (rb_ary_first, rb_ary_last): Return a shared array when
possible.

* array.c (rb_ary_pop, rb_ary_pop_m, rb_ary_shift, rb_ary_shift_m):
  Array#pop and Array#shift can take an optional argument
  specifying the number of elements to remove and return;
  backported from 1.9.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-10 10:36:10 +00:00
knu
99a6e8a3ed Fix a typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-09 12:56:36 +00:00
knu
357f65d592 * array.c (rb_ary_pop): Do not reallocate too often; backported
from 1.9.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-09 12:56:02 +00:00
knu
0c0881d517 Array#reject too.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-09 12:34:35 +00:00
knu
343069e16a * array.c (rb_ary_each, rb_ary_each_index, rb_ary_reverse_each,
rb_ary_reject_bang): Calling Array#each, #each_index,
  #reverse_each, #reject! or #delete_if without a block now
  returns an enumerator; backported from 1.9.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-09 12:21:25 +00:00
knu
c5827ca193 * array.c (rb_ary_index, rb_ary_index): Array#index and #rindex
take a block instead of an argument; backported from 1.9.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-09 11:53:15 +00:00
knu
86d05f81fd * array.c (rb_ary_nitems): Backport Array#nitems with a block;
suggested by Bertram Scharpf <lists@bertram-scharpf.de> in
  [ruby-talk:134083].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-07 12:40:45 +00:00
knu
b0388e77e3 * array.c (rb_ary_slice_bang): If an invalid negative index (<=
-size) is given, do not raise an exception but return nil just
  like slice() does.

* test/ruby/test_array.rb (TestArray::test_slice,
  TestArray::test_slice!): Pull in test cases from trunk.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@14184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-10 15:08:31 +00:00
matz
35c9feaeb7 * array.c (rb_ary_assoc): check and convert inner arrays (assocs)
using #to_ary.

* hash.c (rb_hash_s_create): check and convert argument hash
  using #to_hash.

* hash.c (rb_hash_s_create): Hash#[] now takes assocs as source of
  hash conversion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@13803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-02 06:30:26 +00:00
matz
d84ece5c1c * array.c (rb_ary_subseq): need integer overflow check.
[ruby-dev:31736]

* array.c (rb_ary_splice): ditto.  [ruby-dev:31737]

* array.c (rb_ary_fill): ditto.  [ruby-dev:31738]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@13345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-09-05 13:36:28 +00:00