300 Commits

Author SHA1 Message Date
KOBAYASHI Shuji 26e6e75ba6 Use Rake DSL instead of commands of FileUtils
- Respect `--verbose(-v)` and `--dry-run(-n)` options.
- Silence warnings to keyword arguments on Ruby 2.7.
2019-12-27 16:49:32 +09:00
Yukihiro "Matz" Matsumoto 6bbdb97e75 Merge pull request #4527 from lopopolo/string-each-line-paragraph-mode
Add paragraph mode to String#each_line in mrblib
2019-09-12 21:19:42 +09:00
Yukihiro "Matz" Matsumoto 5b1f25a4e0 Implement Array#each using inline mruby bytecode. 2019-08-17 14:46:32 +09:00
Yukihiro "Matz" Matsumoto 61763129db Implement Class#new using inline mruby bytecode. 2019-08-16 22:30:03 +09:00
Yukihiro "Matz" Matsumoto 603005ba65 Integrate kazuho/mruby-class-new-fiber-safe in the master.
Avoid calling `initialize` via `mrb_funcall`, which cause `cross C
boundary` error from Fibers started in the method.
2019-08-14 14:09:56 +09:00
KOBAYASHI Shuji 9f18aced9f Enumerable#reject, etc. should return Enumerable without block 2019-08-10 22:18:54 +09:00
Yukihiro "Matz" Matsumoto d5939879cc Fixed a bug in #4034 2019-07-17 10:39:17 +09:00
Yukihiro "Matz" Matsumoto d605b72c1d Merge branch 'master' into i110/inspect-recursion 2019-07-17 10:35:41 +09:00
Yukihiro "Matz" Matsumoto b4cdced22f Enumerable#detect {and #find} should call ifnone; fix #4484
It's an error in ISO specification; 15.3.2.2.4 and 15.3.2.2.7
2019-07-13 18:05:01 +09:00
KOBAYASHI Shuji 32c2aa10c7 Fix Numeric#step to infinity; ref. #4555 2019-07-07 22:10:32 +09:00
dearblue 0d452073f4 Replace String#[]= method by C implements
The purpose is to eliminate string objects that are temporarily created during processing.
2019-06-29 14:41:43 +09:00
Ryan Lopopolo 46c972f746 Unify loops to minimize bytecode size 2019-06-25 00:01:51 +02:00
Ryan Lopopolo 6b92acf361 Use explicit block parameter 2019-06-23 03:40:39 +01:00
Ryan Lopopolo 8ea45b862a Optimize String#each_line 2019-06-23 03:29:47 +01:00
Ryan Lopopolo a932b8c96a Speed up base case by 2x
Make non-paragraph mode twice as fast. Performance is within a factor of 2
of the original implementation.
2019-06-22 12:55:02 +01:00
Ryan Lopopolo 0f516bbe1d Add paragraph mode to String#each_line in mrblib
mruby/mruby#4511 demonstrated an infinite loop in `String#each_line` when
given an empty string separator. In MRI, an empty separator places
String#each_line in paragraph mode, where the String is separated on
successive runs of newlines. In paragraph mode, the String
`"abc\n\n\ndef\nxyz"` is split into `["abc\n\n\n", "def\nxyz"]`.

This commit makes the String#each_line implementation as close to
ruby/spec compliant as possible given the limitations of mruby core.
With this patch, the following specs fail for `String#each_line`:

- uses `$/` as the separator when none is given (can be fixed by
  aliasing and redefining the method to use $/ as the default value
  of separator in mruby-io)
- when no block is given returned Enumerator size should return nil
  (`Enumerator#size` is not supported on mruby)
- tries to convert the separator to a string using to_str (`String#to_str`
  is not implemented on mruby)

This patch has similar memory consumption compared to the prior
implementation and is takes 4x the time the prior implementation takes to
execute:

```console
/usr/bin/time -l ./bin/mruby -e '("aaa\n\nbbbbb\n\n\n\n\ncccc" * 100000).each_line("\n") { }';
```
2019-06-22 12:31:01 +01:00
KOBAYASHI Shuji c75402a57b Fix typo in mrblib/range.rb [ci skip] 2019-06-04 10:45:13 +09:00
Yukihiro "Matz" Matsumoto 780342eddb Add Enumerator support to String#each_byte.
`String#each_byte` is not defined in ISO Ruby but it is implemented in
the core mruby because it's useful.
2019-05-15 14:59:48 +09:00
Yukihiro "Matz" Matsumoto fd37bc53de Remove String#=~ and String#match that requires Regexp. 2019-05-15 09:55:21 +09:00
KOBAYASHI Shuji 270131253f Remove duplicated String#each_char 2019-04-27 12:50:02 +09:00
KOBAYASHI Shuji cdb458ed4e Commented out String#scan because it is not implemented yet 2019-04-21 20:34:39 +09:00
KOBAYASHI Shuji 4a8b88f775 Add type check (conversion) in String#[]=
Before this patch:

  'a'[0] = 1        #=> 1
  'a'[:a] = '1'     #=> ArgumentError
  'a'[:a, 0] = '1'  #=> ArgumentError
  'a'[0, :a] = '1'  #=> ArgumentError
  'a'[0, 1] = 1     #=> 1

