Commit Graph

164 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 6b457d2c00 Merge branch 'work_for_merge' of https://github.com/zubycz/mruby into zubycz-work_for_merge 2020-10-15 18:35:13 +09:00
Yukihiro "Matz" Matsumoto 9cebddf9fe Merge pull request #5084 from mruby/mruby3
Mruby3
2020-10-15 18:31:06 +09:00
taiyoslime bec4d05340 Introduce endless range (a part of #5085)
Co-Authored-By: n4o847 <22975590+n4o847@users.noreply.github.com>
Co-Authored-By: smallkirby <ssmallkirby@gmail.com>
2020-10-13 14:09:36 +09:00
Yukihiro "Matz" Matsumoto 2b188ed8a1 Reorganize Integer system.
- Integrate `Fixnum` and `Integer`
- Remove `Integral`
- `int / int -> int`
- Replace `mrb_fixnum()` to `mrb_int()`
- Replace `mrb_fixnum_value()` to `mrb_int_value()`.
- Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12 18:19:54 +09:00
n4o847 59af217779 Remove unnecessary assignment in String#upto
Co-authored-by: taiyoslime <t@iyosli.me>
Co-authored-by: smallkirby <ssmallkirby@gmail.com>
2020-10-12 16:50:22 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT`
- `MRB_USE_FLOAT` => `MRB_USE_FLOAT32`

The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +09:00
dearblue 57611240a9 Prohibit string changes by "s"/"z" specifier of mrb_get_args()
- The `s` specifier is a string pointer obtained without performing `mrb_str_modify()`, so it cannot be changed.
- The `z` specifier cannot be changed because it is a string pointer obtained by `RSTRING_CSTR()` which returns `const char *`.
2020-09-25 21:02:58 +09:00
Yukihiro "Matz" Matsumoto 49ae2a69f2 Add mrb_get_arg1() that retrieves single (and only) argument.
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one
argument.

And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
2020-06-20 12:49:46 +09:00
Yukihiro "Matz" Matsumoto 106f4c4e9d Add proper casts to silence VC warnings. 2020-06-05 16:04:30 +09:00
KOBAYASHI Shuji 7047c52d7b Use mrb_str_cat_str instead of mrb_str_concat if possible 2019-10-20 16:26:10 +09:00
KOBAYASHI Shuji 7ce5d33947 Integrate mrb_str_inspect and mrb_str_dump 2019-10-10 19:50:48 +09:00
KOBAYASHI Shuji f252ab0770 Use mrb_define_method instead of mrb_define_alias 2019-09-21 16:51:10 +09:00
KOBAYASHI Shuji 0bedd900b9 Remove mrb_get_args(mrb, ""); ref 30f37872 2019-09-18 16:07:21 +09:00
Yukihiro "Matz" Matsumoto 57d7fe94a9 Add a macro mrb_frozen_p that points to MRB_FROZEN_P. 2019-09-14 23:21:44 +09:00
Yukihiro "Matz" Matsumoto 04b098d000 Move tests related to getbyte, setbyte, byteslice` to core. 2019-09-11 18:49:08 +09:00
Yukihiro "Matz" Matsumoto ec3aeede20 Move String#{getbyte,setbyte,byteslice} to the core; #4696
Unlike CRuby, there's no way to process strings byte-wise by core
methods because there's no per string encoding in mruby, so that
we moved 3 byte-wise operation methods from `mruby-string-ext` gem.
2019-09-11 18:47:39 +09:00
KOBAYASHI Shuji fab781cf8b Drop test dependency from mruby-string-ext to mruby-enumerator 2019-09-11 10:35:52 +09:00
dearblue 05a873c25c Simplify get arguments
- `mrb_str_index_m()` and `mrb_str_rindex()`
  Make `mrb_get_args()` called only once from called twice.
- `mrb_str_byteslice()`
  Replace `goto` with `if ~ else`.
2019-08-18 15:38:25 +09:00
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in
my environment than before the introduction of new specifiers/modifiers
(5116789a) with this change.

  ------------+-------------------+-------------------+--------
   BINARY     | BEFORE (5116789a) |   AFTER (This PR) |  RATIO
  ------------+-------------------+-------------------+--------
   mruby      |      593416 bytes |      593208 bytes | -0.04%
   libmruby.a |      769048 bytes |      767264 bytes | -0.23%
  ------------+-------------------+-------------------+--------

BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613,
so I put it back.
2019-08-05 13:18:50 +09:00
Yukihiro "Matz" Matsumoto 5779464ec3 Add return to silence a warning; ref #4593 2019-07-24 10:50:22 +09:00
KOBAYASHI Shuji e86aa61f20 Add encoding argument to Integral#chr
Currently, `Integral#chr` in mruby changes behavior by `MRB_UTF8_STRING`
setting.

before this patch:

  $ bin/mruby -e 'p 171.chr'  #=> "\xab"  (`MRB_UTF8_STRING` is disabled)
  $ bin/mruby -e 'p 171.chr'  #=> "«"     (`MRB_UTF8_STRING` is enabled)

This behavior is incompatible with Ruby, and a little inconvenient because
it can't be interpreted as ASCII-8BIT with `MRB_UTF8_STRING`, I think.

So add encoding argument according to Ruby.

after this patch:

  $ bin/mruby -e 'p 171.chr'                #=> "\xab"
  $ bin/mruby -e 'p 171.chr("ASCII-8BIT")'  #=> "\xab"
  $ bin/mruby -e 'p 171.chr("UTF-8")'       #=> "«"

Allow only `String` for encoding because mruby doesn't have `Encoding`
class, and `"ASCII-8BIT"` (`"BINARY"`) and `"UTF-8"` (only with
`MRB_UTF8_STRING`) are valid value (default is `"ASCII-8BIT"`).
2019-07-23 20:16:46 +09:00
KOBAYASHI Shuji c980fe2792 Integrate Integral#chr (Fixnum#chr) to mruby-string-ext
Because they're defined in both `mruby-string-ext` and `mruby-numeric-ext`
(they seem more natural to define in N, but `mruby-string-ext` depends on
`Integral#chr`).
2019-07-21 22:59:41 +09:00
KOBAYASHI Shuji 8ab846b5b9 Refine String#chr test and separate Fixnum#chr test 2019-07-19 21:48:06 +09:00
Ryan Lopopolo eab07daf92 Add Range#max and Range#min tests from Ruby Spec 2019-07-09 01:41:10 -07:00
Ryan Lopopolo 469c6261c6 Add tests for String Ranges
Range#each depends on String#upto which is implemented in mruby-string-ext
which is why these tests live there.
2019-07-08 22:36:24 -07:00
KOBAYASHI Shuji bc3176da63 Use __ENCODING__ in tests
It cannot be used for `String#size` test if judging whether or not `MRB_UTF8_STRING` is defined by result of `String#size`.
2019-06-28 19:26:29 +09:00
KOBAYASHI Shuji 75df13a973 Fix String#byteslice with MRB_UTF8_STRING and some edge cases
Example:

  $ bin/mruby -e '
    p "あa".byteslice(1)
    p "bar".byteslice(3)
    p "bar".byteslice(4..0)
  '

  Before this patch:

    "a"
    ""
    RangeError (4..0 out of range)

  After this patch (same as Ruby):

    "\x81"
    nil
    nil
2019-06-25 23:09:23 +09:00
KOBAYASHI Shuji db3e6f6ac6 Fix typo in String#setbyte error message 2019-06-12 20:45:27 +09:00
dearblue 56e0e1934d Name the return value of mrb_range_beg_len() 2019-05-25 12:12:21 +09:00
KOBAYASHI Shuji 270131253f Remove duplicated String#each_char 2019-04-27 12:50:02 +09:00
KOBAYASHI Shuji cd4daf78ec Use FrozenError instead of RuntimeError in String#rstrip! 2019-03-15 22:49:40 +09:00
KOBAYASHI Shuji e3b339bec6 Fix missing assertions in mruby-string-ext test 2019-03-12 21:47:33 +09:00
Yukihiro "Matz" Matsumoto b5d43a16a3 Removed String#try_convert method from mruby-string-ext gem.
Because `try_convert` method rarely used in production. For mruby users,
we have `__to_str` utility method to check string type.
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
Yukihiro "Matz" Matsumoto 485955eccc String#{squeeze,delete,count} to use bitmap for matching; ref #4163 2018-11-15 04:51:27 +09:00
Yukihiro "Matz" Matsumoto 4550f4e381 Pattern length may overflow uint16_t; fixed #4163
The issue is reported by `https://hackerone.com/dgaletic`.
2018-11-15 02:03:54 +09:00
Yukihiro "Matz" Matsumoto f2084f300b Add tests for empty patterns for tr and count; #4156 #4157 2018-11-02 08:58:21 +09:00
Yukihiro "Matz" Matsumoto 8e59695625 Empty pattern string for String#tr should remove characters; fix #4157 2018-11-02 08:55:17 +09:00
Yukihiro "Matz" Matsumoto 65b04066a2 Empty pattern string can generate TR_UNINITIALIZED pattern; fix #4156 2018-11-02 08:54:24 +09:00
Yukihiro "Matz" Matsumoto 7ad53273a2 Silence Appveyor's VC compilation warnings. 2018-11-01 22:52:12 +09:00
Yukihiro "Matz" Matsumoto cca5e0977c VS 2017 C does not understand inline struct initialization; ref #4153 2018-10-30 09:01:12 +09:00
take-cheeze 52d55e6069 Keep tr_pattern static 2018-10-29 13:21:36 +09:00
Yukihiro "Matz" Matsumoto e6841abad6 Fixed a String#squeeze bug in handling iso-8859-1 strings; ref #4127 2018-09-27 21:43:35 +09:00
Yukihiro "Matz" Matsumoto 01c2f59e14 Revert "Fix comparisons in str_squeeze."
This reverts commit 7b04fcd092.
The issue was addressed by 9e3cbaa. No longer needed.
2018-09-26 12:35:25 +09:00
Yukihiro "Matz" Matsumoto 9e3cbaaacd Avoid using memmove() for performance; fix #4130 2018-09-26 12:20:37 +09:00
Yukihiro "Matz" Matsumoto fb49a94314 Rename tr_pattern_free() to tr_free_pattern(). 2018-09-26 12:17:38 +09:00
Takeshi Watanabe 67897195de Fix leak in mrb_str_count 2018-09-25 11:48:59 +09:00
Clayton Smith 7b04fcd092 Fix comparisons in str_squeeze. 2018-09-24 18:16:12 -04:00
Yukihiro "Matz" Matsumoto 346f154ece Implement String#delete and #delete!; ref #4086
mruby restriction:
In mruby, `String#delete` only takes single pattern argument.
2018-09-21 00:03:07 +09:00