Commit Graph

1318 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto b67955b8ca Change the arguments of following implicit conversion functions:
- `mrb_convert_type`
- `mrb_check_convert_type`

Those function no longer take `tname` string representation of desired
type, and take method symbols instead of `const char*` names. This is
incompatible change. I hope no third-party gems use those functions.
2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto 8864c30d16 Provide functions that take symbols instead of const char*.
- mrb_define_class_id
- mrb_define_module_id
- mrb_define_method_id
- mrb_define_singleton_method_id
- mrb_define_module_function_id
- mrb_define_const_id
- mrb_undef_method_id
- mrb_undef_class_method_id
- mrb_class_defined_id
- mrb_class_get_id
- mrb_class_defined_under_id
- mrb_class_get_under_id
- mrb_module_get_id
- mrb_module_get_under_id
- mrb_define_class_under_id
- mrb_define_module_under_id
- mrb_exc_get_id
2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto fa6a9f6f13 Add functions that take symbols as arguments.
- :
2020-10-12 16:20:58 +09:00
Yukihiro "Matz" Matsumoto dcd3e5907c Define a new function mrb_funcall_id().
`mrb_funcall_id()` takes `mrb_sym` instead of `char*` for a method name.
You can use `MRB_SYM()`/`MRB_QSYM()` to specify the method to call.
2020-10-12 16:20:57 +09:00
Yukihiro "Matz" Matsumoto 246c76e261 Rename MRB_OPSYM() to MRB_QSYM().
Where `QSYM` means quoted symbols, which cannot be represented C
symbols, so specify aliases instead.

- operators: name of the operation, e.g. add for `+`
- predicates: add `_p` suffix instead of `?`
- bang methods: add `_b` suffix instead of `!`
- instance variables: add `a_` prefix instead of `@`
- global variables: add `d_` prefix instead of `@`
- class variables: unsupported; don't use them
2020-10-12 16:20:53 +09:00
Yukihiro "Matz" Matsumoto 1bcf6d9f3c Create MRB_OPSYM() macro to refer symbols corresponding operators.
For example, `MRB_OPSYM(add)` refers a symbol for `+`.
2020-10-12 16:20:51 +09:00
Yukihiro "Matz" Matsumoto 97e3c3a5a3 Undefine internal macros in presym.h.
- MRB_PRESYM_CSYM
- MRB_PRESYM_SYM
2020-10-12 16:20:51 +09:00
Yukihiro "Matz" Matsumoto eddd324979 Add MRB_SYM() for inline symbols. 2020-10-12 16:20:41 +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 c27e451931 Merge pull request #4933 from dearblue/variables
Fix take over file scope variables with `mruby` and `mirb` command
2020-09-10 18:12:38 +09:00
dearblue f99c315400 Remove enum call_type
It seems to be unnecessary from mruby-1.0.0 or earlier.
2020-09-03 23:18:16 +09:00
SiZiOUS 510b9e7abc mruby-io: Fixing compilation issue under the legacy MinGW environment
Adding MRB_MINGW32_LEGACY in common.h in order to identify the legacy MinGW environment (i.e. NOT to be confused with MinGW-w64).
For more info about MinGW defined macros, see: https://sourceforge.net/p/predef/wiki/Compilers/
2020-08-29 13:58:00 +02:00
KOBAYASHI Shuji 77c35e7097 Simplify MSVC detection to mrb_static_assert 2020-08-12 20:05:31 +09:00
Yukihiro "Matz" Matsumoto 2aa70e9690 Merge pull request #5062 from shuujii/use-normal-static_assert-in-mrb_static_assert-as-much-as-possible
Use normal `static_assert` in `mrb_static_assert` as much as possible
2020-08-11 22:33:44 +09:00
KOBAYASHI Shuji bab7e9f032 Use normal static_assert in mrb_static_assert as much as possible
* `_Static_assert` can also be used with `-std=gnu99` on GCC >= 4.6.
* `static_assert` can be used on MSVC.
* `static_assert` can be used even on old G++/Clang++ if
  `__GXX_EXPERIMENTAL_CXX0X__` is defined.