After this patch / Ruby:

  'a'[0] = 1        #=> TypeError
  'a'[:a] = '1'     #=> TypeError
  'a'[:a, 0] = '1'  #=> TypeError
  'a'[0, :a] = '1'  #=> TypeError
  'a'[0, 1] = 1     #=> TypeError
2019-04-19 20:14:23 +09:00
KOBAYASHI Shuji 916045921e Remove duplicated include Comparable in mrblib/string.rb 2019-04-18 19:58:05 +09:00
Yukihiro "Matz" Matsumoto 292bffb32e Avoid infinite loop when no Regexp class is available; fix #4363 2019-04-08 20:27:28 +09:00
Yukihiro "Matz" Matsumoto af51119d3a Raise error on failed comparison in sort; ref #4307 2019-03-02 15:46:50 +09:00
KOBAYASHI Shuji 6da3cd5d22 Move NONE to mrblib/enum.rb 2019-02-01 16:02:01 +09:00
KOBAYASHI Shuji 8969edf03b Avoid runtime evaluation for MRB_WITHOUT_FLOAT 2019-01-16 19:32:29 +09:00
KOBAYASHI Shuji de5da4b7f6 Fix coercing for first step counter in Numeric#step
Before:

  a=[]; 7.step(4, -3.0) { |c| a << c }; p a  #=> [7, 4.0]

After / Ruby:

  a=[]; 7.step(4, -3.0) { |c| a << c }; p a  #=> [7.0, 4.0]
2019-01-15 21:41:54 +09:00
KOBAYASHI Shuji b30ca87bd0 Integrate mrblib/float.rb into src/numeric.c
- Avoid hack for `MRB_WITHOUT_FLOAT` in build scripts
- Avoid runtime dispatch for `MRB_WITHOUT_FLOAT`
2019-01-04 20:31:05 +09:00
Yukihiro "Matz" Matsumoto cca19532c5 Remove Kernel#class_defined? which is not available in CRuby; #3829 2019-01-03 11:34:35 +09:00
Yukihiro "Matz" Matsumoto c022e4643f Avoid assignments from type checking String#__to_str. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 610bcc88c2 Removed to_hash conversion method. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto ff08856fe3 Remove implicit conversion using to_str method; fix #3854
We have added internal convenience method `__to_str` which
does string type check.

The issue #3854 was fixed but fundamental flaw of lack of stack
depth check along with fibers still remains. Use `MRB_GC_FIXED_ARENA`
for workaround.
2018-11-19 12:05:46 +09:00
Yukihiro "Matz" Matsumoto afca99a40b Remove implicit conversion using to_int method.
The ISO standard does not include implicit type conversion using
`to_int`. This implicit conversion often causes vulnerability.
There will be no more attacks like #4120.

In addition, we have added internal convenience method `__to_int` which
does type check and conversion (from floats).
2018-11-19 11:28:51 +09:00
take-cheeze b37b312081 Rename libmruby stuff to avoid confusion 2018-10-29 14:07:16 +09:00
Yukihiro "Matz" Matsumoto 34872e90d4 Re-implement Array#_inspect and Hash#_inspect without blocks.
To reduce the env object allocation; ref #4143
2018-10-29 11:55:49 +09:00
Tomoyuki Sahara 91444c4747 replace quicksort with mergesort. 2018-10-18 13:07:47 +09:00
Yukihiro "Matz" Matsumoto 54ec08c7f1 Implement Hash#rehash in C using sg_compact(). 2018-09-26 23:09:48 +09:00
Yukihiro "Matz" Matsumoto d78acc7afe Add index to larger segment lists for performance 2018-09-26 23:09:48 +09:00
Yukihiro "Matz" Matsumoto 8ffd4e47fb Use mrb_undef_value for delete mark instead of shifting Hash entry table.
That means entry table should be compacted periodically by `sg_compact()`.
2018-09-26 23:09:48 +09:00
Yukihiro "Matz" Matsumoto 3a9caad8eb Move Symbol#to_proc to the core from mruby-symbol-ext gem.
Even though `Symbol#to_proc` is not included in ISO standard, the
`some_method(&:method_name)` is used very widely and convenient.
So we moved it to the core.
2018-09-20 13:47:29 +09:00
Yukihiro "Matz" Matsumoto 2be42aef0f Fix ISO/JIS section numbers. 2018-09-01 09:35:46 +09:00
Yukihiro "Matz" Matsumoto a3fb80904d Remove unused Hash#__update method. 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto b3a1d37926 Make Array.new to accept both integers and floats.
This time we used `Integral` module which is mruby specific.
2018-08-25 09:19:17 +09:00
Yukihiro "Matz" Matsumoto b083c1351f Fixed the corner case bug in String#{gsub!,sub!}.
`"a".sub!("a", "a")` should not return `nil`.
2018-08-25 09:17:46 +09:00
Ichito Nagata 2af92d0ebc Let inspect recursion do the right thing 2018-06-04 11:25:10 +09:00
Ichito Nagata 4a2b055cdd let Hash#merge keep ifnone value 2018-06-01 12:48:17 +09:00
Yukihiro "Matz" Matsumoto 50a9c5d7c7 Update the patch to not use funcall in C; ref #4013 2018-04-28 11:26:23 +09:00
kimu_shu 4b29abc565 Fix Enumerable#hash on non 32-bit integer conf. 2018-04-28 11:26:23 +09:00
Tomoyuki Sahara f0e54df4fe sort method should not consume system stack. 2018-04-23 12:28:15 +09:00