Commit Graph

4264 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto b98bf36a15 Use mrb_str_inspect instead of mrb_str_dup; fix #4678 2019-09-12 17:15:55 +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
Yukihiro "Matz" Matsumoto 9d9cb0ab6a Fix mod.constants not to have duplicate constant names; #4698
The fix was based on PR from @dearblue
2019-09-09 23:14:07 +09:00
Yukihiro "Matz" Matsumoto a1a838d966 Remove duplication of BasicObject constant; fix #4698 2019-09-09 23:14:07 +09:00
KOBAYASHI Shuji b156aa2cf6 Fix Class.new argument specs 2019-09-09 21:37:35 +09:00
Yukihiro "Matz" Matsumoto 715afd6fdb Merge pull request #4695 from dearblue/promote-to-int
Fix `mrb_vformat()` crashes with `MRB_INT16`
2019-09-08 22:46:25 +09:00
dearblue 311d867deb Fix mrb_vformat() crashes with MRB_INT16
If `MRB_INT16` is specified, the variable length argument `mrb_int` is
converted to `int`.
2019-09-08 20:31:35 +09:00
Yukihiro "Matz" Matsumoto 9d08025b8b Revert part of #4225
Since in mruby, Integer and Float interchange frequently (mostly on
overflow), so adding explicit `.0` can cause problems sometimes.

For example:
https://github.com/mattn/mruby-json/pull/40
https://github.com/pepabo/mruby-msd/pull/13
https://github.com/mattn/mruby-json/pull/42
2019-09-07 22:27:30 +09:00
KOBAYASHI Shuji 489f655d18 Fix argument specs to BasicObject 2019-09-04 22:49:57 +09:00
David Siaw 6375639917 fix lots of warnings and make logo not so big 2019-08-26 02:08:33 +09:00
dearblue c9c27e9d69 Suppress warning by gcc with -Wmaybe-uninitialized 2019-08-24 11:44:51 +09:00
KOBAYASHI Shuji be78b5d8f7 Fix RBreak exceeding 6 words on 32-bit mode w/o boxing and MRB_USE_FLOAT
ref: https://github.com/mruby/mruby/pull/4483#issuecomment-498001736

In this configuration, `tt` of `RBreak::val` is set into `RBreak::flags`.
2019-08-23 22:15:42 +09:00
KOBAYASHI Shuji a84ab12735 Prioritize embedded string over nofree (or normal) string
Prioritize embedded string in the following functions:

- `str_new_static`
- `str_new`
- `mrb_str_new_capa`
- `mrb_str_pool`

The reasons are as follows:

- Consistency with `mrb_str_byte_subseq` and `str_replace`.
- Memory locality increases and may be slightly faster.
- No conversion cost to embedded string when modifying the string.
2019-08-21 12:06:03 +09:00
KOBAYASHI Shuji 8157672a29 Use RBasic padding for embedded string on 64-bit CPU
On 64-bit CPU, there is padding in `RBasic`, so reorder the fields and use
it as buffer of embedded string. This change allows 4 more bytes to be
embedded on 64-bit CPU.

However, an incompatibility will occur if `RString::as::ary` is accessed
directly because `RString` structure has changed.
2019-08-20 18:49:55 +09:00
KOBAYASHI Shuji 507dbf984e Move mrb_str_pool to src/string.c to use str_init family 2019-08-19 19:18:52 +09:00
Yukihiro "Matz" Matsumoto f263088b0d Merge pull request #4638 from dearblue/simplify-get-args
Simplify get arguments
2019-08-19 07:30:48 +09:00
Yukihiro "Matz" Matsumoto 1b9801a04b Merge pull request #4641 from shuujii/rename-mrb_shared_string-len-to-mrb_shared_string-capa
Rename `mrb_shared_string::len` to `mrb_shared_string::capa`
2019-08-19 07:24:06 +09:00
Yukihiro "Matz" Matsumoto feecb3321a Merge pull request #4640 from shuujii/also-use-str_init_shared-for-orig-in-str_make_shared
Also use `str_init_shared` for `orig` in `str_make_shared()`
2019-08-19 07:23:23 +09:00
KOBAYASHI Shuji d2d201cc82 Rename mrb_shared_string::len to mrb_shared_string::capa
Because this field is used as capacity of string buffer.
2019-08-18 20:08:04 +09:00
KOBAYASHI Shuji aaa509dd07 Also use str_init_shared for orig in str_make_shared() 2019-08-18 19:44:00 +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
dearblue 279c21b816 Prohibit changes to iseq in principle 2019-08-18 15:00:32 +09:00
Yukihiro "Matz" Matsumoto 83dab1ee0d Merge pull request #4634 from shuujii/refactor-set-unset-string-type-flags
Refactor set/unset string type flags
2019-08-17 23:41:52 +09:00
KOBAYASHI Shuji caba5fef27 Refactor set/unset string type flags
Introduce `RSTR_SET_TYPE_FLAG` macro to set the specified string type flag and
clear the others.
2019-08-17 21:24:08 +09:00
Yukihiro "Matz" Matsumoto 277c91e94c Merge pull request #4625 from dearblue/rindex-broken-utf8
Fix `String#rindex` with invalid UTF-8 string
2019-08-17 15:52:34 +09:00
Yukihiro "Matz" Matsumoto 5b1f25a4e0 Implement Array#each using inline mruby bytecode. 2019-08-17 14:46:32 +09:00
dearblue bc27273087 Fix String#rindex with invalid UTF-8 string
Previously `String#rindex` returned the wrong index when given an
invalid UTF-8 string.