2020-08-11 20:47:20 +09:00
Yukihiro "Matz" Matsumoto 5e55b61c44 Fix mrb_int and size_t combination warnings. 2020-08-11 15:06:51 +09:00
KOBAYASHI Shuji 0d54568b4d Allow mrb_static_assert() to be used outside of functions
The use of `struct` is an idea by @dearblue.
2020-08-09 20:39:36 +09:00
Yukihiro "Matz" Matsumoto c849b894ed Reintroduce mrb_static_assert; #5051
Note that the home brew version of `mrb_static_assert` only works within
the function body.  This reverts commit 8f99689.
2020-08-08 10:39:26 +09:00
Yukihiro "Matz" Matsumoto 9742bce198 Merge pull request #5059 from mruby/stable
Merge mruby 2.1.2
2020-08-06 17:47:36 +09:00
Hiroshi Mimaki 7f8d38bbbe Merge master. 2020-08-06 17:38:20 +09:00
Yukihiro "Matz" Matsumoto 8f99689ba3 Remove mrb_static_assert from the core; #5051 2020-08-06 16:01:45 +09:00
Hiroshi Mimaki 1a9bdfcde5 Update release date. 2020-08-06 12:45:59 +09:00
Yukihiro "Matz" Matsumoto 0a505dcfd6 Simplify khash.h.
- Remove ` kh_put_prepare` function used only internally
- Remove `n_occupied` member from `kh_` struct
2020-07-31 18:14:02 +09:00
dearblue cdf45438f0 Fixed shift width for MRB_ENV_SET_BIDX()
ref c07f24cd1 and close #5035
2020-07-29 09:05:29 +09:00
dearblue ccd5f203bf Improve prototype for mrb_objspace_page_slot_size(); ref #5032
If it qualify a return type that is not a pointer with `const`, the
compiler ignores it.
2020-07-24 11:48:09 +09:00
Yukihiro "Matz" Matsumoto 9840d6a2e7 Merge pull request #5038 from dearblue/bidx
Fixed shift width for `MRB_ENV_SET_BIDX()`
2020-07-17 07:12:31 +09:00
dearblue 5dc87f77d4 Fixed shift width for MRB_ENV_SET_BIDX()
ref c07f24cd1 and close #5035
2020-07-16 23:11:30 +09:00
Rory O'Connell f74d370c15 mrb_ prefix convention 2020-07-15 19:57:22 -07:00
Rory OConnell 6f945a09b4 Use object iv table size in calculation 2020-07-13 15:59:24 -07:00
Rory OConnell e7bd7d0eaf Use size of hash's table in calculation 2020-07-13 15:58:50 -07:00
Rory OConnell 41e3220539 All values use page slot size in calculation 2020-07-13 15:56:27 -07:00
Hiroshi Mimaki b6b9c57f24 Update version to 2.1.2. (mruby 2.1.2 RC) 2020-07-01 16:49:21 +09:00
Yukihiro "Matz" Matsumoto c07f24cd18 Change flag names in preparation of REnv refactoring. 2020-06-25 06:57:41 +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 dad99afae8 Remove unnecessary comments from MRB_TT_* definitions. 2020-06-15 09:54:55 +09:00
Yukihiro "Matz" Matsumoto f93dffb5ee Remove unused MRB_TT_FILE. 2020-06-15 07:47:22 +09:00
Yukihiro "Matz" Matsumoto 7f593893e8 Update OP_HASH generation to support big hash creation. 2020-06-09 22:42:38 +09:00
Yukihiro "Matz" Matsumoto f1523d2404 Squashed commit of the following:
commit 2d7d545c4c4bfce7fdcbcbe9baaeb437915742f0
Merge: 625a1249 b178914b
Author: Yukihiro "Matz" Matsumoto <matz@ruby.or.jp>
Date:   Fri Jun 5 14:35:13 2020 +0900

    Merge branch 'fix-mrb_open-with-nomem' of https://github.com/dearblue/mruby into dearblue-fix-mrb_open-with-nomem

commit b178914b11
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 22:22:44 2019 +0900

    Fix invalid pointer free inside other heap's block

     1. `e = mrb_obj_alloc(...)`
     2. `e->stack = mrb->c->stack` (`mrb->c->stack` is anywhere in the range `stbase...stend`)
     3. And raised exception by `mrb_malloc()`!
     4. `mrb_free(e->stack)` by GC part (wrong free)

commit 52e3d5d858
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 21:55:36 2019 +0900

    Fix memory leak for temporary symbols when out of memory

commit 4c5499b88e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 11:42:07 2019 +0900

    Fix uninitialized pointer dereference for debug section

commit 8e993167de
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 11:41:09 2019 +0900

    Fix memory leak for temporary filenames when out of memory

commit 8b422577e6
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 10:57:51 2019 +0900

    Fix memory leak for irep when out of memory

commit 6b35ebf49a
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 10:55:50 2019 +0900

    Fix uninitialized pointer dereference when do not finished initializing irep

commit 2531f2631e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 10:48:15 2019 +0900

    Fix NULL pointer dereference when do not finished initializing irep

commit e2d6896eba
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 12:54:19 2019 +0900

    Fix memory leak for irep when out of memory by `mrb_proc_new()`

commit b6214ff8a0
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 12:53:07 2019 +0900

    Fix memory leak for `khash_t` in `kh_init_size()` when out of memory by `kh_alloc()`

