Commit Graph

606 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 7cdef2b03e string.c: share UTF-8 length table with mruby-string-ext. 2022-05-25 11:25:43 +09:00
Yukihiro "Matz" Matsumoto bb99d7b2ca string.c (mrb_utf8len): reduce UTF-8 table size. 2022-05-25 08:04:19 +09:00
Yukihiro "Matz" Matsumoto d7731a95ab string.c (mrb_str_rindex_m): avoid RSTRING_CHAR_LEN() if possible.
Since it scans the string. Use char_backtrack() instead for negative
offset (counting from the tail).
2022-05-24 08:47:07 +09:00
Yukihiro "Matz" Matsumoto 9475521fa3 string.c (char_adjust): simplify and unroll function. 2022-05-23 23:12:40 +09:00
Yukihiro "Matz" Matsumoto 4769ace7e1 string.c (char_backtrack): simplify the code using utf8_islead(). 2022-05-23 23:12:40 +09:00
Yukihiro "Matz" Matsumoto 916fd642fa string.c (mrb_utf8len): unroll a for loop. 2022-05-21 16:14:16 +09:00
Yukihiro "Matz" Matsumoto 54bbc062fb string.c (index,rindex) use single byte version for ASCII strings. 2022-05-21 08:51:11 +09:00
Yukihiro "Matz" Matsumoto 038aa6beb2 strinc.rb (sub, gsub): use byte index instead of char index. 2022-05-19 10:14:59 +09:00
Yukihiro "Matz" Matsumoto c2648ad95d string.c: add byteindex and byterindex methods. 2022-05-16 16:00:00 +09:00
Yukihiro "Matz" Matsumoto 8c985ff851 string.c (mrb_str_index_m): no need to align the position; ref #4569 2022-05-16 14:17:21 +09:00
Yukihiro "Matz" Matsumoto f225db4ed6 string.c: move compilation condition to remove unreachable code. 2022-04-25 10:04:39 +09:00
Yukihiro "Matz" Matsumoto eba74c038e string.c: avoid a local variable. 2022-04-14 10:55:00 +09:00
Yukihiro "Matz" Matsumoto dcaf4083d5 src/bigint.c: implement multi-precision integer.
To enable multi-precision integer support, you need to link
`mruby-bigint` mrbgem. The gem itself is empty but it turns on
the "bigint" support.
2022-04-09 17:16:10 +09:00
Yukihiro "Matz" Matsumoto b99c389ec3 internal.h: aggregate internal functions.
Internal functions can only be called from within the library.
Functions listed in `mruby/internal.h` can be called from:

* core (src/*.c)
* gems (mrbgems/**/*.c)

But not from the application linked with `libmruby`.
2022-04-02 18:25:13 +09:00
Yukihiro "Matz" Matsumoto 4e1cf3293b string.h: replace obsolete functions with macros.
- mrb_string_value_ptr()
- mrb_string_value_len()
2022-03-15 19:08:25 +09:00
Yukihiro "Matz" Matsumoto 37d6506972 string.c: remove unused API mrb_str_strlen().
Compatibility macro is provided for safety.
2022-03-14 14:11:25 +09:00
Yukihiro "Matz" Matsumoto 19b9184aa3 string.c: remove unnecessary goto. 2022-03-09 15:21:13 +09:00
Yukihiro "Matz" Matsumoto dc98988482 string.c: small refactoring regarding check_null_byte. 2022-03-06 23:49:40 +09:00
Yukihiro "Matz" Matsumoto 7528c25aae string.c: remove unnecessary mrb_assert_int_fit(). 2022-03-05 08:04:33 +09:00
Yukihiro "Matz" Matsumoto 31d4bbcfea string.c: improve size/capacity check before allocations. 2022-03-04 14:17:21 +09:00
Yukihiro "Matz" Matsumoto 876bcba694 string.c: avoid integer type mixture in mrb_str_cat(). 2022-03-03 16:29:54 +09:00
Yukihiro "Matz" Matsumoto c3f0f84da5 string.c: remove code duplication using str_init_modifiable(). 2022-03-03 14:48:29 +09:00
Yukihiro "Matz" Matsumoto 1a9991f165 string.c: remove unnecessary size check before string initialization. 2022-03-03 08:08:02 +09:00
Yukihiro "Matz" Matsumoto a9bde42641 string.c: small refactoring (open else clause after return). 2022-03-03 08:08:02 +09:00
Yukihiro "Matz" Matsumoto a4f740ff9a string.c: use mrb_int instead of size_t. 2022-03-03 08:08:02 +09:00
Yukihiro "Matz" Matsumoto 51a3317c5b string.c: check integer overflow using mrb_int_mul_overflow(). 2022-03-03 08:08:01 +09:00
Yukihiro "Matz" Matsumoto 9fc26eacd1 Merge pull request #5619 from dearblue/properties
Get object properties after `mrb_get_args()`
2021-12-31 15:28:11 +09:00
dearblue a137ef12f9 Get object properties after mrb_get_args()
ref. #5613