```terminal
% ruby26 -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")'
11
% ./mruby-head -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")'
nil
% ./mruby-patched -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")'
11
```
2019-08-17 12:05:03 +09:00
Yukihiro "Matz" Matsumoto e76c5aad36 Stop using mrb_to_str as a converter (it is not). 2019-08-17 11:49:00 +09:00
Yukihiro "Matz" Matsumoto 0286a7f709 Avoid mrb_funcall from Class#new when no overloading. 2019-08-17 09:02:47 +09:00
Yukihiro "Matz" Matsumoto 99715a2e62 Merge pull request #4633 from shuujii/shared-fshared-string-is-not-required-when-sharing-nofree-string
SHARED/FSHARED string is not required when sharing NOFREE string
2019-08-16 23:20:44 +09:00
Yukihiro "Matz" Matsumoto 0923ff6313 Optimize bytecode for Class#new. 2019-08-16 22:37:30 +09:00
Yukihiro "Matz" Matsumoto 61763129db Implement Class#new using inline mruby bytecode. 2019-08-16 22:30:03 +09:00
KOBAYASHI Shuji 9832e91304 SHARED/FSHARED string is not required when sharing NOFREE string
I think the string buffer of NOFREE string always exists and does not need
to be released, so it can be shared as another NOFREE string.

Also changed the `mrb_shared_string` field order so that eliminate padding if
`int` and `mrb_int` sizes are less than pointer size.
2019-08-16 22:05:58 +09:00
Yukihiro "Matz" Matsumoto 06c7ff0666 Avoid creating unnecessary empty arrays on splat.
But this changes requires `OP_ARYCAT` and `OP_ARYPUSH` to accept `nil`
as their first operand. Alternative VMs (e.g. `mruby/c`) that understand
mruby bytecode need to be updated.
2019-08-16 16:42:40 +09:00
Yukihiro "Matz" Matsumoto fa8515bc2c Stop raising exceptions from undef C API.
Some `undef' functions may be called before initialization, thus causes
infinite error recursion.
2019-08-16 16:42:40 +09:00
KOBAYASHI Shuji 59844ddde0 Remove unneeded #include in src/string.c 2019-08-15 12:18:33 +09:00
KOBAYASHI Shuji af6724c2f6 Extract initialization code of shared and fshared string to function 2019-08-14 22:20:34 +09:00
Yukihiro "Matz" Matsumoto d986b9ff7b Avoid array copying in mrb_instance_new. 2019-08-14 15:08:48 +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
Yukihiro "Matz" Matsumoto 8ed15fd92e Small refactoring on #4630 2019-08-14 12:20:40 +09:00
Yukihiro "Matz" Matsumoto 9f6328d499 Remove MRB_API from functions only called from vm.c.
* `mrb_vm_define_class`
* `mrb_vm_define_module`

Only functions called from user code requires `MRB_API`.
2019-08-14 09:33:23 +09:00
KOBAYASHI Shuji 7af0ee099d Extract struct RString initialization code to function 2019-08-13 22:40:30 +09:00
KOBAYASHI Shuji dfb297e3c4 mrb_str_pool can embed one more byte; ref #4626 2019-08-12 21:42:31 +09:00
Yukihiro "Matz" Matsumoto ad0b546088 Merge pull request #4626 from shuujii/mrb_str_modify_keep_ascii-can-embed-one-more-byte
`mrb_str_modify_keep_ascii` can embed one more byte
2019-08-12 17:09:21 +09:00
Yukihiro "Matz" Matsumoto 285ce9d8aa Replacing region may overwrap with the target region; fix #4627 2019-08-12 16:51:01 +09:00
Yukihiro "Matz" Matsumoto 472dba19ea Revert "Should have cleared mrb->globals in mrb_gc_free_gv; fix #4618"
This reverts commit 3dc8d9d7b3.
2019-08-11 22:14:56 +09:00
Yukihiro "Matz" Matsumoto 0376383354 Reorder finalization to avoid potential crash; ref #4618
`mrb_gc_destroy` may call other mruby API functions from the finalizers.
So call that function first.
2019-08-11 22:14:56 +09:00
Yukihiro "Matz" Matsumoto 70b53f91c2 Add NUL always to short strings; ref 98fc887 2019-08-11 22:14:56 +09:00
KOBAYASHI Shuji 450684ab33 mrb_str_modify_keep_ascii can embed one more byte
The condition to make an embedded string was incorrect. Because there were
several similar codes, extracted into `RSTR_EMBEDDABLE_P` macro.
2019-08-11 20:48:37 +09:00
Yukihiro "Matz" Matsumoto b377b7d580 Update mrb_to_str and related functions.
Contrary to the name, `mrb_to_str` just checks type, no conversion.
2019-08-07 16:20:40 +09:00