Commit Graph

200 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto bbb0882343 Modifying frozen objects will raise FrozenError.
`FrozenError` is a subclass of `RuntimeError` which used to be
raised.  [Ruby2.5]
2017-12-12 18:41:18 +09:00
Yukihiro "Matz" Matsumoto 03a3bd9178 The number of argument should be retrieved by mrb_get_argc; fix #3848
You should not access `mrb->c->ci->argc` directly.
2017-11-13 16:16:38 +09:00
YAMAMOTO Masaya acdc2d1f24 Add MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
Yukihiro "Matz" Matsumoto 85a400e43d Reimplement Array#shift to be faster. 2017-08-26 02:03:21 +09:00
Yukihiro "Matz" Matsumoto cec53ff77e Array#first to treat 1 argument case specially to improve performance. 2017-08-26 02:03:21 +09:00
Yukihiro "Matz" Matsumoto 9146d5c34f Zero width unshift should not touch memory; ref #3780 2017-08-19 11:11:26 +09:00
Yukihiro "Matz" Matsumoto 8b3298b2d6 Unshift pointer move size was wrong (not len but alen); fix #3780 2017-08-19 11:08:46 +09:00
Yukihiro "Matz" Matsumoto 8fbc4bef55 Reduce signed/unsigned comparison warnings; ref #3785 2017-08-18 22:54:59 +09:00
Yukihiro "Matz" Matsumoto f1767fd079 Separate mrb_str_buf_new and mrb_str_new_capa.
`mrb_str_buf_new` is an old function that ensures capacity size of
`MRB_STR_BUF_MIN_SIZE` minimum. Usually one need to use
`mrb_str_new_capa` instead.
2017-08-18 22:17:48 +09:00
Miura Hideki 75ec86ed00 Improve Array structure 2017-08-18 20:12:00 +09:00
Yukihiro "Matz" Matsumoto ef0b239704 Remove unnecessary inline function ary_elt.
And the function does not conform the naming convention anyway.
2017-08-11 12:57:37 +09:00
Yukihiro "Matz" Matsumoto 006661394d Fixed heap buffer overflow in mrb_ary_unshift_m; fix #3760 2017-08-05 01:18:52 +09:00
Yukihiro "Matz" Matsumoto f26d00d9e8 Embed small size array elements in the heap.
It reduces the memory consumption and sometimes improve the
performance as well.  For example, the consumed memory size
of `bench/bm_ao_render.rb` is reduced from 1.2GB to 1GB, and
its total execution time become 18.795 sec from 22.229 sec.
2017-07-27 16:13:06 +09:00
Yukihiro "Matz" Matsumoto a18904a4c2 Use "$!" specifier of mrb_get_args. 2017-07-12 14:49:55 +09:00
Yukihiro "Matz" Matsumoto 059d707e3a Add ary_modify_check() to Array#unshift; ref #3737 2017-07-12 14:44:36 +09:00
ksss bf48473cf6 Should only check frozen for Array#pop 2017-07-09 18:05:21 +09:00
ksss e581f2ed97 Should only check frozen fix #3737 2017-07-09 17:47:10 +09:00
Yukihiro "Matz" Matsumoto bf1cb87b34 Array size can be cause integer overflow; fix #3710 2017-06-20 20:19:37 +09:00
Yukihiro "Matz" Matsumoto aa8121cf3a Use mrb_int instead of size_t for array capacity and length. 2017-06-17 08:39:43 +09:00
Yukihiro "Matz" Matsumoto 2837de95fe Prevent splicing big recursive arrrays; ref #3679
We know this is not perfect, but this change makes hack like #3679
bit harder. Harmless for useful cases.
2017-05-31 23:03:39 +09:00
Yukihiro "Matz" Matsumoto 3e07a2d77c Silence warnings caused by implicit type casting. 2017-04-25 21:00:16 +09:00
Yukihiro "Matz" Matsumoto 5a445f012e Add alias "append" to Array#push, and "prepend" to Array#unshift.
According to CRuby [Feature#12746]
2017-04-01 21:27:23 +09:00
okkez 6dbe2272cf Set proper class to subclass of Array
More compatibility to CRuby.
2017-03-29 08:02:21 +09:00
Yukihiro "Matz" Matsumoto 09574922a9 Should not check/call to_str for immediate objects; ref #3515 2017-03-19 20:59:30 +09:00
Yukihiro "Matz" Matsumoto 6db38c3768 Need not to call mrb_obj_as_string() is sep is nil. 2017-03-19 00:28:52 +09:00
Yukihiro "Matz" Matsumoto 72bff2932b Use size_t to avoid integer overflow in mrb_ary_splice(); fix #3413 2017-01-24 11:36:27 +09:00
ksss 78a395d446 Refactoring: Use array_copy instead of for loop 2017-01-23 15:18:48 +09:00
Yukihiro "Matz" Matsumoto 5e1d923381 Changed the behavior of mrb_range_beg_len(); close #3411
The new API is:

int mrb_range_beg_len(mrb, range, &beg, &len, len, trunc)

The new argument `trunc` is a boolean value that specifies
whether the function truncates the range. The new return value
is an integer instead of a boolean, that is:

 0: not a range
 1: range with proper edges
 2: out of range

To get the old behavior, you have to rewrite:

  mrb_range_beg_len(mrb, range, &beg, &len, len)

to:

  mrn_range_beg_len(mrb, range, &beg, &len, len, TRUE) == 1

[Breaking Change]
2017-01-23 14:35:26 +09:00
Yukihiro "Matz" Matsumoto 49fd7590df Use mrb_write_barrier() instead of mrb_field_write_barrier_value()
ref #3409
2017-01-23 10:32:33 +09:00
Yukihiro "Matz" Matsumoto fdec607cd0 Remove unnecessary inline declaration; ref #3409 2017-01-23 10:30:14 +09:00
Yukihiro "Matz" Matsumoto 9d0f07e6a7 Merge pull request #3409 from ksss/mrb_ary_splice
Rewrite mrb_ary_splice
2017-01-23 10:28:09 +09:00
ksss b49bd70f59 Should raise RuntimeError when object frozen 2017-01-22 18:53:20 +09:00
ksss 65c9baae7c Rewrite mrb_ary_splice
Referenced to CRuby's array.c(rb_ary_splice)

fix #3405
2017-01-22 14:06:23 +09:00
Yukihiro "Matz" Matsumoto 392d7fbef9 Add ary_modify() checks; close #3379
This issue was reported by https://hackerone.com/an0n-j
2017-01-07 12:26:29 +09:00
Yukihiro "Matz" Matsumoto 885d929398 Improve capacity enhancing conditions 2017-01-06 14:53:00 +09:00
Yukihiro "Matz" Matsumoto cfdd1e3cc6 ary_expand_capa(): refine conditions to avoid infinite loop; ref #3353 2016-12-31 23:22:17 +09:00
Yukihiro "Matz" Matsumoto 9d84f0d47b ary_expand_capa(): size calculation by size_t; fix #3353
Also more size checks added.
2016-12-31 23:09:56 +09:00
ksss caba1a19dc Check array max size
Fix #3354
2016-12-27 15:48:53 +09:00
Yukihiro "Matz" Matsumoto 9781f7f0ea Add "not reached" mark in mrb_ary_concat() 2016-12-18 02:02:30 +09:00
Yukihiro "Matz" Matsumoto 92c843dd07 rename prefix RBASIC_ to MRB_; ref #3340 2016-12-12 00:54:36 +09:00
Takashi Kokubun 10bb7ad693 Implement Object#freeze 2016-12-11 03:44:15 +09:00
Clayton Smith 2bc3a5fb78 Fix more integer overflows. 2016-12-01 09:08:38 -05:00
Yukihiro "Matz" Matsumoto ab4ab7c8a0 Fix compile error by #3309 2016-12-01 18:37:03 +09:00
Clayton Smith acdddb4f14 Prevent array size calculation overflows. 2016-11-30 13:55:09 -05:00
Clayton Smith b633aa9ad4 Use size_t to calculate bytes needed for array. 2016-11-29 10:26:02 -05:00
Yukihiro "Matz" Matsumoto 246a9a8acd ary_concat: support self concatenation; fix #3302 2016-11-29 22:36:11 +09:00
Yukihiro "Matz" Matsumoto 0c924b9287 fixed a bug in self modifying Array#[]=; fix #3274 2016-11-24 19:30:21 +09:00
Yukihiro "Matz" Matsumoto 1f554ff854 Fixed rindex calling into mrb_equal bug
Fixed by Alex Snaps and reported by Mathieu Leduc-Hamel,
both from shopify.com.  Thank you!
2016-11-16 02:10:44 +09:00
Yukihiro "Matz" Matsumoto 739dad6e87 Fixed a memory problem in Array#to_h
Reported from Alex Snaps via Mathieu Leduc-Hamel,
both from shopify.com.  Thank you!
2016-11-16 01:29:04 +09:00
ksss d265c03da0 Fix SEGV when splat object
Splat operation should return an array.
And raise an error if result of convert by to_a is not array or nil.
2016-09-08 16:35:17 +09:00