I checked with Valgrind, and the methods that can cause use-after-free are `Array#rotate`, `Array#rotate!`, and `String#byteslice`.
Since `String#rindex` uses `RSTRING_LEN()` indirectly inside the function, no reference to the out-of-bounds range is generated.
2021-12-30 22:34:22 +09:00
Yukihiro "Matz" Matsumoto 66a099b1b3 string.c: reorganize str_convert_range using mrb_ensure_int_type 2021-12-29 16:44:35 +09:00
Yukihiro "Matz" Matsumoto b6d31810fe string.c: use mrb_as_int macro. 2021-12-29 16:39:56 +09:00
Yukihiro "Matz" Matsumoto 7850549a5e string.c: use FNV1a algorithm for the string hash function. 2021-10-23 09:31:01 +09:00
Yukihiro "Matz" Matsumoto 09336c5d49 mruby/ops.h: add new instructions OP_GETIDX and OP_SETIDX.
Which represent `obj[int]` and `obj[int]=val` respectively where `obj`
is either `string`, `array` or `hash`, so that index access could be
faster. When `obj` is not assumed type or `R(a+1)` is not integer, the
instructions fallback to method calls.
2021-10-03 17:14:00 +09:00
Yukihiro "Matz" Matsumoto 7e612b1c89 string.c: check integer overflow in str_replace_partial. 2021-09-09 19:12:59 +09:00
Yukihiro "Matz" Matsumoto 8a41d2b876 string.c: check integer overflow in mrb_str_aset(). 2021-09-09 19:12:36 +09:00
Yukihiro "Matz" Matsumoto cbfaa5e20f object.c: rename mrb_to_int to mrb_to_integer.
Consistent naming: `integer` to represent integer packed in `mrb_value`
instead of `int`.
2021-09-07 14:31:56 +09:00
Yukihiro "Matz" Matsumoto 79bc8e2539 string.h: rename mrb_str_to_inum to mrb_str_to_integer.
Consistent naming: `integer` to represent integer packed in `mrb_value`
instead of `inum`.
2021-09-07 14:31:56 +09:00
Yukihiro "Matz" Matsumoto 41d0b343e6 string.c: need to adjust index for UTF-8. 2021-09-01 07:00:56 +09:00
Yukihiro "Matz" Matsumoto 3622f2c4b5 string.c: implement __sub_replace() in C.
To reduce number of string allocation.
2021-09-01 07:00:55 +09:00
Yukihiro "Matz" Matsumoto 2c41739b66 mruby.h: obsolete mrb_to_str().
Replace them by `mrb_ensure_string_type()`.
2021-09-01 07:00:55 +09:00
dearblue 5a57602860 Organize the include of header files
- `#include <math.h>` is done in `mruby.h`.
  Eliminate the need to worry about the `MRB_NO_FLOAT` macro.

- Include mruby header files before standard header files.
  If the standard header file is already placed before `mruby.h`, the standard header file added in the future tends to be placed before `mruby.h`.

This change should some reduce the chances of macros that must be defined becoming undefined in C++ or including problematic header files in a particular mruby build configuration.
2021-08-21 15:42:57 +09:00
Yukihiro "Matz" Matsumoto ef66406c50 string.c: mrb_str_to_cstr() should always return a mutable string. 2021-08-18 21:40:10 +09:00
Yukihiro "Matz" Matsumoto b9d2b47f16 Replace mrb_fixnum_value() with mrb_int_value().
Use `mrb_fixnum_value()` only when you are absolutely sure that the
value is within `Fixnum` range, i.e. 31 bits signed integer at least.
2021-08-03 13:00:11 +09:00
Yukihiro "Matz" Matsumoto 23e7cb41e5 Replace fixnum references with int.
The `Fixnum` class is no longer provided by `mruby`.
2021-08-03 13:00:10 +09:00
Yukihiro "Matz" Matsumoto 5c804cf68f Remove redundant include headers.
- stdlib.h
- stddef.h
- stdint.h
- stdarg.h
- limits.h
- float.h
2021-07-25 13:07:10 +09:00
dearblue cc95e346fd Added MRB_OBJ_ALLOC() macro that does not require a cast
The `MRB_OBJ_ALLOC()` macro function returns a pointer of the type corresponding to the constant literal defined in `enum mrb_vtype`.
2021-06-20 11:08:28 +09:00
Yukihiro "Matz" Matsumoto 3acc09ae61 string.c: make mrb_str_len_{inum,dbl}() static. 2021-06-08 17:19:31 +09:00
Yukihiro "Matz" Matsumoto d8ec544564 string.c: remove two unused functions.
* `mrb_cstr_to_inum()`
* `mrb_cstr_to_dbl()`
2021-06-08 17:00:54 +09:00
Yukihiro "Matz" Matsumoto a5f323835e string.c: add base>36 check to String#to_i. 2021-06-08 16:59:57 +09:00
Yukihiro "Matz" Matsumoto bf523b71d1 strtod.c: new public domain implementation of strtod; ref #5448
Instead of using copyrighted `strtod`, now use the public domain
implementation of `strtod` by Yasuhiro Matsumoto (@mattn). The function
has been renamed to `mrb_float_read()`; ref #5460 as well.
2021-05-24 12:10:14 +09:00
Yukihiro "Matz" Matsumoto 5eebbd7df2 Global renaming regarding integer and float.
Consistent number conversion function names:
* `mrb_value` to immediate (C) value
  * `mrb_int()` -> `mrb_as_int()`
  * `mrb_to_flo()` -> `mrb_as_float()`
* `mrb_value` to `mrb_value` (converted)
  * `mrb_to_int()'
  * `mrb_Integer()` - removed
  * `mrb_Float()` -> `mrb_to_float`

Consistent function name (avoid `_flo` suffix):
* `mrb_div_flo()` -> `mrb_div_float`
2021-05-17 15:07:05 +09:00