commit 19162dd6c1
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 02:15:07 2019 +0900

    Fix memory leak for symbol string when out of memory in `kh_put()`

commit 15e67297ff
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 02:12:24 2019 +0900

    Fix keep wrong symbol index when out of memory

commit 3f8e2b3752
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 02:08:13 2019 +0900

    Fix keep wrong symbol capacity when out of memory

commit a3cfe755ab
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 10:11:37 2019 +0900

    Fix NULL pointer dereference `mrb->c` by `mark_context()`

commit d9c7b6be6e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 15:25:09 2019 +0900

    Fix protect exception for print error message

commit 100642750e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 11:59:02 2019 +0900

    Protect exception for mruby core initialization

commit 7a0418304e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Fri Jan 18 20:38:27 2019 +0900

    Fix memory leak for string object when out of memory

    The `mrb_str_pool()` function has a path to call `malloc()` twice.

    If occurs `NoMemoryError` exception in second `malloc()`,
    first `malloc()` pointer is not freed.

commit fef1c152ce
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 13:05:09 2019 +0900

    Fix stack overflow when out of memory

    As a result of this change, no backtrace information is set
    for NoMemoryError (`mrb->nomem_err`).

    Detailes:

    When generating a backtrace, called `mrb_intern_lit()`,
    `mrb_str_new_cstr()` and `mrb_obj_iv_set()` function with
    `exc_debug_info()` function in `src/error.c`.

    If a `NoMemoryError` exception occurs at this time,
    the `exc_debug_info()` function will be called again,
    and in the same way `NoMemoryError` exception raised will result
    in an infinite loop to occurs stack overflow (and SIGSEGV).

commit da7d7f881b
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 12:00:38 2019 +0900

    Fix NULL pointer dereference `mrb->nomem_err` when not initialized

    Add internal functions (not `static`):

      * `mrb_raise_nomemory()`
      * `mrb_core_init_abort()`
2020-06-05 14:40:07 +09:00
Hiroshi Mimaki 81d340e042 Merge master. 2020-06-05 12:42:56 +09:00
Hiroshi Mimaki f9d113f764 Update release date. 2020-06-04 17:20:46 +09:00
Yukihiro "Matz" Matsumoto 41f3456a28 Merge pull request #4865 from take-cheeze/istruct_align
Align RIStruct data for rational/complex
2020-06-04 11:01:04 +09:00
dearblue f85906b679 Remove patch_irep() in mruby-eval
- It can now deal with operands in the range of `OP_EXT*`.
- It can now call the same method as the variable name without arguments.

  ```ruby
  def a
    "Safe!"
  end

  a = "Auto!"

  eval "a()" # call method `a`
  ```
2020-06-02 14:49:27 +09:00
Rory OConnell 89ceb3e7ba Fix float constant redefinition warnings 2020-05-31 20:11:38 -07:00
Yusuke Endoh 6f4c585bd7 Do not destruct rest arguments for __send__
Formerly, `__send__(*args)` modified `args` with `Array#shift`.
This bug affects optcarrot.

This changeset avoids the array destruction by using
`args = args[1, len-1]`.
2020-05-24 01:25:03 +09:00
Rory OConnell 69bc477b43 Adding warnings for mrb_load functions leaking RProc objects 2020-05-19 01:07:49 -07:00
Yukihiro "Matz" Matsumoto f5ee7df7f3 Rename (and expose) UTF-8 related functions; ref #4712
- mrb_utf8len() - returns the size of a UTF-8 char (in bytes)
- mrb_utf8_strlen() - returns the length of a UTF-8 string (in char)
2020-05-07 09:31:07 +09:00
Yukihiro "Matz" Matsumoto 87576b819e Remove endian information/flags from compiled binary format.
Since `mruby 2.0`, compiled bytecode no longer depends on the
endian of the machine.
2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 87d77c13f5 Update compiled binary format version for OP_LOADI16. 2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto fa8668c77d Add a new instruction OP_LOADI16.
Which loads 16bit integer to the register. The instruction number should
be reorder on massive instruction refactoring. The instruction is added
for `mruby/c` which had performance issue with `OP_EXT`. With this
instruction, `mruby/c` VM can just raise errors on `OP_EXT` extension
instructions.
2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto c143d87e7c Remove mrb_run from MRB_API; #4488
`mrb_run` requires to push callinfo stack before calling, which is very
hard from outside of `vm.c`. So there should be virtually no correct
usage of the function, hence the cause of #4488. We removed it.

You can use `mrb_top_run(mrb, proc, self, 0)` instead of
`mrb_run(mrb, proc self)`.
2020-05-07 08:38:46 +09:00