Commit Graph

417 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 905fef2669 Reduce invocation of mrb_convert_type() from mrb_str_to_str(). 2019-02-06 22:07:11 +09:00
KOBAYASHI Shuji 7a2865cfef Fix markup and remove unneeded comment for doc in src/string.c [ci skip] 2019-02-05 19:11:59 +09:00
KOBAYASHI Shuji 69fd1a5925 Fix Symbol#size for multi-byte characters with MRB_UTF8_STRING
Before:

  p :あ.size  #=> 3

After:

  p :あ.size  #=> 1
2019-02-04 18:11:22 +09:00
KOBAYASHI Shuji 486154ce34 Remove unused macro in src/string.c 2019-01-29 20:21:25 +09:00
Yukihiro "Matz" Matsumoto c03fa0e1b3 Recover String#to_str; ref #4177
We have removed implicit conversion to strings using `to_str`. But some
people still using `to_str` as a typical string method, i.e. they do
string check by code like: `obj.respond_to?(:to_str)`. So we have
recovered the method.
2018-12-17 15:59:42 +09:00
Yukihiro "Matz" Matsumoto 65a2c2082d Call mrb_str_to_str from mrb_string_value_ptr for compatibility. 2018-11-19 17:11:19 +09:00
Yukihiro "Matz" Matsumoto 9516731329 Use type checking mrb_to_str instead of converting mrb_str_to_str. 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 adb1eae912 Use mrb_raise() instead of mrb_raisef(); ref #4062 2018-06-28 22:40:24 +09:00
Yukihiro "Matz" Matsumoto 695f29cd60 Add negative check in mrb_str_resize; fix #4062 2018-06-27 16:32:24 +09:00
Yukihiro "Matz" Matsumoto 2d4c092de7 Need to call mrb_str_modify() in mrb_str_cat_str(); fix #4018
If `str` and `str2` are the same string object `str->ptr` may be
rewritten by `mrb_str_modify()`.
2018-05-02 22:50:55 +09:00
Yukihiro "Matz" Matsumoto 0fee6e1ee9 Fix broken support of MRB_WITHOUT_FLOAT; fix #4015 2018-04-28 15:15:28 +09:00
Takeshi Watanabe 87ef6aeb02 Fallback to float when caompiled binary with 64bit compiler.
closes #3997.
2018-04-17 22:59:07 +09:00
Takeshi Watanabe 77a3863a3d Return nil if type differ in String#<=>. 2018-03-24 16:18:44 +09:00
Yukihiro "Matz" Matsumoto 1d55260423 String#inspect to use hexadecimal, not octal to print unprintable. 2018-02-12 22:56:24 +09:00
Lothar Scholz 06f90a3b45 Make source compilable with C++17
Changes applied:

- Removing "register" keyword
- Fixing const pointer to pointer assignments
- Adding type casts to rb_malloc calls
2017-12-23 01:10:43 +01:00
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 f723832ebc Should allocate memory region before updating len; fix #3842
Otherwise half-baked string object will be allocated.
2017-11-08 08:46:55 +09:00
YAMAMOTO Masaya 625f9f6fa3 Merge branch 'master' of github.com:mruby/mruby 2017-11-04 01:23:12 +09:00
Yukihiro "Matz" Matsumoto e4662d77e7 Should not use FSHARED state for string from irep pools; fix #3829
This strings in `irep` pools may be freed forcefully in `mrb_irep_free`.
This commit probably fixes #3817 as well.
2017-11-03 08:24:47 +09:00
YAMAMOTO Masaya acdc2d1f24 Add MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
Yukihiro "Matz" Matsumoto 7edbe428ca Add new type of shared string: RSTR_FSHARED.
`RSTR_FSHARED` use frozen strings as shared body instead of
`struct mrb_shared_string`. This reduces allocation from
literal strings.
2017-10-01 16:24:43 +09:00
Tomasz Dąbrowski 53f934a7ee fix: src\string.c(2219): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski ef8df492e9 fix: src\string.c(1924): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 027b8d8377 fix: src\string.c(1130): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 46ccabacf0 fix: src\string.c(497): warning C4244: '=': conversion from 'mrb_int' to 'long', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 3e1d60ae0b fix: src\hash.c(27): warning C4244: '=': conversion from 'mrb_int' to 'khint_t', possible loss of data 2017-09-27 22:22:05 +02:00
Yukihiro "Matz" Matsumoto ab3b6dbd2a strlen returns size_t; need to cast before assigning to int. 2017-08-22 08:14:09 +09:00
Yukihiro "Matz" Matsumoto 3f90af6b42 (Try to) fix mixture of int and size_t in UTF-8 conversion.
This only effects VC.
2017-08-22 07:35:51 +09:00
Yukihiro "Matz" Matsumoto a8bd06904d mrb_str_cat: capa should not be zero to avoid infinite loops. 2017-08-18 23:42:34 +09:00
Yukihiro "Matz" Matsumoto a06adb176f mrb_str_cat: capa should be bigger than total. 2017-08-18 23:42:33 +09:00
Yukihiro "Matz" Matsumoto 8b5be554c7 ARY_CAPA handles capacity for embedded arrays by itself. 2017-08-18 23:42:33 +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
Yukihiro "Matz" Matsumoto 722d123b87 Remove code duplication in mrb_str_concat. 2017-08-18 22:17:48 +09:00
Yukihiro "Matz" Matsumoto 4c25738ac7 Merge str_buf_cat and mrb_str_cat. 2017-08-18 22:17:47 +09:00
Yukihiro "Matz" Matsumoto 0ff28c9e60 Silence integer type conversion warnings. 2017-08-11 13:10:31 +09:00
Christopher Aue 2fadddcd20 Replaced tabs with spaces 2017-08-09 21:56:27 +02:00
Christopher Aue c7018ea962 Added mrb_str_index to the mrb API 2017-07-28 21:07:20 +02:00
Yukihiro "Matz" Matsumoto a18904a4c2 Use "$!" specifier of mrb_get_args. 2017-07-12 14:49:55 +09:00
Yukihiro "Matz" Matsumoto c377d504f6 Avoid undefined behavior of signed integer overflow; fix #3728 2017-07-05 03:11:39 +09:00
ksss bdb36b3404 Make string embad from shared 2017-05-13 22:44:52 +09:00
ksss 8cba9a9e42 Adjust to the optimum type 2017-05-05 14:20:21 +09:00
Yukihiro "Matz" Matsumoto 5e79bc9377 Make String#replace to check equality before modifying flags.
ref #3588
2017-04-06 08:25:25 +09:00
Yukihiro "Matz" Matsumoto 77331d127b Unify else clause style 2017-04-03 16:56:27 +09:00
Yukihiro "Matz" Matsumoto d27a3d47cd String#initialize to make a string empty; ref #3574 2017-04-03 10:22:38 +09:00
ksss 76e10351fa String#index shouldn't return nil when "".index "" 2017-03-05 14:15:18 +09:00
Yukihiro "Matz" Matsumoto 7db0786abd Fix integer overflow; fix #3473
The fix is suggested by https://hackerone.com/lucnguyen
2017-02-28 09:54:56 +09:00
Yukihiro "Matz" Matsumoto 405f5a2d2a Add type check by mrb_get_args(); ref #3476 2017-02-28 09:30:06 +09:00
Yukihiro "Matz" Matsumoto 74dbee8e52 Add check before calling str_substr(); ref #3476 2017-02-28 09:21:24 +09:00
Yukihiro "Matz" Matsumoto bdac7dfae8 Check if the value is fixnum before mrb_funcall(); fix #3476
The issue is reported by https://hackerone.com/aerodudrizzt
2017-02-28 09:14:42 +09:00