Compare commits

...

2161 Commits

Author SHA1 Message Date
Hiroshi Mimaki 58fb6f421a Set the mruby-1.4.0 release date to 2018-1-16. 2018-01-16 10:15:19 +09:00
Yukihiro "Matz" Matsumoto 623436276e Merge pull request #3916 from mimaki/mruby-socket-cygwin-test
Passed mruby-test on Cygwin.
2017-12-26 15:51:18 +09:00
Hiroshi Mimaki f55df0da7b addrinfo.ai_protocol was not set on Cygwin. 2017-12-26 11:12:49 +09:00
Hiroshi Mimaki bce811a53a Disabled UNIXSocket test on Cygwin 2017-12-26 11:05:28 +09:00
Yukihiro "Matz" Matsumoto 6b09692684 Add `Integer#{allbits?,anybits?,nobits?}. [Ruby2.5]
In mruby, those methods are defined in `Integral` module.
2017-12-26 09:44:39 +09:00
Yukihiro "Matz" Matsumoto 3d7141b7fe Move Intefer#chr to Integral#chr.
Since mruby mixes `Integer` and `Float`, integer operations have
been moved to `Integral` module.
2017-12-26 09:42:34 +09:00
Yukihiro "Matz" Matsumoto ad17ba0e11 KeyError from Hash#fetch should inspect key.
To distinguish string keys and symbol keys.
2017-12-25 23:52:40 +09:00
Yukihiro "Matz" Matsumoto e4a9b4a3ad `Enumerable#{one?,none?,all?,any?} to take pattern argument [Ruby2.5] 2017-12-25 23:43:43 +09:00
Yukihiro "Matz" Matsumoto 421819dc2c Add Hash#slice [Ruby 2.5] 2017-12-25 23:43:37 +09:00
Yukihiro "Matz" Matsumoto df68a3345d assert_equal() takes result as the first argument 2017-12-25 15:39:45 +09:00
Yukihiro "Matz" Matsumoto 2a5545cc25 Update Kernel#method_missing tests for new NoMethodError message.
Also removed tests that depends on implementation details of the default
`method_missing` behavior.
2017-12-23 15:18:13 +09:00
Yukihiro "Matz" Matsumoto 6999e45742 Do not include object string representation in NoMethodError message.
This information is not mandatory but causes a lot of problems in the
past due to infinite recursion by redefining `to_str`, `inspect` etc.
2017-12-23 15:15:03 +09:00
Yukihiro "Matz" Matsumoto ca0f32a208 super should raise TypeError when the receiver is switched; fix #3911
The receiver can be switched using `#instance_eval` etc.
2017-12-23 11:14:12 +09:00
Yukihiro "Matz" Matsumoto aa8786f79c Do not initialize a local variable soon to be assigned. 2017-12-23 11:14:12 +09:00
Yukihiro "Matz" Matsumoto 7e520838b3 Avoid infinite recursion in method_missing; ref #3908 2017-12-23 11:13:27 +09:00
Yukihiro "Matz" Matsumoto 44b4f69fce May need more stack space in mrb_funcall_with_block; fix #3908 2017-12-23 10:01:30 +09:00
Yukihiro "Matz" Matsumoto 8d7e95282c Add #module_exec and #class_exec in mruby-class-ext gem. 2017-12-23 10:01:30 +09:00
Yukihiro "Matz" Matsumoto 7fbbd7ab9f Should not overwrite ci->target_class in mrb_exec_irep().
For example, the following code behaved wrong:

```ruby
Object.instance_exec(1,2,3){|*a|
  def foo
    42
  end
}
p foo()
```
2017-12-23 10:01:30 +09:00
Yukihiro "Matz" Matsumoto 7990bb7fa7 Merge pull request #3913 from llothar/master
Make source compilable with C++17
2017-12-23 09:44:00 +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 100f0e6759 Do not need to take target_class from the upper proc.
Since it is already set in `mrb_proc_new()`.
2017-12-20 19:37:26 +09:00
Yukihiro "Matz" Matsumoto 73b05f0130 Should not overwrite MRB_PROC_TARGET_CLASS(p) if p has env; fix #3905 2017-12-20 19:37:26 +09:00
Yukihiro "Matz" Matsumoto 165e7b181b Fixed method look-up for method_missing in OP_SUPER; ref #3905
Method look-up for `OP_SUPER` should start from the superclass of
the `target_class` but if it fails, the look-up for `method_missing`
should start from the class of the receiver.

The following code explains the case:
```ruby
class Bar
  def foo
    super
  end
end

class Foo<Bar
  def method_missing(mid, *)
    p mid
  end
end
```
Foo.new.foo
2017-12-20 19:37:26 +09:00
Yukihiro "Matz" Matsumoto d0f60182af The superclass info should be taken from `TARGET_CLASS(ci->proc).
Not from `ci->target_class` that may be switched using `class_eval` etc.
fix #3899, fix #3906

We found out there is a mruby specific limitation that `super` may be
screwed up when a method is defined in a module and `super` is called
in the block with the target class switched (for example, `super` in
`class_eval` block).  Now we raise `RuntimeError` for such cases.

The following code works in CRuby but not in mruby.
```
module M
  def foo
    "aaa".singleton_class.class_eval{super 2}
  end
end
class Foo
  def foo(*); end
end
class Bar<Foo
  include M
end
Bar.new.foo
```
2017-12-20 10:34:54 +09:00
Yukihiro "Matz" Matsumoto d9049c10fa Merge pull request #3904 from ksss/mruby-method
Add mruby-method
2017-12-18 11:59:36 +09:00
Yukihiro "Matz" Matsumoto bba6c9a1ce Fix descriptor leakage; ref #3903 2017-12-18 11:55:12 +09:00
Yukihiro "Matz" Matsumoto e5056d058a Fix fptr leakage; ref #3903 2017-12-18 11:55:12 +09:00
Yukihiro "Matz" Matsumoto 83d02bcd5a Use _dup2 instead of dup2 on Windows; ref #3903 2017-12-18 11:55:12 +09:00
Yukihiro "Matz" Matsumoto 5e22e8e350 open on Windows takes int 3rd argument instead of mode_t. 2017-12-18 11:15:27 +09:00
ksss c0914dbb65 mruby/data.h doesn't need 2017-12-18 11:11:44 +09:00
Yukihiro "Matz" Matsumoto b4dcb8f286 Use _dup instead of dup on Windows; ref #3903 2017-12-18 11:10:49 +09:00
ksss 615f296fcf Clean up some files and docs 2017-12-18 11:10:10 +09:00
ksss ae786b18d5 Shouldn't use alloca 2017-12-18 11:05:55 +09:00
Yukihiro "Matz" Matsumoto a510564d6d Merge pull request #3903 from ksss/io-dup
Implement IO#initialize_copy
2017-12-18 10:58:12 +09:00
ksss b83ff8ccd8 Add mrbgems/mruby-method
from https://github.com/ksss/mruby-method/commit/0837a0b507a5b4cdf8a1f1039ee371cee4e3b7fb
2017-12-18 10:54:37 +09:00
ksss 35185e69bf Implement IO#initialize_copy 2017-12-17 18:02:37 +09:00
Yukihiro "Matz" Matsumoto ddb1aae41d Need to set ci->proc before calling methods; fix #3902 2017-12-16 09:33:37 +09:00
Yukihiro "Matz" Matsumoto 03614ed918 Need to clear exception handler on return; fix #3898 2017-12-16 09:17:07 +09:00
Yukihiro "Matz" Matsumoto 05129ab9b3 Check if destinations are too distant; fix #3900 fix #3901 2017-12-15 17:57:45 +09:00
Yukihiro "Matz" Matsumoto 7ecb96a00a Merge pull request #3897 from mimaki/initialize-is_socket
Initialized mrb_io.is_socket
2017-12-14 13:58:27 +09:00
Hiroshi Mimaki 41039524a9 Initialized mrb_io.is_socket 2017-12-14 12:36:25 +09:00
Yukihiro "Matz" Matsumoto 5b304c156c On Windows, _S_IREAD and _S_IWRITE is defined in sys/stat.h. 2017-12-14 01:19:44 +09:00
Yukihiro "Matz" Matsumoto 7ac39333b5 Use _open and _close on Windows. 2017-12-14 01:19:21 +09:00
Yukihiro "Matz" Matsumoto ebf49932c7 Merge pull request #3895 from mattn/fix-mkstemp
fix mkstemp implementation for MSVC
2017-12-14 00:46:19 +09:00
Yasuhiro Matsumoto e7e5db51de fix mkstemp implementation for MSVC 2017-12-14 00:43:38 +09:00
Yukihiro "Matz" Matsumoto f0379c8c45 Merge pull request #3892 from mimaki/ipproto-winsock
Use IPPROTO enum values on WinSock.
2017-12-14 00:09:45 +09:00
Yukihiro "Matz" Matsumoto 16e473caad Rename BasicSocket#is_socket= to #_is_socket; ref #3878 2017-12-14 00:07:42 +09:00
Yukihiro "Matz" Matsumoto 69ad12de06 Exclude UNIXSocket tests again; ref #3878 2017-12-14 00:05:23 +09:00
Takeshi Watanabe d2163d13a8 Declare super class in socket.rb. 2017-12-14 00:05:23 +09:00
Takeshi Watanabe 949bf6ca43 Fix socket closing by using closesocket API in windows instead. 2017-12-14 00:05:23 +09:00
Yukihiro "Matz" Matsumoto 2300c9f737 Merge pull request #3893 from mimaki/add-mrbgem-summary
Added mrbgem's summary.
2017-12-14 00:00:10 +09:00
Yukihiro "Matz" Matsumoto dc5de38414 Merge pull request #3894 from mattn/mirb-locale
fix locale message in mirb
2017-12-13 23:11:49 +09:00
Yukihiro "Matz" Matsumoto 1a150a6e48 Merge pull request #3891 from mimaki/set-addrinfo-protocol
Set protocol of AddrInfo
2017-12-13 23:00:25 +09:00
Yasuhiro Matsumoto 0ab9ac6b22 fix locale in mirb 2017-12-13 22:28:18 +09:00
Hiroshi Mimaki 584e4e413a Added mrbgem's summary. 2017-12-13 16:05:06 +09:00
Hiroshi Mimaki 9fac1a3f8b Use IPPROTO enum values on WinSock. 2017-12-13 15:58:23 +09:00
Hiroshi Mimaki 398da99d05 Set protocol of AddrInfo 2017-12-13 14:44:13 +09:00
Yukihiro "Matz" Matsumoto 55fced30cd Use _tempnam instead of tempnam on Windows. 2017-12-13 14:17:49 +09:00
Yukihiro "Matz" Matsumoto a3925f3dec Merge pull request #3889 from mattn/fix-crash
fix crash bug on Windows
2017-12-13 14:10:44 +09:00
Yukihiro "Matz" Matsumoto aec65f2605 Merge pull request #3890 from mimaki/mruby-socket-windows-test
Skip tests on Windows platform
2017-12-13 13:59:28 +09:00
Hiroshi Mimaki 4353623b72 Skip tests on Windows platform 2017-12-13 13:02:59 +09:00
Yasuhiro Matsumoto 6123d653b7 fix crash bug on Windows 2017-12-13 12:48:26 +09:00
Yukihiro "Matz" Matsumoto fa33bd86a8 Remove VC++ compiler warnings. 2017-12-13 11:39:32 +09:00
Yukihiro "Matz" Matsumoto 7d940e3682 Merge pull request #3888 from mattn/fix-locale
fix path locales
2017-12-13 10:24:52 +09:00
Yasuhiro Matsumoto 16c2ac2588 fix path locales 2017-12-13 10:12:59 +09:00
Yukihiro "Matz" Matsumoto e14387440e Skip test/t/float.rb tests; ref #3827 2017-12-13 08:45:46 +09:00
Yukihiro "Matz" Matsumoto 11b6696ce2 Retrieve operands at the beginning of OP_SCLASS. 2017-12-13 08:43:15 +09:00
Yukihiro "Matz" Matsumoto e647b16d1d Should not define Float class in mrblib/00class.rb; ref #3828
Unless it is defined in `numeric.c`.
2017-12-13 08:42:07 +09:00
Yukihiro "Matz" Matsumoto ad06781107 Fixed wrong MRB_WITHOUT_FLOAT condition; ref #3827 2017-12-13 08:38:34 +09:00
Yukihiro "Matz" Matsumoto c66978521d Reduce VC++ type mismatch warnings. 2017-12-13 08:10:35 +09:00
Yukihiro "Matz" Matsumoto 5a5adafabf Merge pull request #3886 from mattn/io-windows
implement popen/flock on Windows
2017-12-13 07:56:24 +09:00
Yasuhiro Matsumoto b07269584c fix build for MSVC 2017-12-13 00:21:30 +09:00
Yasuhiro Matsumoto e0e23b1765 close file descriptors 2017-12-13 00:18:02 +09:00
Yasuhiro Matsumoto 7c8c9f9532 mingw have mkstemp 2017-12-13 00:08:10 +09:00
Yasuhiro Matsumoto 7ff907f680 fix test 2017-12-13 00:07:51 +09:00
Yasuhiro Matsumoto f1ea7a31c0 implement flock on Windows 2017-12-12 23:21:41 +09:00
Yasuhiro Matsumoto df2c3771f8 fix compilation error 2017-12-12 22:39:21 +09:00
Yasuhiro Matsumoto f6f8bb2416 fix compilation error 2017-12-12 22:39:20 +09:00
Yasuhiro Matsumoto 06ec17de60 add definition for pid_t on MSVC 2017-12-12 22:39:19 +09:00
Yasuhiro Matsumoto d549603a8a close handle 2017-12-12 22:39:18 +09:00
Yasuhiro Matsumoto b8ca0b7cd8 implement popen on Windows 2017-12-12 22:39:17 +09:00
Yukihiro "Matz" Matsumoto c863e0dac8 Merge pull request #3885 from Shokuji/cygwin_mruby_io_test
fixed mruby-io so that the test passes on cygwin
2017-12-12 22:34:10 +09:00
Yukihiro "Matz" Matsumoto c6ea948030 Revert "Update .travis.yml to use gcc-6"
This change caused Travis CI errors on OSX.  This reverts
commit c76631d445.
2017-12-12 22:31:14 +09:00
Yukihiro "Matz" Matsumoto 346ebfb0ea Merge pull request #3882 from mattn/fix-filename
use filename in locale
2017-12-12 22:27:25 +09:00
Yukihiro "Matz" Matsumoto 25bee356b1 Merge pull request #3884 from mimaki/mruby-io-test-on-windows
Fixed mruby-io test failure on Windows platform.
2017-12-12 22:21:08 +09:00
Yasuhiro Matsumoto 17cd7a65e7 fix wrong variable name 2017-12-12 18:52:41 +09:00
Yasuhiro Matsumoto bceb6640fa fix compilation error 2017-12-12 18:52:41 +09:00
Yasuhiro Matsumoto 977f79478f use filename in locale 2017-12-12 18:52:40 +09: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 d4ff92bcf6 Do not use FIXABLE when mrb_int is big enough. 2017-12-12 17:45:15 +09:00
Yukihiro "Matz" Matsumoto 3d98fa2e46 Reduce type mismatch warnings in pack.c. 2017-12-12 17:45:15 +09:00
Yukihiro "Matz" Matsumoto a5b8603aa2 Winsock uses int where UNIX uses size_t. 2017-12-12 17:45:15 +09:00
Yukihiro "Matz" Matsumoto a9e434e69a Merge pull request #3883 from mattn/fix-ssize_t
fix build on mingw
2017-12-12 17:31:26 +09:00
窪山 翔士 e71a6a7b2c fixed mruby-io so that the test passes on cygwin 2017-12-12 17:29:05 +09:00
Hiroshi Mimaki 5ef8f18e9b Fixed mruby-io test failure on Windows platform. 2017-12-12 16:57:13 +09:00
Yasuhiro Matsumoto 99328695e3 fix build on mingw 2017-12-12 16:47:34 +09:00
Yukihiro "Matz" Matsumoto 9c0426c990 Winsock does not provide ssize_t; Use int instead. 2017-12-12 09:52:39 +09:00
Yukihiro "Matz" Matsumoto 2db06c471e Revert "Update .travis.yml"
This reverts commit f73ac4112f.
This change caused Travis errors.
2017-12-12 09:49:26 +09:00
Yukihiro "Matz" Matsumoto 08a508cbee Fixed the mixture of int and long in mruby-pack. 2017-12-12 09:48:53 +09:00
Yukihiro "Matz" Matsumoto 5bf60b4837 Merge pull request #3881 from mame/mrb_without_float-for-mruby-io-and-mruby-pack
Support MRB_WITHOUT_FLOAT to mruby-io and mruby-pack
2017-12-12 07:49:30 +09:00
Yusuke Endoh d96b2c9a76 Support MRB_WITHOUT_FLOAT to mruby-io and mruby-pack 2017-12-12 00:47:56 +09:00
Yukihiro "Matz" Matsumoto 85fc9b88d0 Merge pull request #3880 from mruby/matz-patch-1
Update .travis.yml
2017-12-11 23:23:10 +09:00
Yukihiro "Matz" Matsumoto f73ac4112f Update .travis.yml 2017-12-11 22:17:30 +09:00
Yukihiro "Matz" Matsumoto 0e452a75ac Update .travis.yml 2017-12-11 19:36:52 +09:00
Yukihiro "Matz" Matsumoto b763759972 Reduce VC++ compiler warnings. 2017-12-11 17:22:46 +09:00
Yukihiro "Matz" Matsumoto c76631d445 Update .travis.yml to use gcc-6
The patch is created by @take_cheese in #3872
2017-12-11 17:19:49 +09:00
Yukihiro "Matz" Matsumoto 6d42195fb2 Add enable_sanitizer method for clang and gcc.
The patch is created by @take_cheese in #3872
2017-12-11 17:14:50 +09:00
Yukihiro "Matz" Matsumoto 274884abe5 Reduce VC++ compiler warnings. 2017-12-09 16:14:12 +09:00
Yukihiro "Matz" Matsumoto 761218e70b Skip socket tests on Windows platform.
Some test may be OK but we skip everything as a starting point.
2017-12-09 14:22:53 +09:00
Yukihiro "Matz" Matsumoto b103fa229d File.symlink may not be implemented on some platforms; ref #3877 2017-12-09 14:22:03 +09:00
Yukihiro "Matz" Matsumoto bda273f35d Merge pull request #3877 from bamchoh/patch-3
Skip "File.readlink fails" test on MSVC
2017-12-09 14:16:20 +09:00
Yukihiro "Matz" Matsumoto 6bc38f4637 Merge pull request #3876 from bamchoh/patch-2
Use same format between Fail and Skip
2017-12-09 13:15:10 +09:00
bamchoh 0ded91c806 Skip "File.readlink fails" test on MSVC
When MSVC, "File.readlink fails with non-symlink" test was failed even if raising NotImplementedError
2017-12-09 03:27:05 +09:00
bamchoh 81dc383291 Use same format between Fail and Skip
We can see gem name in skip message by this fix
2017-12-09 02:12:37 +09:00
Yukihiro "Matz" Matsumoto 550c878216 Use RL_READLINE_VERSION to determine rl_free existence; fix #3875 2017-12-08 21:49:12 +09:00
Yukihiro "Matz" Matsumoto e17092debd Merge pull request #3874 from mimaki/fix-mingw-compile-error
Fixed compile error of `mruby-io` gem on MinGW.
2017-12-08 14:34:10 +09:00
Yukihiro "Matz" Matsumoto c47a1984b4 Merge pull request #3873 from take-cheeze/fix_socket_test_leak
Fix memory leak found by leak sanitizer.
2017-12-08 14:33:49 +09:00
Hiroshi Mimaki 7f3bda5653 Fixed compile error of mruby-io gem on MinGW. 2017-12-08 12:58:26 +09:00
Takeshi Watanabe 5de7dc2948 Fix memory leak found by leak sanitizer. 2017-12-08 12:10:28 +09:00
Yukihiro "Matz" Matsumoto 83065df67a Reduce compiler warnings from mruby-io gem. 2017-12-08 10:07:41 +09:00
Yukihiro "Matz" Matsumoto f9d1d72217 Avoid VC++ reserved word template. 2017-12-08 09:55:55 +09:00
Yukihiro "Matz" Matsumoto 36a0b864ba Reduce VC++ compiler warnings. 2017-12-08 09:50:02 +09:00
Yukihiro "Matz" Matsumoto f1207573bd Uninitialized value returned. 2017-12-08 09:50:02 +09:00
Yukihiro "Matz" Matsumoto 6ebcb7417a AppVeyor compile errors resolution. 2017-12-08 09:37:50 +09:00
Yukihiro "Matz" Matsumoto 9df7bceb15 AppVeyor compiler does not proved some POSIX functions.
- `mode_t` by `int`
- `umask` by `_umask`
- `rmdir` by `_rmdir`
- `mkstemp` and `mkdtemp` by using `_mktemp`
2017-12-08 09:19:59 +09:00
Yukihiro "Matz" Matsumoto b724e06cf2 Avoid uninitialized local variables in mruby-pack. 2017-12-07 20:28:30 +09:00
Yukihiro "Matz" Matsumoto bc9e3e6fd0 Add type cast to readline(2) return value. 2017-12-07 20:26:34 +09:00
Yukihiro "Matz" Matsumoto 764a568aa4 Remove unused variable usock from mruby-socket/src/socket.c. 2017-12-07 20:25:40 +09:00
Yukihiro "Matz" Matsumoto ff1194c134 fixup! Fix type casting errors when mruby-socket compiled by C++. 2017-12-07 20:24:13 +09:00
Yukihiro "Matz" Matsumoto a5412d48fd Add 'mrbgems/mruby-pack/' from commit '383a9c79e191d524a9a2b4107cc5043ecbf6190b'
git-subtree-dir: mrbgems/mruby-pack
git-subtree-mainline: 842e6945f2
git-subtree-split: 383a9c79e1
2017-12-07 18:35:09 +09:00
Yukihiro "Matz" Matsumoto 842e6945f2 Fix type casting errors when mruby-socket compiled by C++.
Also `bool` is a reserved word in C++.
2017-12-07 18:23:01 +09:00
Yukihiro "Matz" Matsumoto 73ef548c63 Add 'mrbgems/mruby-socket/' from commit 'ab54185005ec87fe4f5b10df95ad29659884141b'
git-subtree-dir: mrbgems/mruby-socket
git-subtree-mainline: d75266dd1b
git-subtree-split: ab54185005
2017-12-07 18:11:13 +09:00
Yukihiro "Matz" Matsumoto d75266dd1b Add 'mrbgems/mruby-io/' from commit '3c8e1f94c44252c836f79a48bb17726da28e2756'
git-subtree-dir: mrbgems/mruby-io
git-subtree-mainline: 10ed730e4b
git-subtree-split: 3c8e1f94c4
2017-12-07 18:11:06 +09:00
Yukihiro "Matz" Matsumoto 10ed730e4b Cancel df3507660 that does not do any good. 2017-12-07 15:18:41 +09:00
Yukihiro "Matz" Matsumoto cdf173d32c Avoid updating to reallocated stack in OP_RETURN; fix #3870
The code was introduced to address #3175 but it's no longer needed.
2017-12-07 15:05:14 +09:00
Yukihiro "Matz" Matsumoto 0e46b14b9e The ci should not be equal to cibase with OP_R_BREAK; #3871 2017-12-06 17:28:20 +09:00
Yukihiro "Matz" Matsumoto 6975258efd The proc with top-level env must be 'proc-closure'; fix #3871 2017-12-06 17:28:20 +09:00
Yukihiro "Matz" Matsumoto ae44e80668 Limit ecall() depth to 32 (default). 2017-12-06 17:28:20 +09:00
Yukihiro "Matz" Matsumoto b00d45b095 mrb_method_search_vm() should gives the defined class.
Otherwise `super` may call a wrong method.
2017-12-06 17:28:20 +09:00
Yukihiro "Matz" Matsumoto 4a99f4949e Need to set ci->proc when we have RProc structure.
Mentioned in https://qiita.com/bamchoh/items/eabebbbb330cb0e0470a
2017-12-05 11:43:12 +09:00
Yukihiro "Matz" Matsumoto cbb6f29875 Merge pull request #3868 from bamchoh/patch-1
Revise MRB_METHOD_PROC macro's argument
2017-12-05 06:47:22 +09:00
bamchoh 940133b627 Revise MRB_METHOD_PROC macro's argument
I revised MRB_METHOD_PROC macro's argument fn to m.
2017-12-05 01:22:43 +09:00
Yukihiro "Matz" Matsumoto 1fea63429e Some OS uses libedit that does not provide rl_free().
`libedit` is a `readline` compatible library with BSD license.
2017-12-04 11:53:19 +09:00
Yukihiro "Matz" Matsumoto 0b5d97ec42 Need to unshare env stack on break; fix #3866 2017-12-04 10:15:12 +09:00
Yukihiro "Matz" Matsumoto 6f4d4bbcc7 Remove temporary objects from GC arena in `mrb_vformat()'; #3863 2017-12-04 08:56:11 +09:00
Yukihiro "Matz" Matsumoto 5d04e3316b Check if ci->proc is not NULL and MRB_PROC_CFUNC_P(); fix #3867 2017-12-04 08:56:11 +09:00
Yukihiro "Matz" Matsumoto ff8b608c52 Free read lines using the deallocation function from the library.
To avoid potential `malloc/free` mismatch.
2017-12-04 08:56:11 +09:00
Yukihiro "Matz" Matsumoto cd9f53d42e Pop exception objects from the bottom of GC arena; fix #3863 2017-12-04 08:56:11 +09:00
Yukihiro "Matz" Matsumoto c35a402676 The stack shift width should be determined by p->upper; fix #3864
And check required register number from `ci->proc` as well.
The fixes for #3859 and #3862 were incomplete.
2017-12-01 10:01:46 +09:00
Yukihiro "Matz" Matsumoto 86ef9a2806 Avoid calling mrb_env_unshare() when env is NULL.
Small performance improvement by reducing function invocations.
2017-11-30 08:19:38 +09:00
Yukihiro "Matz" Matsumoto 2b9f762ba1 Avoid double free() of env stack; fix #3860
Should turn on `MRB_ENV_STACK_UNSHARED` flag only after env stack
reallocation.  `malloc()` may fail.
2017-11-30 08:17:14 +09:00
Yukihiro "Matz" Matsumoto d3e273ba4e Wrong stack adjustment in ecall() (f35f975 #3859); fix #3862 2017-11-30 08:04:27 +09:00
Yukihiro "Matz" Matsumoto f3279b41e6 Stop infinite recursion in Class#to_s; fix #3861 2017-11-30 07:58:11 +09:00
Yukihiro "Matz" Matsumoto 5f7cdecdc9 Clear c->prev on fiber termination. 2017-11-29 20:25:55 +09:00
Yukihiro "Matz" Matsumoto b746a0f0d2 Need to free contexts when freeing fibers.
Memory leak fixed; ref #3711
2017-11-29 20:24:03 +09:00
Yukihiro "Matz" Matsumoto 9c78a9bfa2 Set MRB_FIBER_TERMINATED flag on exception termination of a fiber. 2017-11-29 20:17:33 +09:00
Yukihiro "Matz" Matsumoto b7c3a876f1 Add most recent call last message to the backtrace. 2017-11-29 16:56:10 +09:00
Yukihiro "Matz" Matsumoto 3e67a116d1 Call all ensure clauses pushed at OP_STOP. 2017-11-29 12:16:16 +09:00
Yukihiro "Matz" Matsumoto afa53809e2 No need to use ecall_adjust(). 2017-11-29 12:15:24 +09:00
Yukihiro "Matz" Matsumoto f35f975d26 Fixed stack address adjustment in ecall(); fix #3859 2017-11-29 12:14:05 +09:00
Yukihiro "Matz" Matsumoto d4fc980527 Need to evaluate ensure clauses at fiber termination. 2017-11-29 11:57:33 +09:00
Yukihiro "Matz" Matsumoto 6bb5ad786c Remove unnecessary code; ref #3711 2017-11-29 11:44:07 +09:00
Yukihiro "Matz" Matsumoto 597149ae23 Change newline style of test/t/lang.rb (from DOS) 2017-11-22 16:10:28 +09:00
Yukihiro "Matz" Matsumoto b4f9b031de Some cosmetic changes 2017-11-22 16:09:50 +09:00
Yukihiro "Matz" Matsumoto 284a1d12ee Provide shortcut comparison methods for numbers for performance. 2017-11-22 15:43:48 +09:00
Yukihiro "Matz" Matsumoto 0ab21a9a5e Stack adjustment should be based on p->upper; fix #3857
It used to be based on `ci->proc` but the callinfo position may be
wrong when `ecall()` is called during stack rewinding from `OP_RETURN`.
2017-11-22 14:05:11 +09:00
Yukihiro "Matz" Matsumoto fbafa78098 Clear ensure stack after calling in OP_EPOP; #3855 3856 2017-11-22 12:22:45 +09:00
Yukihiro "Matz" Matsumoto 4665b07f7b No need to pop ensure stack if eidx is smaller than epos; #3855 #3856 2017-11-22 12:21:24 +09:00
Yukihiro "Matz" Matsumoto fe3ac50845 fixup! Remove fixed argument of ecall(); ref #3855 #3856 2017-11-22 12:20:56 +09:00
Yukihiro "Matz" Matsumoto cb4b042777 Remove fixed argument of ecall(); ref #3855 #3856 2017-11-22 12:19:40 +09:00
Yukihiro "Matz" Matsumoto 393133e741 Should have marked all ensure stack entries; fix #3855 fix #3856 2017-11-22 12:18:20 +09:00
Yukihiro "Matz" Matsumoto 8b7a8978e2 Reduce the size of struct RBreak to reduce memory usage.
The old size of `struct RBreak` was 56 bytes (`MRB_NO_BOXING`)
and it's bigger than other object structures. That increase the
size of `RVALUE` thus increase the total amount of memory consumption.
2017-11-20 18:33:41 +09:00
Yukihiro "Matz" Matsumoto 8f2c62407c Add MRB_METHOD_TABLE_INLINE option.
Now the method tables (in classes/modules and caches) keeps C function
pointers without wrapping in `struct RProc` objects. For the sake of
portability, `mrb_method_t` is represented by the struct and union, but
if the most significant bit of the pointer is not used by the platform,
`mrb_method_t` should be packed in `uintptr_t` to reduce memory usage.

`MRB_METHOD_TABLE_INLINE` is turned on by default for linux.
2017-11-20 18:33:41 +09:00
Yukihiro "Matz" Matsumoto 6c06e77446 Add MRB_METHOD_CACHE description to include/mrbconf.h 2017-11-20 06:04:27 +09:00
Yukihiro "Matz" Matsumoto 6a9efd6849 Invoke mrb_full_gc() before ObjectSpace.count_objects. 2017-11-19 12:19:46 +09:00
Yukihiro "Matz" Matsumoto 9b2454c94d Leave hash->ht to be NULL if initial capacity is zero. 2017-11-19 03:46:58 +09:00
Yukihiro "Matz" Matsumoto 7405821f5a doc/limitaions.md: Remove infinite recursion entry.
It's fixed since 1.3.0
2017-11-18 21:16:22 +09:00
Yukihiro "Matz" Matsumoto 86f9254df0 doc/limitaions.md: Remove Kernel.binding entry.
Since no ISO classes/methods are not provided by mruby, there's
no use mentioning `Kernel.binding` here.
2017-11-18 21:14:19 +09:00
Yukihiro "Matz" Matsumoto 825e93eba4 Assign operands to local variables. 2017-11-18 00:03:59 +09:00
Yukihiro "Matz" Matsumoto 31ce73ddc3 Merge pull request #3853 from ukrainskiysergey/variable_c_cosmetic_changes
Removed useless condition
2017-11-18 00:03:50 +09:00
Ukrainskiy Sergey a2d0ee59c6 Removed useless condition 2017-11-17 22:30:22 +09:00
Yukihiro "Matz" Matsumoto 269f9f2125 Merge pull request #3852 from dabroz/feature-array-transpose
implement Array.transpose
2017-11-17 21:50:34 +09:00
Tomasz Dąbrowski e65fa4d7a2 implement Array.transpose 2017-11-17 12:39:34 +01:00
Yukihiro "Matz" Matsumoto d01003ce3a Merge pull request #3851 from ukrainskiysergey/variable_c_cosmetic_changes
Cosmetic changes in variable.c
2017-11-17 20:04:37 +09:00
Ukrainskiy Sergey ddd32d74e1 Changed the assignment of a variable in variable.c 2017-11-17 19:43:57 +09:00
Ukrainskiy Sergey 74714c8fee Changed numbers to TRUE and FALSE for mrb_bool in variable.c 2017-11-17 19:16:29 +09:00
Yukihiro "Matz" Matsumoto c8da602752 Need to save stack space by number of registers from the current proc,
Not from the execution ensure proc; fix #3849
2017-11-17 01:08:46 +09:00
Yukihiro "Matz" Matsumoto 03a3bd9178 The number of argument should be retrieved by mrb_get_argc; fix #3848
You should not access `mrb->c->ci->argc` directly.
2017-11-13 16:16:38 +09:00
Yukihiro "Matz" Matsumoto c210a8adf9 Fixed wrong stack extend size; fix #3847 2017-11-11 17:55:32 +09:00
Yukihiro "Matz" Matsumoto 181f980b6c Need to clear stack region for local variables in eval; fix #3844 2017-11-10 21:53:12 +09:00
Yukihiro "Matz" Matsumoto 41c8c419cf Use proper target_class to define class/module; fix #3843
The outer class of the class/module definition should be taken from
`MRB_TARGET_CLASS(mrb->c->ci->proc)` not `mrb->c->ci->target_class`
which is the target of constant lookups.
2017-11-09 00:14:21 +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
Yukihiro "Matz" Matsumoto 7ae20e0785 Simplify MRB_WITHOUT_FLOAT condtion 2017-11-08 08:45:59 +09:00
Yukihiro "Matz" Matsumoto 37f6e42293 Removed redundant function prototype. 2017-11-04 17:59:00 +09:00
Yukihiro "Matz" Matsumoto d6cb4f9cf2 Merge branch 'pandax381-mrb_without_float' 2017-11-04 12:33:07 +09:00
Yukihiro "Matz" Matsumoto a751f7f196 Make mirb to print warnings; ref #3827 2017-11-04 12:32:34 +09:00
Yukihiro "Matz" Matsumoto fef4b394a7 Avoid compiling fmt_fp.c if MRB_WITHOUT_FLOAT is set; #3827 2017-11-04 12:12:52 +09:00
Yukihiro "Matz" Matsumoto de2363a9f0 Merge branch 'mrb_without_float' of https://github.com/pandax381/mruby into pandax381-mrb_without_float 2017-11-04 11:49:25 +09:00
Yukihiro "Matz" Matsumoto 388d26d770 Reimplement block_given?; ref #3841
Make `block_given?` to search for the top of the scope first.
The top of the scope means either:

* the top method body
* the enclosing class body
* the top-level

The special case is the method defined by `define_method` with a
block as in #3841. In cases like this, the method body (given by
a block) is not considered as the top of the scope. You need to use
`&block` in the block parameter if you want to know if a block is
given to the method.

This commit also changes the behavior of `MRB_PROC_SCOPE` flag.
Now it is only set if the `proc` is either a class body or a method
body defined in Ruby. It is no longer set for a block that given to
`define_method`.
2017-11-04 11:20:04 +09:00
Yukihiro "Matz" Matsumoto ab27abe083 The bidx saved in env may be useless; fix #3841
When `block_given?` is called from a block given to `define_method`
as a method body, the `bidx` may not be within `env` saved closure.
In this case, it causes heap buffer overflow.
2017-11-04 03:01:37 +09:00
YAMAMOTO Masaya 625f9f6fa3 Merge branch 'master' of github.com:mruby/mruby 2017-11-04 01:23:12 +09:00
Yukihiro "Matz" Matsumoto e7fe6ee263 Avoid pointer arithmetic in backtrace.c; #3816 2017-11-04 00:35:50 +09:00
Yukihiro "Matz" Matsumoto 12e38597c8 Always check division-by-zero to avoid undefined behavior; fix #3816
Also removed the code to normalize NaN value for `MRB_NAN_BOXING`.
Tha code was added to fix #1712 but no longer required after 249f05e7d.
2017-11-03 09:35:55 +09:00
Yukihiro "Matz" Matsumoto d489b41c31 Reduce memory leaks from mirb. 2017-11-03 08:24:47 +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
Yukihiro "Matz" Matsumoto 13a318b0c7 Merge pull request #3840 from iij/keep-backtrace-rethrown-exc
don't strip away backtrace info when an exception is re-thrown
2017-11-02 21:36:26 +09:00
Tomoyuki Sahara f6896751b4 don't overwrite backtrace info. 2017-11-02 15:44:05 +09:00
Yukihiro "Matz" Matsumoto ddfb24908c Fixed constant (and class variable) reference bug; fix #3839
Unlike method definition, constant reference should start from
`MRB_PROC_TARGET_CLASS(ci->proc)`, not `ci->target_class`.
In addition, `MRB_PROC_TARGET_CLASS(ci->proc)` is always set.
2017-10-31 09:10:08 +09:00
Yukihiro "Matz" Matsumoto 022570ab8d Call stack may not reference the destination proc; fix #3838
The destination `proc` may be an orphan.
2017-10-31 09:10:08 +09:00
Yukihiro "Matz" Matsumoto b6598e052f Need to mark fibers referenced from env; fix #3837
The issue #3837 is a regression of #3819. I was mistakenly removed
a important code to mark fibers from `env`.
2017-10-31 09:10:08 +09:00
Yukihiro "Matz" Matsumoto 77edafb04c Need to check number of argument of Struct#new; fix #3823 2017-10-29 00:25:45 +09:00
Yukihiro "Matz" Matsumoto 59dc7d0763 Removed a debug printf; fix #3834 2017-10-28 23:39:21 +09:00
Yukihiro "Matz" Matsumoto 1b45e034ba Remove one of the lines that did the same thing; fix #3836
The change is suggested by `ukrainskiysergey` in #3836.
I deleted the other line for clarity. I also updated comment lines.
2017-10-28 23:35:01 +09:00
Yukihiro "Matz" Matsumoto 6316e0c75d Should clear ensure stack at OP_RETURN break; #3715
This is a resurrection of d0a7e01, which is accidentally
removed by 93f5f22; Fix #3715
2017-10-28 23:27:07 +09:00
Yukihiro "Matz" Matsumoto 92e24f809b Should check if callinfo stack is popped before updating the stack.
This is a resurrection of 75c374c, which is accidentally removed by
93f5f22; Fix #3507 #3512 #3518 #3521
2017-10-28 23:10:28 +09:00
Yukihiro "Matz" Matsumoto c7c9543bed Fixed UPVAR gotchas; fix #3835
Both `uvenv` function and `env` generation in `create_proc_from_string`
function have bugs to handling enclosed environment objects.
2017-10-28 23:08:31 +09:00
Yukihiro "Matz" Matsumoto 57dad6e3fd Remove a debug variable 2017-10-28 01:37:51 +09:00
Yukihiro "Matz" Matsumoto 23d18bbd62 Add parentheses to pacify a warning. 2017-10-28 01:32:25 +09:00
Yukihiro "Matz" Matsumoto 93f5f22577 Heavily refactored how lexical scope links are implemented; fix #3821
Instead of `irep` links, we added a `upper` link to `struct RProc`.
To make a space for the `upper` link, we moved `target_class` reference.
If a `Proc` does not have `env`, `target_class` is saved in an `union`
shared with `env` (if a `Proc` has env, you can tell it by `MRB_PROC_ENV_P()).
Otherwise `target_class` is referenced from `env->c`. We removed links
in `env` as well.

This change removes 2 members from `mrb_irep` struct, thus saving 2
words per method/proc/block. This also fixes potential memory leaks
due to the circular references caused by a link from `mrb_irep`.
2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 3f9d00ded3 comment out bench build from standard build_config.rb 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 4614b9d632 remove inline from replacement memcpy&memset 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 5405b47f41 Update test for Kernel#local_variables 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 14877469d1 Remove MRB_API from mrb_env_unshare() 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 07cf7b16f3 Add some peephole optimizations 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 6c966a1f86 Change the order of "expected" and "actual" in test 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 0cf5a0ee37 Use alias to implement attr method 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto fda64be996 Flush stdout after every print from tests 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 71eeb86a99 Format codedump for OP_{LE,LT,GE,GT}. 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto d08205b40d Merge pull request #3833 from bggd/appveyor_winbison_ruby24
Appveyor Improvements
2017-10-25 00:31:44 +09:00
bggd 7f4cc0de51 Turn on method cache for AppVeyor CI 2017-10-24 21:39:05 +09:00
bggd 7a13e89509 Use Ruby 2.4 instead of AppVeyor's Default(Ruby 1.9) 2017-10-24 21:37:36 +09:00
bggd 8a9b6c4352 Use win_bison instead of Cygwin's bison. Use YACC environment variable instead of global PATH 2017-10-24 21:31:37 +09:00
Yukihiro "Matz" Matsumoto 0c3ee0ba66 Add `Array#{permutation,combination}. 2017-10-20 10:38:58 +09:00
Yukihiro "Matz" Matsumoto f2394859e3 Add main.define_method 2017-10-19 10:39:06 +09:00
Tomoyuki Sahara 3c8e1f94c4 Merge pull request #94 from kazuho/kazuho/rename-compatibility
make `rename` behavior consistent with MRI
2017-10-18 13:22:22 +09:00
Yukihiro "Matz" Matsumoto fc930700b7 Add Kernel#itself; CRuby2.2 2017-10-18 10:21:54 +09:00
Yukihiro "Matz" Matsumoto ce916b99b8 Add Hash#to_proc; CRuby2.3 2017-10-18 10:18:43 +09:00
Yukihiro "Matz" Matsumoto b5dfbce767 Add Numeric#{positive?,negative?}; CRuby2.3 2017-10-18 10:10:37 +09:00
Yukihiro "Matz" Matsumoto 44f07045d1 Add Hash#fetch_values; CRuby2.3 2017-10-18 10:05:39 +09:00
Yukihiro "Matz" Matsumoto 913b83d579 Merge branch 'dabroz-fix-get-argc' 2017-10-17 15:24:00 +09:00
Yukihiro "Matz" Matsumoto 3c20c96f84 Use a new function: mrb_get_argc(); ref #3826 2017-10-17 15:23:32 +09:00
Yukihiro "Matz" Matsumoto b890528a18 Remove mrb_vm_get_argc; ref #3826 2017-10-17 15:22:45 +09:00
Yukihiro "Matz" Matsumoto 344a7ce20c Merge branch 'fix-get-argc' of https://github.com/dabroz/mruby into dabroz-fix-get-argc 2017-10-17 15:07:05 +09:00
Yukihiro "Matz" Matsumoto 4122c320bb Add {String,Symbol}#casecmp?; CRuby2.4 2017-10-17 13:26:37 +09:00
Yukihiro "Matz" Matsumoto db8265f428 Add Comparable#uniq; CRuby2.4 2017-10-17 12:46:51 +09:00
Yukihiro "Matz" Matsumoto 4e365156d1 Add Comparable#clamp; CRuby2.4 2017-10-17 11:19:12 +09:00
Yukihiro "Matz" Matsumoto 061d804a59 Add Numeric#{finite?,infinite?}; CRuby2.4 2017-10-17 11:19:12 +09:00
Yukihiro "Matz" Matsumoto 332d8d2a1c Add String#delete_{prefix,suffix}; CRuby2.5 2017-10-17 11:19:12 +09:00
Yukihiro "Matz" Matsumoto 1519616ecb Add Kernel#yield_self; CRuby2.5 2017-10-17 09:10:13 +09:00
Yukihiro "Matz" Matsumoto c96def7c96 Remove top-level constant lookup; CRuby2.5 2017-10-17 08:45:06 +09:00
Yukihiro "Matz" Matsumoto e59ad60327 do/end blocks to work with rescue/ensure/else; CRuby2.5 2017-10-17 08:17:31 +09:00
Yukihiro "Matz" Matsumoto fb85855fa1 Add more checks before accessing struct pointer; ref #3831 2017-10-17 07:43:35 +09:00
Yukihiro "Matz" Matsumoto be2c1592ed Check struct-array pointer before accessing; fix #3831 2017-10-16 22:53:36 +09:00
Yukihiro "Matz" Matsumoto 1988bec23e Need to adjust the stack length of the top-level environment; fix #3819 2017-10-16 22:35:25 +09:00
Yukihiro "Matz" Matsumoto c3710dbb96 Fix a compile error on zero mrbgem case. 2017-10-16 18:46:15 +09:00
Yukihiro "Matz" Matsumoto 6b0c22e395 Merge pull request #3830 from dearblue/fix-alias-for-struct-accessors
fix alias for Struct accessors
2017-10-16 18:45:52 +09:00
YAMAMOTO Masaya b70d69de09 Support MRB_WIHTOUT_FLOAT to mruby-kernel-ext 2017-10-16 18:15:47 +09:00
YAMAMOTO Masaya 9afd376fa4 Support MRB_WIHTOUT_FLOAT to mruby-object-ext 2017-10-16 18:15:25 +09:00
YAMAMOTO Masaya b0cdb93a3a Support MRB_WIHTOUT_FLOAT to mruby-numeric-ext (test only) 2017-10-16 18:14:34 +09:00
YAMAMOTO Masaya 9c1f21aaa1 Support MRB_WIHTOUT_FLOAT to mruby-string-ext 2017-10-16 18:09:56 +09:00
dearblue 44e2c97152 fix alias for Struct accessors 2017-10-15 23:43:55 +09:00
YAMAMOTO Masaya 5d781312ca Support MRB_WIHTOUT_FLOAT to mruby-sprintf 2017-10-13 16:42:35 +09:00
Yukihiro "Matz" Matsumoto fa974a1f6a Merge pull request #3828 from asfluido/master
Correct a small error in parse.y
2017-10-12 20:19:24 +09:00
Carlo Prelz af3d5d6c8a Correct a small error in parse.y, which causes the reading of unassigned memory (triggers an error when address sanitizer is active) 2017-10-12 09:54:02 +02:00
Kazuho Oku 0d92431061 make the behavior consistent with MRI 2017-10-12 15:23:52 +09:00
YAMAMOTO Masaya 81ea81e05c Fix typo 2017-10-11 19:52:21 +09:00
YAMAMOTO Masaya 3eebe81b35 Upadte AUTHORS 2017-10-11 19:44:34 +09:00
YAMAMOTO Masaya dcd5d0ffec Test for MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
YAMAMOTO Masaya acdc2d1f24 Add MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
YAMAMOTO Masaya 679dfd75a8 Use division expression instead of some floating point literals 2017-10-11 17:58:11 +09:00
Tomasz Dąbrowski be86d8b45f correctly handle *splat arguments in mrb_get_argc, also add mrb_vm_get_argc and mrb_get_argv
Fixes #3825
2017-10-10 18:40:38 +02:00
Yukihiro "Matz" Matsumoto 80e03f3ffb Merge pull request #3824 from nobu/bug/paren_arg
Bug/paren arg
2017-10-09 12:39:13 +09:00
Nobuyoshi Nakada 82983330a3 Fix parse error on TRICK2013/yhara 2017-10-09 08:56:46 +09:00
Nobuyoshi Nakada 1c2a2827b3 Replace lvar_defined with local_var_p 2017-10-09 08:54:25 +09:00
Tomoyuki Sahara f8121953e7 Merge pull request #92 from palkan/master
Handle shared/frozen strings in IO#sysread
2017-10-05 21:27:58 +09:00
Vladimir Dementyev 43795cb1f1 Remove useless mrb_str_modify 2017-10-05 15:22:57 +03:00
Vladimir Dementyev 4c255c7739 Handle shared/frozen strings in IO#sysread
See https://github.com/mruby/mruby/commit/7edbe428caca6814841195a3f2720745cf04353e
2017-10-05 14:40:43 +03:00
Yukihiro "Matz" Matsumoto c3c882f681 Use uint32_t to avoid signed integer overflow warning; #3816 2017-10-01 17:53:10 +09:00
Yukihiro "Matz" Matsumoto 8c408379aa Add cscope.files to .gitignore. 2017-10-01 16:24:43 +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
Yukihiro "Matz" Matsumoto 473b7d0efd Cut links from irep in heaps finalization. 2017-09-29 00:18:55 +09:00
Yukihiro "Matz" Matsumoto 7b01b969f5 codedump to display OP_CALL. 2017-09-29 00:18:55 +09:00
Yukihiro "Matz" Matsumoto 29a9e698e3 Merge pull request #3815 from dabroz/fix-warnings
Fix MSVC 14.0 warnings
2017-09-29 00:18:39 +09:00
Tomasz Dąbrowski 999ce87129 fix: src\vm.c(2631): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 77d6a953ff fix: src\vm.c(1757): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski ebd45b1072 fix: src\vm.c(1744): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 0bff4b6a09 fix: src\vm.c(1702): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 885916c84b fix: src\vm.c(708): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski e88fc10679 fix: src\vm.c(704): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski ec7f478eda fix: src\vm.c(457): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 67ab8406b8 fix: src\vm.c(445): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 23cc698134 fix: src\vm.c(438): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 5ede90cdf4 fix: src\vm.c(438): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02: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 6cde950017 fix: src\state.c(66): warning C4200: nonstandard extension used: zero-sized array in struct/union 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 0e2976bf93 fix: src\range.c(136): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski b7e71e4cef fix: src\proc.c(96): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 490de9dbe1 fix: src\print.c(22): warning C4244: 'initializing': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 220c628210 fix: src\pool.c(33): warning C4200: nonstandard extension used: zero-sized array in struct/union 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski f0c1074b07 fix: src\numeric.c(1215): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 4a0c9c9e31 fix: src\numeric.c(954): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 332a04af73 fix: src\numeric.c(897): warning C4244: 'function': conversion from 'mrb_int' to 'mrb_float', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 971a4f9122 fix: src\kernel.c(874): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 0e0c96096d fix: src\kernel.c(861): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 7d98055862 fix: src\hash.c(139): warning C4244: 'function': conversion from 'mrb_int' to 'khint_t', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 8cef3f946c fix: src\hash.c(40): warning C4244: '=': conversion from 'mrb_int' to 'khint_t', 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
Tomasz Dąbrowski c7b663f2cf fix: src\gc.c(1425): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski b406e9f795 fix: src\gc.c(1392): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 1dcf8ba488 fix: src\gc.c(559): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 7a2391b120 fix: src\error.c(76): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 4d6b8dbcb9 fix: src\dump.c(710): warning C4244: 'function': conversion from 'mrb_int' to 'uint16_t', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski f4a17dd7b5 fix: src\dump.c(657): warning C4244: 'function': conversion from 'mrb_int' to 'uint16_t', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 5ed76e381c fix: src\class.c(949): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 9c5db48d1f fix: src\class.c(949): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski d8b37d0381 fix: src\class.c(583): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 4146b5c2b5 fix: src\backtrace.c(83): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 7507d46992 fix: src\array.c(86): warning C4244: '=': conversion from 'mrb_int' to 'uint32_t', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski be81504770 fix: mrbgems\mruby-time\src\time.c(641): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 0848407ee5 fix: mrbgems\mruby-time\src\time.c(372): warning C4244: 'function': conversion from 'mrb_int' to 'double', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski d713f8d761 fix: mrbgems\mruby-test\driver.c(67): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 2640896911 fix: mrbgems\mruby-string-ext\src\string.c(49): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 8d816fa142 fix: mrbgems\mruby-string-ext\src\string.c(30): warning C4244: '=': conversion from 'mrb_int' to 'long', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski d3819620ce fix: mrbgems\mruby-string-ext\src\string.c(38): warning C4244: '=': conversion from 'mrb_int' to 'char', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski a94525d4ea fix: mrbgems\mruby-sprintf\src\sprintf.c(1052): warning C4244: '+=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 1e2c962fa5 fix: mrbgems\mruby-sprintf\src\sprintf.c(623): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 897eabb1bb fix: mrbgems\mruby-sprintf\src\sprintf.c(646): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski e10b329fa3 fix: mrbgems\mruby-sprintf\src\sprintf.c(618): warning C4244: 'initializing': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 861077f779 fix: mrbgems\mruby-sprintf\src\sprintf.c(516): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 553dbad2c6 fix: mrbgems\mruby-math\src\math.c(660): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 49e96a2e19 fix: mrbgems\mruby-math\src\math.c(491): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 536b95eb48 fix: mrbgems\mruby-kernel-ext\src\kernel.c(114): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 9d89f8c00b fix: mrbgems\mruby-fiber\src\fiber.c(215): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 377d6a47ac fix: mrbgems\mruby-exit\src\mruby-exit.c(10): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski f632baddb1 fix: mrbgems\mruby-eval\src\eval.c(301): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 14:42:27 +02:00
Tomasz Dąbrowski 49db1db81f fix: mrbgems\mruby-eval\src\eval.c(214): warning C4244: '=': conversion from 'mrb_int' to 'short', possible loss of data 2017-09-27 14:42:27 +02:00
Tomasz Dąbrowski 2e239a296e fix: mrbgems\mruby-compiler\core\parse.y(3455): warning C4244: 'function': conversion from 'intptr_t' to 'int', possible loss of data 2017-09-27 14:42:27 +02:00
Tomasz Dąbrowski f1a02dff58 fix: include\mruby/gc.h(43): warning C4200: nonstandard extension used: zero-sized array in struct/union 2017-09-27 14:42:27 +02:00
Yukihiro "Matz" Matsumoto 381850280c The [] special method call should be able to take a block. 2017-09-25 20:44:50 +09:00
Yukihiro "Matz" Matsumoto e98823f189 The lex_state after literals should be EXPR_ENDARG. 2017-09-25 20:44:04 +09:00
Yukihiro "Matz" Matsumoto e01d35ef79 The symbols should not take brace blocks. 2017-09-25 20:22:36 +09:00
Yukihiro "Matz" Matsumoto 298177fd6a Merge pull request #3813 from dabroz/feature-fix-date
Change DISABLE_STDIO to MRB_DISABLE_STDIO in mruby-time/time.c
2017-09-25 20:19:13 +09:00
Tomasz Dabrowski e00b48be4a change DISABLE_STDIO to MRB_DISABLE_STDIO in mruby-time/time.c 2017-09-25 13:11:20 +02:00
Yukihiro "Matz" Matsumoto 7450a774a5 The first instruction was skipped mistakenly in ensure clause; fix #3811 2017-09-23 10:12:04 +09:00
Yukihiro "Matz" Matsumoto 0ceaa0960a OP_EPOP operand may be bigger than mrb->c->eidx; fix #3810 2017-09-22 13:00:58 +09:00
Yukihiro "Matz" Matsumoto 5760226e71 Remove temporary limitation of OP_EPOP.
After f68f5f6, the operand of `OP_EPOP` should have been `1`.
Now we have removed the limitation.
2017-09-12 12:41:02 +09:00
Tomoyuki Sahara ab54185005 receiver variables must be "mrb_int" for mrb_get_args("i").
Otherwise, it can cause a segfault on the platforms where the
size of "int" and "mrb_int" differs.
2017-09-12 12:32:12 +09:00
Tomoyuki Sahara a809d42f5a remove whitespaces at the end of line. 2017-09-12 11:43:21 +09:00
Yukihiro "Matz" Matsumoto d6e41c3e51 The callinfo stack may be reallocated in cipush; fix rest of #3809
fix #3809
2017-09-11 23:13:47 +09:00
Yukihiro "Matz" Matsumoto 3d8c1a7e97 The ensure stack may be empty at OP_EPOP; fix 1st part of #3809 2017-09-11 22:46:34 +09:00
Yukihiro "Matz" Matsumoto 2a1e616e4d Avoid calling mrb_funcall to invoke #initialize from Class.new.
If `#initialize` is implemented in C, we don't need stack consuming
`mrb_funcall`.
2017-09-06 14:35:24 +09:00
Yukihiro "Matz" Matsumoto cbfa2b3588 Avoid recursion from mark_context(). 2017-09-05 21:13:16 +09:00
Yukihiro "Matz" Matsumoto f68f5f6b97 Avoid crossing C function boundary from OP_EPOP; ref #3789 2017-09-05 21:12:36 +09:00
Yukihiro "Matz" Matsumoto 7f4b57bb20 Restrict OP_EPOP operand to 1; ref #3789 2017-09-05 21:11:41 +09:00
Tomoyuki Sahara 15f4bdb529 Merge pull request #37 from udzura/fix-types
Fix type int to mrb_int
2017-09-04 23:55:37 +09:00
Uchio KONDO 5b6e4eda2a Fix type int to mrb_int
- mruby's default int size is changed after: https://github.com/mruby/mruby/commit/f0f4a1088a270e339407a24ffe8be748f4764fc2
- implicit cast causes some errors
2017-09-04 16:33:57 +09:00
Yukihiro "Matz" Matsumoto 3acaa44a70 Restructure irep->outer chain; fix #3804
Instead of `irep -> proc` chain, we use `irep -> irep` chain to
avoid GC bugs like #3804. We added `target_class` reference to
`mrb_irep` struct. That means one more word consumption per `irep`.
2017-09-04 06:51:31 +09:00
Yukihiro "Matz" Matsumoto 8a5d783f2e Call initialize only when it's not empty. 2017-09-04 06:49:05 +09:00
Yukihiro "Matz" Matsumoto 5d7e4957e0 Merge pull request #3806 from flaviommedeiros/master
Trying to make the code more readable
2017-09-03 07:51:12 +09:00
Yukihiro "Matz" Matsumoto da97715e11 Merge pull request #3805 from fl0l0u/patch-1
Update print.c
2017-09-03 07:48:33 +09:00
fl0l0u e03042ec19 Update print.c
Strings not containing a newline are not printed synchronously
ex. bin/mruby -e '["a", "b", "c", "\n", "d", "e", "f", "\n"].each {|e| print e ; usleep 200000}'
2017-09-02 18:26:50 +02:00
Flavio Medeiros 9f677b72db Trying to make the source code more understandable by removing mixing of ternary if statements with attributions. 2017-09-02 13:25:09 -03:00
Yukihiro "Matz" Matsumoto 476af3c647 Merge pull request #3802 from christopheraue/proc_break_tests
Tested local jump errors caused by break in a proc
2017-09-02 22:19:15 +09:00
Yukihiro "Matz" Matsumoto ab99e2c293 Avoid copying over initialized procs using initialize_copy; fix #3803
It may be better to raise exceptions, but CRuby doesn't.
2017-09-01 06:51:59 +09:00
Yukihiro "Matz" Matsumoto 57610091ce Update method cache clearing. 2017-09-01 06:51:59 +09:00
Yukihiro "Matz" Matsumoto f0f4a1088a Make the default integer size to be MRB_INT64 on 64bit systems; close #3800
Unless `MRB_NAN_BOXING` is specified.
2017-09-01 06:51:59 +09:00
Christopher Aue 35deaae776 Tested LocalJumpErrors caused by break in a proc 2017-08-30 12:25:55 +02:00
Yukihiro "Matz" Matsumoto 71357ff1d8 Merge pull request #3801 from christopheraue/assert_raise_refactoring
Allowed to pass multiple exceptions to assert_raise
2017-08-30 18:56:59 +09:00
Christopher Aue bf32265743 Allowed to pass multiple exceptions to assert_raise 2017-08-30 11:03:51 +02:00
Yukihiro "Matz" Matsumoto fe3227cd5c Set the ORPHAN flag in Proc.new; fix #3798 2017-08-30 16:51:40 +09:00
Yukihiro "Matz" Matsumoto 483a038d39 Fixed a critical typo; ref #3798 2017-08-30 16:51:17 +09:00
Yukihiro "Matz" Matsumoto 2c85213298 Need to mark mrb->range_class; fix #3797 2017-08-30 16:12:12 +09:00
Yukihiro "Matz" Matsumoto 79b4f61b02 Merge pull request #3799 from christopheraue/assert_raise_refactoring
Refactored #assert_raise and #assert_nothing_raised
2017-08-30 14:47:12 +09:00
Christopher Aue 4b0b8f7e1a Refactored #assert_raise and #assert_nothing_raised 2017-08-29 23:25:53 +02:00
Yukihiro "Matz" Matsumoto 8976f47e0a Need to update ci after callinfo stack reallocation; fix #3796 2017-08-29 11:06:34 +09:00
Yukihiro "Matz" Matsumoto c082249838 Exclude the top-level closure from each_object; fix #3793 2017-08-29 09:29:14 +09:00
Yukihiro "Matz" Matsumoto 786cbf06c3 Revert "Clear irep->outer when no Proc reference the irep; fix #3793"
This reverts commit 15d48efa4b.
2017-08-29 09:27:45 +09:00
Yukihiro "Matz" Matsumoto 1260d3b68a Add `__ENCODING__' support.
`__ENCODING__' returns the current encoding name (string), unlike
CRuby that returns the encoding object.
2017-08-28 22:42:06 +09:00
Yukihiro "Matz" Matsumoto f1fa5bf1c6 Remove integer type mismatch warnings from parse.y. 2017-08-28 22:31:02 +09:00
Yukihiro "Matz" Matsumoto 15d48efa4b Clear irep->outer when no Proc reference the irep; fix #3793 2017-08-28 10:06:04 +09:00
Yukihiro "Matz" Matsumoto fd927d786e Merge pull request #3795 from christopheraue/array_refactoring
Array refactorings and speed improvements
2017-08-27 08:56:41 +09:00
Christopher Aue c956e17c02 Replaced Array#each with while loop for performance reasons
Example benchmark:
$ time build/bench/bin/mruby -e "Array.new(2_000_000){ |i| i }.index{ |i| i == 1_999_999 }"

Before:
real    0m0.934s
user    0m0.922s
sys     0m0.003s

After:
real    0m0.590s
user    0m0.583s
sys     0m0.007s
2017-08-26 15:57:25 +02:00
Christopher Aue 6c9013e22b Removed unneeded block check in Array#uniq 2017-08-26 15:57:25 +02:00
Christopher Aue f3fb43c729 Reimplemented Array#flatten with #flatten! 2017-08-26 15:57:25 +02:00
Yukihiro "Matz" Matsumoto ccd555421a Merge pull request #3794 from dabroz/fix-flt-epsilon
Fix building with MRB_USE_FLOAT=1
2017-08-26 22:29:00 +09:00
Tomasz Dąbrowski 01b9b71902 fix mrbgems/mruby-range-ext/src/range.c:142:71: error: use of undeclared identifier 'FLT_EPSILON' 2017-08-26 12:11:57 +02:00
Yukihiro "Matz" Matsumoto 85a400e43d Reimplement Array#shift to be faster. 2017-08-26 02:03:21 +09:00
Yukihiro "Matz" Matsumoto cec53ff77e Array#first to treat 1 argument case specially to improve performance. 2017-08-26 02:03:21 +09:00
Yukihiro "Matz" Matsumoto 1b545a6b63 Check for ability to skip optional argument parsing. 2017-08-26 02:03:21 +09:00
Yukihiro "Matz" Matsumoto 60104ce41d Silence compiler warning regarding float condition; fix #3790 2017-08-26 02:02:45 +09:00
Yukihiro "Matz" Matsumoto 43ec918be1 Remove unused mrb_obj_iv_ifnone() from API. 2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto 0e10a23d7a Add checks if iv_tbl is NULL. 2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto 0c52112dd4 Keep Range class in mrb_state structure for performance. 2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto 04dbbff3c1 Use khash for instance variables tables instead of segment list.
For performance reason. Segmented list consumes slightly less memory
but takes a lot of time especially when there are many slots in the
segment lists (e.g. class constants).
2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto f2cc1239a5 Turn on method cache for Travis CI. 2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto f7f1aca8b5 Merge pull request #3792 from dabroz/fix-test-int16
Fix string test with 16-bit integers
2017-08-26 02:00:30 +09:00
Yukihiro "Matz" Matsumoto 5f2c7e47bb Merge pull request #3791 from dabroz/fix-msvc-warning
Fix MSVC warnings in fmt_fp.c
2017-08-26 01:54:59 +09:00
Tomasz Dąbrowski 17c249780f fix String#% %d test with MRB_INT16 set 2017-08-25 14:36:05 +02:00
Tomasz Dąbrowski 5d9b84ef40 fix fmt_fp.c(329) : warning C4244: 'return' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:18:31 +02:00
Tomasz Dąbrowski 78b13b3955 fix fmt_fp.c(251) : warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data 2017-08-25 14:18:05 +02:00
Tomasz Dąbrowski ef6a762d41 fix fmt_fp.c(224) : warning C4244: '=' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:14:17 +02:00
Tomasz Dąbrowski bac37a9f1a fix fmt_fp.c(220) : warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data 2017-08-25 14:13:06 +02:00
Tomasz Dąbrowski b2a16d6bf7 fix fmt_fp.c(206) : warning C4244: 'initializing' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:12:08 +02:00
Tomasz Dąbrowski c8341dbf7c fix fmt_fp.c(178) : warning C4244: 'return' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:10:43 +02:00
Tomasz Dąbrowski 5d099e40e6 fix fmt_fp.c(123) : warning C4244: 'return' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:10:24 +02:00
Yukihiro "Matz" Matsumoto 63f10a1ee5 Merge pull request #3788 from christopheraue/fix_codegen_op_send_nregs
Fixed register windows of OP_SENDs generated during codegen
2017-08-24 14:38:03 +09:00
Christopher Aue 3366894a40 Fixed register windows of OP_SENDs generated by NODE_{DREGX,REGX}; ref #3783 2017-08-23 18:16:05 +02:00
Christopher Aue 499498a6a7 Tested register windows of OP_SENDs generated by NODE_{DXSTR,XSTR}; ref #3783 2017-08-23 18:15:54 +02:00
Christopher Aue 84d8ecc1d7 Fixed register windows of OP_SENDs generated by NODE_OP_ASGN; ref #3783 2017-08-23 18:15:44 +02:00
Christopher Aue 4aca9ef98e Refactored code around generation of OP_SEND in NODE_OP_ASGN 2017-08-23 18:15:38 +02:00
Christopher Aue 1221f7676e Fixed register windows of OP_SENDs generated by NODE_{FOR,SYMBOLS}; ref #3783 2017-08-23 18:15:27 +02:00
Christopher Aue c040c8d92b Tested register windows of OP_SENDs generated by NODE_{RESCUE,HASH,ALIAS}; ref #3783 2017-08-23 18:15:08 +02:00
Christopher Aue c6596cf26a Fixed register windows of OP_SENDs generated by NODE_{SCALL,CASE,YIELD,UNDEF}; ref #3783 2017-08-23 18:12:35 +02:00
Christopher Aue 64e5208404 Asserted bidx < ci->nregs for OP_SEND and OP_SUPER 2017-08-23 15:18:06 +02:00
Yukihiro "Matz" Matsumoto 4c9a604877 Added method cache.
To enable method cache, define `MRB_METHOD_CACHE` or
`MRB_METHOD_CACHE_SIZE`. The cache size must be power of 2.
The default cache size is 128.

The measurement:
I measured simple benchmarks found in benchmark/ directory. With
method cache enabled, we gained 6-8% performance improvement, with
97-99% cache hit rate.
2017-08-22 22:17:01 +09:00
Yukihiro "Matz" Matsumoto a65f4dbb32 Remove possible path that leaves a local variable uninitialized. 2017-08-22 15:50:08 +09:00
Yukihiro "Matz" Matsumoto db437b04a4 mrb_obj_respond_to to use mrb_method_search_vm. 2017-08-22 14:23:46 +09:00
Yukihiro "Matz" Matsumoto 0d865a77d5 c (mrbc_context) may be NULL; fix #3787 2017-08-22 09:47:10 +09: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 a7d611fb23 Reduce signed/unsigned warnings in dump.c 2017-08-19 21:50:36 +09:00
Yukihiro "Matz" Matsumoto 5d0fc7e57a Reduce signed/unsigned warnings in fmt_fp.c 2017-08-19 17:09:30 +09:00
Yukihiro "Matz" Matsumoto 8cea1f8907 Use ptrdiff_t instead of int. 2017-08-19 15:51:08 +09:00
Yukihiro "Matz" Matsumoto a117ec771b Remove mixed signed/unsigned comparison in debug.c. 2017-08-19 14:42:30 +09:00
Yukihiro "Matz" Matsumoto 834523945e Replace stack pop() by push_n(2); pop_n(3); fix #3783
To calculate correct register windows size. The fix was suggested
by Christopher Aue.
2017-08-19 11:56:04 +09:00
Yukihiro "Matz" Matsumoto db098d3e0e Type check before traversing irep->outer; fix #3782 2017-08-19 11:39:42 +09:00
Yukihiro "Matz" Matsumoto 2294ebdd44 Call mrb_full_gc before gc_each_objects; ref #3782
Otherwise dead object may be seen from `#each_object`.
2017-08-19 11:38:11 +09:00
Yukihiro "Matz" Matsumoto 9146d5c34f Zero width unshift should not touch memory; ref #3780 2017-08-19 11:11:26 +09:00
Yukihiro "Matz" Matsumoto 8b3298b2d6 Unshift pointer move size was wrong (not len but alen); fix #3780 2017-08-19 11:08:46 +09:00
Yukihiro "Matz" Matsumoto 29ad0a7964 capacify' for mrb_str_new_capa should not be 0`. 2017-08-18 23:42:34 +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 8fbc4bef55 Reduce signed/unsigned comparison warnings; ref #3785 2017-08-18 22:54:59 +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 198c898817 Rename mrb_str_concat2 to mrb_str_concat_m.
According to the naming convention a function that implements
a method should be suffixed by `_m`.
2017-08-18 22:17:47 +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 2adb0c201e Merge pull request #3786 from christopheraue/3784_fix
Reset ci in OP_SUPER after potential realloc
2017-08-18 22:17:33 +09:00
Yukihiro "Matz" Matsumoto 11c3ad999e Merge pull request #3781 from clayton-shopify/fix-hash-compact-bang
Check whether internal khash is initialized in Hash#compact!
2017-08-18 22:13:33 +09:00
Yukihiro "Matz" Matsumoto f229ed917e Merge pull request #3785 from miura1729/original
Improve Array structure
2017-08-18 20:37:31 +09:00
Miura Hideki 75ec86ed00 Improve Array structure 2017-08-18 20:12:00 +09:00
Christopher Aue 6b0860ce61 Reset ci in OP_SUPER after potential realloc 2017-08-18 13:11:08 +02:00
Clayton Smith 5dc688fb12 Check whether internal khash is initialized in Hash#compact! 2017-08-17 12:13:41 -04:00
Yukihiro "Matz" Matsumoto 0789ec71e0 Merge pull request #3779 from christopheraue/vm_refactoring
Some more vm refactorings
2017-08-13 07:11:21 +09:00
Christopher Aue d5ac785b31 Reintroduced not storing converted proc directly in the stack 2017-08-12 23:59:40 +02:00
Christopher Aue 198df61039 Removed unneeded ci->nregs checks in OP_SEND and OP_SUPER
Because of #3504 `ci->nregs = bidx+1` was introduced in b64f08784c.
This led to the follow up error #3551 whose fix introduced the `if (bidx >= ci->nregs)`
check in 071164b799 and the `stack_extend(mrb, ci->nregs)`
in 93d802987e.

Then, the code causing #3504 reappeared again in #3590. The fix for it moved the code
dealing with the block in OP_SUPER from below the `cipush`  to above the `cipush`
in d9fb8b69b0. The `if (bidx >= ci->nregs) { ... }` from
then on works with the original callinfo and not the pushed one. `ci->nregs` needed to
be modified for the pushed one because it is initialized to 0. But for the original ci
it is propertly set and a check is not needed.
2017-08-12 23:27:17 +02:00
Christopher Aue f2d4640998 Extended stack always based on ci->nregs 2017-08-12 14:47:22 +02:00
Christopher Aue 3f591d71c6 Refactored variable usage in OP_SEND and OP_SUPER 2017-08-12 14:31:18 +02:00
Yukihiro "Matz" Matsumoto 8bf492f127 Reduce integer type mismatch warnings in VC. 2017-08-12 09:35:35 +09:00
Yukihiro "Matz" Matsumoto baa5d2e3f7 Remove some empty lines; ref #3778 2017-08-11 22:39:31 +09:00
Yukihiro "Matz" Matsumoto 0828a962c0 Merge pull request #3778 from christopheraue/vm_refactoring
Refactored OP_SEND and OP_SUPER and calculate argc right at the top
2017-08-11 22:38:32 +09:00
Yukihiro "Matz" Matsumoto 42f9af41fb Merge pull request #3777 from christopheraue/super_method_missing_test
Added basic test for calling a missing method through super
2017-08-11 22:35:40 +09:00
Christopher Aue 731dd78aa0 Added basic test for calling a missing method through super 2017-08-11 14:09:22 +02:00
Christopher Aue 58f5115b22 Refactored OP_SEND and OP_SUPER and calculate argc right at the top 2017-08-11 13:42:06 +02:00
Yukihiro "Matz" Matsumoto d077a5f0a6 scan_hex may be used to parse both unicode and hex escape.
The error checks for both usage should be separated; ref #3774
2017-08-11 14:25:02 +09:00
Yukihiro "Matz" Matsumoto 56d4e41d76 Fixed a wrong condition in scan_hex; fix #3774 2017-08-11 14:14:30 +09:00
Yukihiro "Matz" Matsumoto 96d4c2d385 Remove an unused argument from each_backtrace_func. 2017-08-11 13:52:24 +09:00
Yukihiro "Matz" Matsumoto 1d781da8a6 Should not include float.h here. 2017-08-11 13:52:01 +09:00
Yukihiro "Matz" Matsumoto db72cdae28 Merge branch 'christopheraue-super_method_missing_fix' 2017-08-11 13:16:40 +09:00
Yukihiro "Matz" Matsumoto ab39ed4f82 Defer mid update after unshift; ref #3776 2017-08-11 13:15:50 +09:00
Yukihiro "Matz" Matsumoto 9feb069124 Merge branch 'super_method_missing_fix' of https://github.com/christopheraue/mruby into christopheraue-super_method_missing_fix 2017-08-11 13:14:32 +09:00
Yukihiro "Matz" Matsumoto 0ff28c9e60 Silence integer type conversion warnings. 2017-08-11 13:10:31 +09:00
Yukihiro "Matz" Matsumoto ef0b239704 Remove unnecessary inline function ary_elt.
And the function does not conform the naming convention anyway.
2017-08-11 12:57:37 +09:00
Yukihiro "Matz" Matsumoto 67e2dddb82 Remove mrb_ary_len function. Use RARRAY_LEN instead. 2017-08-11 12:52:36 +09:00
Yukihiro "Matz" Matsumoto 8f6b2121d9 Update document comment of array C API functions. 2017-08-11 12:51:45 +09:00
Yukihiro "Matz" Matsumoto 4e2f4f4280 Avoid possible data loss by using ptrdiff_t. 2017-08-11 12:12:11 +09:00
Yukihiro "Matz" Matsumoto ae04005092 The type of ARY_EMBED_LEN should be mrb_int. 2017-08-11 12:09:37 +09:00
Yukihiro "Matz" Matsumoto 3e075a7b6c Should not call to_str in mrb_vformat; fix #3773 2017-08-11 09:21:47 +09:00
Yukihiro "Matz" Matsumoto 68470bef86 Check method existence in `to_enum'; ref #3773 2017-08-11 09:21:09 +09:00
Christopher Aue 2249551c63 Fixed calling missing method through super with 126 args 2017-08-10 23:26:39 +02:00
Yukihiro "Matz" Matsumoto ac42ccc1fc Merge pull request #3772 from vvakame/add2authors
Updated AUTHORS
2017-08-10 09:50:08 +09:00
vvakame a8658b0f2c Updated AUTHORS 2017-08-10 09:21:40 +09:00
Yukihiro "Matz" Matsumoto a7462a7f42 Remove redundant flo_hash function.
`flo_hash` implemented `15.2.8.3.18` but `Kernel#hash` (15.3.1.3.15)
now works for numbers.
2017-08-10 08:47:01 +09:00
Yukihiro "Matz" Matsumoto 3d288ef0d8 Use standard hash functions in mrb_hash_ht_hash_func. 2017-08-10 08:47:01 +09:00
Yukihiro "Matz" Matsumoto 78be0172f7 Normalize float numbers before calculating a hash value. 2017-08-10 08:36:09 +09:00
Yukihiro "Matz" Matsumoto 9826ca54f2 VM stack may be reallocated during mrb_hash_get; fix #3771 2017-08-10 08:21:43 +09:00
Yukihiro "Matz" Matsumoto 9e0c48ddc6 Merge pull request #3770 from christopheraue/tabs_to_spaces
Replaced tabs with spaces
2017-08-10 07:59:49 +09:00
Christopher Aue 2fadddcd20 Replaced tabs with spaces 2017-08-09 21:56:27 +02:00
Yukihiro "Matz" Matsumoto 24c345fe5c Merge branch 'vvakame-add-hash-compact' 2017-08-09 21:21:31 +09:00
Yukihiro "Matz" Matsumoto 6c61a60609 Implement Hash#compact! in C; ref #3769 2017-08-09 21:20:50 +09:00
vvakame 4d46f366ac add method(compact, compact!) and test of Hash to mruby-hash-ext 2017-08-09 19:18:02 +09:00
Yukihiro "Matz" Matsumoto f9c3ebd29d Wrong blkargs pos for vararg; ref #3768 2017-08-09 15:23:20 +09:00
Yukihiro "Matz" Matsumoto 0a61df1c34 The block argument offset saved in the env was wrong; fix #3768
When the method takes variable number of argument (`argc = -1`),
the block argument offset should be `-1` not `0`.
2017-08-09 12:57:55 +09:00
Yukihiro "Matz" Matsumoto 8f62957888 Support break within rescue clauses; fix #3767 ref #3721 2017-08-09 12:25:20 +09:00
Yukihiro "Matz" Matsumoto 66e2928bd4 Float values divided by zero should honor signs; fix #3766
It also fixes unexpected resurrection of #3745 by #3752
2017-08-08 02:13:11 +09:00
Yukihiro "Matz" Matsumoto 8494557006 Set the current pc as the error position in OP_ERR; ref #3765 2017-08-08 01:55:46 +09:00
Yukihiro "Matz" Matsumoto e910cf6169 Check if ptr is NULL before calling memset; fix #3765 2017-08-08 01:54:43 +09:00
Yukihiro "Matz" Matsumoto 1358725738 Merge pull request #3764 from christopheraue/new_hash_perf
Improved speed of creating new hash tables
2017-08-07 01:48:39 +09:00
Christopher Aue ec7475d88b Prevented resizing just created hashes in specific size ranges 2017-08-05 20:59:26 +02:00
Christopher Aue 0e5c3c4ebd Improved speed of creating new hash tables 2017-08-04 22:08:29 +02:00
Yukihiro "Matz" Matsumoto 1b9c4855a3 proc->body.irep may be NULL; fix #3761 2017-08-05 01:28:11 +09:00
Yukihiro "Matz" Matsumoto 006661394d Fixed heap buffer overflow in mrb_ary_unshift_m; fix #3760 2017-08-05 01:18:52 +09:00
Yukihiro "Matz" Matsumoto 36dbfd9bda Change return type of scan_oct from int to int32_t. 2017-08-05 01:06:36 +09:00
Yukihiro "Matz" Matsumoto e86c252a99 Left shift of signed integers is undefined behavior in C; fix #3762 2017-08-05 01:06:36 +09:00
Yukihiro "Matz" Matsumoto 8095754e28 Merge pull request #3763 from mimaki/fix-mrdb-source-path
Fixed a invalid source path name on mruby debugger.
2017-08-04 23:41:14 +09:00
Hiroshi Mimaki 7bdc709da0 Fixed a invalid source path name on mruby debugger. 2017-08-04 17:25:03 +09:00
Yukihiro "Matz" Matsumoto 7b88c1a8e5 Now local_variables works when for closures; fix #3710 2017-08-02 07:44:58 +09:00
Yukihiro "Matz" Matsumoto da24af34b9 Better class name management.
The change removes several internal instance variables used by
class name management. The variables `__classid__` and `__classpath__`
are no longer available. `__outer__` is used only for unnamed outer
classes/modules (and will be removed after they are named).

[Important note]
Along with this change we removed several public functions.

 - mrb_class_outer_module()
 - mrb_class_sym()

We believe no one have used those functions, but if you do, please
ask us for the workaround.
2017-08-01 22:25:49 +09:00
Yukihiro "Matz" Matsumoto 2170fad406 Cosmetic changes (removing spaces before * in return types). 2017-08-01 16:31:18 +09:00
Yukihiro "Matz" Matsumoto 648e9ea51b Move naming unnamed classes/modules
From `mrb_mod_const_set` to `mrb_const_set`.
2017-08-01 16:25:09 +09:00
Yukihiro "Matz" Matsumoto 3f6a098626 Reimplement constant look-up rule to follow lexical scoping.
This update fix CRuby scoping incompatibility; close #600; close #3200
2017-08-01 15:57:32 +09:00
Yukihiro "Matz" Matsumoto 9e10afe1d0 Implements `Module::nesting' (15.2.2.3.2); ref #600, #3200 2017-08-01 15:37:21 +09:00
Yukihiro "Matz" Matsumoto 16aafdd866 Merge pull request #3759 from christopheraue/authors_update
Updated AUTHORS
2017-07-31 07:27:04 +09:00
Yukihiro "Matz" Matsumoto facf5f99d4 Merge pull request #3758 from christopheraue/enumeration_perf
Improved speed of enumeration methods
2017-07-31 07:26:46 +09:00
Christopher Aue a4ff31eaf6 Updated AUTHORS 2017-07-30 16:19:24 +02:00
Christopher Aue 3359b86ec7 Improved speed of enumeration methods 2017-07-30 13:19:31 +02:00
Yukihiro "Matz" Matsumoto c8fdab8725 Merge branch 'udzura-move-task-class-definitions' 2017-07-29 07:15:10 +09:00
Yukihiro "Matz" Matsumoto e821c25d38 Merge branch 'move-task-class-definitions' of https://github.com/udzura/mruby into udzura-move-task-class-definitions 2017-07-29 07:09:53 +09:00
Yukihiro "Matz" Matsumoto b290e98f3b Merge pull request #3757 from christopheraue/module_const_get_class_path
Extended Module#const_get to support class paths
2017-07-29 07:05:37 +09:00
Yukihiro "Matz" Matsumoto cf23a85333 Merge pull request #3755 from christopheraue/array_bsearch_index
Added Array#bsearch_index
2017-07-29 07:01:53 +09:00
Yukihiro "Matz" Matsumoto dda73da640 Merge pull request #3756 from christopheraue/fix_mod_include_ret_val
Fixed return value of Module#include and #prepend
2017-07-29 06:53:06 +09:00
Christopher Aue a3bfd735a0 Added Array#bsearch_index 2017-07-28 23:51:49 +02:00
Christopher Aue 451574f142 Refactored Array#bsearch 2017-07-28 23:51:40 +02:00
Christopher Aue f937af5745 Extended Module#const_get to support class paths 2017-07-28 23:19:49 +02:00
Christopher Aue c7018ea962 Added mrb_str_index to the mrb API 2017-07-28 21:07:20 +02:00
Christopher Aue b499ad6749 Fixed return value of Module#include and #prepend 2017-07-28 17:38:40 +02:00
Christopher Aue 8a6ce74b4d Tested Array#bsearch more thoroughly 2017-07-28 17:15:35 +02:00
Yukihiro "Matz" Matsumoto 4696093673 Rename MRB_SEGMENT_SIZE to MRB_IV_SEGMENT_SIZE. 2017-07-27 16:14:03 +09:00
Yukihiro "Matz" Matsumoto 1e41026b28 Always use MRB_USE_IV_SEGLIST. 2017-07-27 16:14:03 +09:00
Yukihiro "Matz" Matsumoto f26d00d9e8 Embed small size array elements in the heap.
It reduces the memory consumption and sometimes improve the
performance as well.  For example, the consumed memory size
of `bench/bm_ao_render.rb` is reduced from 1.2GB to 1GB, and
its total execution time become 18.795 sec from 22.229 sec.
2017-07-27 16:13:06 +09:00
Yukihiro "Matz" Matsumoto 5d44f8582e Remove loop from OP_POPERR. 2017-07-27 10:30:43 +09:00
Yukihiro "Matz" Matsumoto 7d5cf8749a (0).div(0.0) should be NaN; fix #3754 2017-07-26 15:48:50 +09:00
Yukihiro "Matz" Matsumoto 46ab8fdf07 (0.0).div(0) should not be infinity; fix #3753 2017-07-25 15:28:41 +09:00
Yukihiro "Matz" Matsumoto 9fa3d77114 0/0 should not be infinity; fix #3752 2017-07-25 15:11:31 +09:00
Yukihiro "Matz" Matsumoto 7b8d784040 Reimplement sort method to reduce array copying. 2017-07-25 14:42:38 +09:00
Yukihiro "Matz" Matsumoto 7f9e333647 Should not update @objs from mruby-bin-mruby mrbgem.rake; fix #3751 2017-07-24 16:53:20 +09:00
Yukihiro "Matz" Matsumoto 308341b990 Clear mrb_callinfo struct by zero initializer. 2017-07-24 16:47:11 +09:00
Yukihiro "Matz" Matsumoto 1fc9a3019d Initialize potentially uninitialized local variable. 2017-07-24 16:46:27 +09:00
Yukihiro "Matz" Matsumoto 1c360965e7 Need to unshare env on OP_R_BREAK too. 2017-07-21 10:57:21 +09:00
Yukihiro "Matz" Matsumoto 5fee3f5869 Move NULL check to mrb_env_unshare(); ref #3750 2017-07-21 10:14:15 +09:00
Yukihiro "Matz" Matsumoto e2c9a30571 Should not raise LocalJumpError on funcall'ed frame; fix #3750 2017-07-21 07:17:21 +09:00
Yukihiro "Matz" Matsumoto 04c21d9d6b Merge pull request #3749 from christopheraue/fix_spec_rbfiles
Fixed setting custom rbfiles in gemspec
2017-07-20 23:14:34 +09:00
Yukihiro "Matz" Matsumoto 25a0a6b038 Need to patch OP_GETUPVAR and OP_SETUPVAR; fix #3732 2017-07-20 22:47:20 +09:00
Christopher Aue 5a9eedf541 Fixed setting custom rbfiles in gemspec 2017-07-19 19:46:36 +02:00
Yukihiro "Matz" Matsumoto aa3cb0466e Avoid C undefined behavior of division by zero; close #3745 2017-07-19 09:49:41 +09:00
Yukihiro "Matz" Matsumoto ca2cfc6fe9 Merge pull request #3746 from christopheraue/mod_singleton_class_p
Implemented Module#singleton_class?
2017-07-19 09:08:11 +09:00
Yukihiro "Matz" Matsumoto 645b0fb58c Merge branch 'christopheraue-const_set_mod_to_s' 2017-07-19 09:03:51 +09:00
Yukihiro "Matz" Matsumoto 14a72b0800 Avoid constant-set duplication; ref #3747 2017-07-19 09:03:07 +09:00
Yukihiro "Matz" Matsumoto a8bffdae50 Merge branch 'const_set_mod_to_s' of https://github.com/christopheraue/mruby into christopheraue-const_set_mod_to_s 2017-07-19 08:58:06 +09:00
Christopher Aue 468cc34c93 Fixed Module#to_s and #name for #const_set modules 2017-07-18 22:55:37 +02:00
Christopher Aue dd52b88101 implemented Module#singleton_class? 2017-07-18 20:47:05 +02:00
Yukihiro "Matz" Matsumoto 329938ef15 Simplify mrb_gc_arena_restore() to reduce overhead.
It will no longer shrink arena region. Instead `vm.c` uses
a static function `mrb_gc_arena_shrink()` to shrink.
2017-07-18 23:26:36 +09:00
Yukihiro "Matz" Matsumoto 52aafcd001 Merge pull request #3743 from christopheraue/sprintf_d_tests
added tests for #3736
2017-07-17 09:17:24 +09:00
Yukihiro "Matz" Matsumoto 59eaad9d78 Merge pull request #3742 from christopheraue/iter_exp_tests
added basic tests for while/until/break/next
2017-07-17 09:16:25 +09:00
Christopher Aue 2730231e50 added tests for #3736 2017-07-16 22:34:23 +02:00
Christopher Aue 8fe2a6ce0f added basic tests for while/until/break/next 2017-07-16 22:25:48 +02:00
Yukihiro "Matz" Matsumoto 515a093213 Add Hash#transform_keys! and Hash#transform_values. 2017-07-15 08:51:35 +09:00
Yukihiro "Matz" Matsumoto d7fef24a95 Use keys.each instead of unstable each_keys. 2017-07-15 08:50:52 +09:00
Yukihiro "Matz" Matsumoto 460d628490 Remove duplication in mruby-hash-ext test. 2017-07-14 16:10:26 +09:00
Yukihiro "Matz" Matsumoto 1c02b8558f Avoid duplicated width filling for sprintf %d specifier; fix #3736 2017-07-14 15:21:11 +09:00
Yukihiro "Matz" Matsumoto de3edcc170 Add Hash#transform_{keys,values} to mruby-hash-ext. 2017-07-14 15:13:41 +09:00
Yukihiro "Matz" Matsumoto bad807e7f0 Use floor() to implement round() on WIN32 platform.
This change was suggested by Akira Kakuto.
2017-07-13 20:32:34 +09:00
Yukihiro "Matz" Matsumoto 70e99d6b57 Define round() only on WIN32 platform; fix #3741 2017-07-13 00:09:31 +09:00
Yukihiro "Matz" Matsumoto 7fa9321c18 while|until should have the value from break; fix #3735 2017-07-12 14:56:48 +09:00
Yukihiro "Matz" Matsumoto e5fbe350b3 Avoid float operation to shrink arena buffer size. 2017-07-12 14:52:03 +09:00
Yukihiro "Matz" Matsumoto 9501b18362 Add inline modifier to cipush() and cipop() functions. 2017-07-12 14:50:44 +09:00
Yukihiro "Matz" Matsumoto a18904a4c2 Use "$!" specifier of mrb_get_args. 2017-07-12 14:49:55 +09:00
Yukihiro "Matz" Matsumoto e9b57124a0 Update mrb_get_args() document. 2017-07-12 14:49:06 +09:00
Yukihiro "Matz" Matsumoto adf453a584 Add "*!" argument specifier to avoid stack copying. 2017-07-12 14:48:23 +09:00
Yukihiro "Matz" Matsumoto 059d707e3a Add ary_modify_check() to Array#unshift; ref #3737 2017-07-12 14:44:36 +09:00
Yukihiro "Matz" Matsumoto e1de86134d Merge pull request #3740 from christopheraue/fix_test_output
fixed printing failed assertions
2017-07-12 08:24:02 +09:00
Christopher Aue 495a2e605d fixed printing failed assertions 2017-07-11 12:53:48 +02:00
Yukihiro "Matz" Matsumoto fc666bfe20 POSFIXABLE and NEGFIXABLE should take one argument. 2017-07-11 09:02:24 +09:00
Yukihiro "Matz" Matsumoto 46dee5716f Resurrect POSFIXABLE and NEGFIXABLE; ref 9186828 2017-07-10 09:42:48 +09:00
Yukihiro "Matz" Matsumoto 01fce3dc35 Merge pull request #3739 from ksss/array-shift
Should only check frozen fix #3737
2017-07-09 19:58:11 +09:00
ksss bf48473cf6 Should only check frozen for Array#pop 2017-07-09 18:05:21 +09:00
ksss c76dc33116 Add frozen test for Array#shift 2017-07-09 17:53:12 +09:00
ksss e581f2ed97 Should only check frozen fix #3737 2017-07-09 17:47:10 +09:00
Yukihiro "Matz" Matsumoto ce6c05600a Add fallback definitions of DBL_EPSILPN and LDBL_EPSILON; fix #3733
This is a workaround for mingw-w64 (5.3.1) bug.
2017-07-07 22:47:49 +09:00
Yukihiro "Matz" Matsumoto 718a9ceb6e Reduce allocation size of backtrace arrays. 2017-07-06 09:33:53 +09:00
Yukihiro "Matz" Matsumoto 542f0f7b16 Avoid out-of-bounds access of the backtrace array. 2017-07-06 09:32:28 +09:00
Yukihiro "Matz" Matsumoto 91868286be FIXABLE_FLOAT() fails sometimes in MRB_INT64 environment. 2017-07-06 09:05:46 +09:00
Yukihiro "Matz" Matsumoto cc04f03393 print("%d", 0) should not print -0; fix #3731 2017-07-05 23:31:50 +09:00
Yukihiro "Matz" Matsumoto 2ef5d22b60 Put a space between error position and error message.
For readability's sake.
2017-07-05 18:34:27 +09:00
Yukihiro "Matz" Matsumoto b68e7a605c Negation was not a good way to handle negative integers; fix #3729
There's a number that negation does not work (-2147483648 in 32bit
environment).
2017-07-05 18:13:37 +09:00
Yukihiro "Matz" Matsumoto b643a1a8bc In Ruby, sprintf specifier %u should behave as %d; fix #3730
Since there's no unsigned integer in Ruby. Binary, octal and
hexadecimal negative numbers can be represented by using 2's
compliment. But decimal (not being power of 2) cannot be use
that kind of format.
2017-07-05 17:48:40 +09:00
Yukihiro "Matz" Matsumoto bd66c5d716 Check stack size before accessing env stack; fix #3727 2017-07-05 09:19:06 +09:00
Yukihiro "Matz" Matsumoto cc01dedc65 Avoid undefined behavior of left shifting negative integer; #3728 2017-07-05 03:11:39 +09:00
Yukihiro "Matz" Matsumoto c377d504f6 Avoid undefined behavior of signed integer overflow; fix #3728 2017-07-05 03:11:39 +09:00
Yukihiro "Matz" Matsumoto c6bd8ceab7 Merge pull request #3726 from mruby/stable
mruby-1.3.0
2017-07-04 15:46:38 +09:00
Hiroshi Mimaki 277391e1b2 Set the mruby-1.3.0 release date to 2017-7-4. 2017-07-04 09:15:16 +09:00
Yukihiro "Matz" Matsumoto e9cdc88008 Refactor sprintf() code. 2017-07-04 08:50:39 +09:00
Yukihiro "Matz" Matsumoto 31bc2b0009 Initialize flags for each loop. 2017-07-04 08:46:33 +09:00
Hiroshi Mimaki ba1cd56ffa Fixed an unit test to work on Cygwin. 2017-07-03 16:01:01 +09:00
Yukihiro "Matz" Matsumoto 9b8956cdd0 break should not cross fiber-context boundary; fix #3724 2017-07-01 12:45:27 +09:00
Yukihiro "Matz" Matsumoto 7d99830211 super may be called from a block; fix #3723 2017-07-01 12:45:27 +09:00
Yukihiro "Matz" Matsumoto 466a18b0d3 Remove redundant use of Object#to_s in interpolation. 2017-06-28 23:28:24 +09:00
Yukihiro "Matz" Matsumoto aee1476ebd Provide better way to check compile errors.
Now you can just call `mrb_load_*` functions then check
`context->parser_nerr > 0` if the return value is `undef`,
instead of calling `mrb_parse_*` functions independently.
ref #3248 #3331
2017-06-28 16:04:40 +09:00
Yukihiro "Matz" Matsumoto 15945e14b9 Revert "Make mrb_load_exec a static function."
This reverts commit 7944d9a6d4.
Because it voids #3248 and #3331. But we should add better way
to check whether compile errors occur without duplicated callings.
2017-06-28 16:00:59 +09:00
Yukihiro "Matz" Matsumoto f0abd4241f Avoid mrb_funcall() unless absolutely necessary; ref #3722
As a result, `#chr` is not called for ch < 0x80, so we need to
update the "invalid chr" test.
2017-06-28 12:03:53 +09:00
Yukihiro "Matz" Matsumoto 3554a41a54 Remove unnecessary initialization of a local variable. 2017-06-27 22:48:06 +09:00
Yukihiro "Matz" Matsumoto 877e16501c No longer need to copy argv from mrb_get_args; ref #3722 2017-06-27 22:47:26 +09:00
Yukihiro "Matz" Matsumoto 1a3b32343e Copy argv from VM stack to avoid use-after-free; fix #3722 2017-06-27 22:43:37 +09:00
Yukihiro "Matz" Matsumoto b30eba6a13 Make LocalJumpError a subclass of ScriptError.
It's incompatible with CRuby, but it is required for mruby because
it cannot detect `break` outside of loops in the parsing time, but
in the code generation time where it cannot raise `SyntaxError`.
2017-06-23 18:08:38 +09:00
Yukihiro "Matz" Matsumoto d0717efda6 Should raise an exception if break called in ensure; fix #3721 2017-06-23 18:08:04 +09:00
Yukihiro "Matz" Matsumoto 7944d9a6d4 Make mrb_load_exec a static function. 2017-06-23 17:56:12 +09:00
Yukihiro "Matz" Matsumoto 9a59cd7af8 Silence mrbmemcpy and mrbmemset warnings. 2017-06-23 17:54:02 +09:00
Yukihiro "Matz" Matsumoto b200c7475a No need to mark stacks of terminated fibers; fix #3720 2017-06-22 02:05:14 +09:00
Yukihiro "Matz" Matsumoto c41e262667 Add write barrier to protect singleton class from GC; fix #3717 2017-06-22 01:20:22 +09:00
Yukihiro "Matz" Matsumoto af0bef6dd8 Silence rubocop warnings. 2017-06-22 00:27:17 +09:00
Yukihiro "Matz" Matsumoto e8a4e4262a Add write barrier to protect proc reference from fiber; fix #3719 2017-06-21 17:59:14 +09:00
Yukihiro "Matz" Matsumoto 464d3fc0a3 Use alias enum_for to_enum instead of alias :enum_for :to_enum. 2017-06-21 11:13:43 +09:00
Yukihiro "Matz" Matsumoto 057be5ffb5 use unless instead of if not. 2017-06-21 11:13:33 +09:00
Yukihiro "Matz" Matsumoto d0a7e01d9c Should call ecall() before callinfo adjustment; fix #3715 2017-06-21 02:51:55 +09:00
Yukihiro "Matz" Matsumoto bf1cb87b34 Array size can be cause integer overflow; fix #3710 2017-06-20 20:19:37 +09:00
Yukihiro "Matz" Matsumoto 39779b339e Merge pull request #3718 from miura1729/original
#3711 fix
2017-06-20 16:18:07 +09:00
Miura Hideki 0fa94f9ead #3711 fix 2017-06-20 12:50:00 +09:00
Yukihiro "Matz" Matsumoto 615e7e44e3 Avoid using snprintf(3) in case MRB_DISABLE_STDIO; fix #3714 2017-06-20 09:39:33 +09:00
Yukihiro "Matz" Matsumoto 455f3954dc Merge pull request #3713 from Asmod4n/patch-2
Save gc_arena after buffer got allocated
2017-06-20 09:16:38 +09:00
Asmod4n abca63c73b Save gc_arena after buffer got allocated
Latest fix was freeing the buffer while it was still in use.
Fixes #3712
2017-06-19 20:27:38 +02:00
Yukihiro "Matz" Matsumoto 0de7eec628 Fixed disclosure of local variables by eval; ref #3710
This patch fixes the latter part of #3710. We need to change
`struct REnv` to fix the former part of the issue.
2017-06-19 22:00:16 +09:00
Yukihiro "Matz" Matsumoto 4d3027b08e Increment the version number to 1.3.0. 2017-06-19 16:47:25 +09:00
Yukihiro "Matz" Matsumoto ea250d5f52 Increment RITE_BINARY_FORMAT_VER.
The behavior of `OP_RAISE` has been changed.
2017-06-19 09:23:03 +09:00
Yukihiro "Matz" Matsumoto 667e788159 Use mrb_int instead of int as argument to mrb_hash_new_capa. 2017-06-19 09:21:07 +09:00
Yukihiro "Matz" Matsumoto b0f918d1bd Use mrb_int instead of int. 2017-06-17 10:51:23 +09:00
Yukihiro "Matz" Matsumoto 4b55174fc5 Merge pull request #3706 from MasahikoSawada/fix_typo
Fix a typo in gc.c.
2017-06-17 08:40:57 +09:00
Yukihiro "Matz" Matsumoto 08c385ff66 Mark the GC arena in final_marking_phase.
Arena can be modified during the marking phase.
2017-06-17 08:39:43 +09:00
Yukihiro "Matz" Matsumoto 819ccd3b85 Mark the root context in final_marking_phase.
Because the root context cannot be marked from fibers.
2017-06-17 08:39:43 +09:00
Yukihiro "Matz" Matsumoto 8daabe7115 Mark global variables in final_marking_phase; fix #3704 2017-06-17 08:39:43 +09:00
Yukihiro "Matz" Matsumoto a985847224 Store operands to local variables.
Mostly for debugging purpose.
2017-06-17 08:39:43 +09:00
Yukihiro "Matz" Matsumoto 497a0a791e Correct comments in gc.c 2017-06-17 08:39:43 +09:00
Yukihiro "Matz" Matsumoto aa8121cf3a Use mrb_int instead of size_t for array capacity and length. 2017-06-17 08:39:43 +09:00
Masahiko Sawada 4f0900ef6e Fix a typo in gc.c. 2017-06-17 00:06:16 +09:00
Yukihiro "Matz" Matsumoto 0411cea2df Use MRB_PRId instead of d for mrb_int decimal specifier; ref #3701 2017-06-16 11:50:38 +09:00
Yukihiro "Matz" Matsumoto 6fdf2b035d Merge branch 'ksss-string-upto' 2017-06-16 11:48:32 +09:00
Yukihiro "Matz" Matsumoto e96f254ead Use mrb_str_new() instead of malloc(); ref #3701
Otherwise the function may terminate and cause memory leaks.
2017-06-16 11:46:40 +09:00
Yukihiro "Matz" Matsumoto 473b2bb20d Should not use sizeof(buf) when buf is char*; #3701 2017-06-16 11:42:51 +09:00
Yukihiro "Matz" Matsumoto a7770a39aa Merge branch 'string-upto' of https://github.com/ksss/mruby into ksss-string-upto 2017-06-16 11:35:42 +09:00
Yukihiro "Matz" Matsumoto d4d99dd6d7 Allow break from a block called by mrb_yield; close #3359
This means #3701 is now OK to merge.
2017-06-16 11:34:11 +09:00
Yukihiro "Matz" Matsumoto 9e6a3f6c95 Use MRB_THROW instead of mrb_exc_raise. 2017-06-16 11:22:17 +09:00
Yukihiro "Matz" Matsumoto 6a66ce10b3 Need to unshare env from top callinfo; fix #3685 2017-06-16 08:25:34 +09:00
Yukihiro "Matz" Matsumoto ebd6636a1e Call write barriers for stack-modified fibers; fix #3699 2017-06-15 23:20:36 +09:00
Yukihiro "Matz" Matsumoto d7e09ffa5f Print the file name along with line number on syntax errors; fix #3698 2017-06-15 15:46:03 +09:00
Yukihiro "Matz" Matsumoto 47bd44fce1 Prevent Fiber#initialize to be called twice; fix #3705 2017-06-15 15:16:56 +09:00
Yukihiro "Matz" Matsumoto b298e241c8 Protect the last exception object from GC in ecall; fix #3702 2017-06-15 14:57:18 +09:00
Yukihiro "Matz" Matsumoto 357e478e2c Mark the exception object in the final marking phase; ref #3702 2017-06-15 14:53:49 +09:00
Yukihiro "Matz" Matsumoto 52443c80e2 Save the register value in a local variable for ease of debugging. 2017-06-15 14:52:58 +09:00
Yukihiro "Matz" Matsumoto 988e2ced03 Ensure size of the stack before handling exceptions; fix #3693 2017-06-15 13:37:27 +09:00
Yukihiro "Matz" Matsumoto af6041f1d0 Ensure size of the stack in OP_CALL. 2017-06-15 13:36:36 +09:00
Yukihiro "Matz" Matsumoto bb1bfaa2fb Add helper functions to use gdb reverse-next.
On my machine, gdb reverse-next does not work with memcpy and memset.
Add naive implementation of those functions to override.
2017-06-15 13:32:15 +09:00
Tomoyuki Sahara 04774e5bf2 remove unused exception variables. 2017-06-15 11:00:26 +09:00
Tomoyuki Sahara 7c62d89348 Merge pull request #88 from christopheraue/master
Fix for IO#read(n) with n > IO::BUF_SIZE
2017-06-15 10:53:01 +09:00
ksss 4d9ca27ba6 Use malloc instead of dynamic allocation 2017-06-14 18:28:39 +09:00
ksss 432a813905 Fix arena overflow error 2017-06-14 18:12:56 +09:00
ksss 19785f43d1 Reimplement String#upto 2017-06-14 17:30:31 +09:00
Christopher Aue 3642fe4013 fixed #87: IO#read(n) with n > IO::BUF_SIZE 2017-06-13 21:40:36 +02:00
Yukihiro "Matz" Matsumoto b979226871 Clear stack in OP_CALL; fix #3694 2017-06-14 02:49:07 +09:00
Yukihiro "Matz" Matsumoto 7830b841c7 Fixed uninitialized local variable bug; ref #3692 2017-06-14 01:55:05 +09:00
Yukihiro "Matz" Matsumoto b32ad1307f The out-of-memory error should not be an instance of RuntimeError.
And arena-overflow error as well.  They should not be caught by
`rescue` by default.
2017-06-14 01:01:36 +09:00
Yukihiro "Matz" Matsumoto edb5b3672b Avoid out-of-bound access of VM stack in OP_SENDB; fix #3692 2017-06-14 00:46:21 +09:00
Tomoyuki Sahara 81a0dcdb7a sizeof(optval) must be 1 for IP_MULTICAST_TTL & IP_MULTICAST_LOOP. fixes #34. 2017-06-13 12:13:04 +09:00
Tomoyuki Sahara fe99819bc9 Merge pull request #85 from ksss/read
Support outbuf argument for IO#read
2017-06-12 16:17:53 +09:00
Tomoyuki Sahara c279f00109 Merge pull request #86 from ksss/write
Reseek when write
2017-06-12 16:15:31 +09:00
Tomoyuki Sahara 0b41066e83 Merge pull request #84 from ksss/pos
To accurate `pos`
2017-06-12 15:43:44 +09:00
ksss 051d7bc8db Reseek when write 2017-06-12 09:57:18 +09:00
ksss 1ebe1c8b1f Support outbuf argument for IO#read 2017-06-12 09:43:02 +09:00
ksss 27f422880f To accurate pos
pos shouldn't cache because it's not controllable
2017-06-11 23:22:04 +09:00
Yukihiro "Matz" Matsumoto b9f771dc50 Handles exceptions from code generation phase; fix #3695 2017-06-07 13:29:08 +09:00
Tomoyuki Sahara 3a73a58493 mruby 1.2.0 assumes test blocks return their results. master does not. 2017-06-07 11:36:37 +09:00
Tomoyuki Sahara 383a9c79e1 Merge pull request #13 from ksss/unpack-utf8
Support unpack template "U"
2017-06-07 11:09:43 +09:00
Tomoyuki Sahara dab87cf960 Merge pull request #80 from ksss/sysread
IO#sysread Check for readable
2017-06-05 16:21:30 +09:00
Yukihiro "Matz" Matsumoto fc7096f18a Limit recursion level of codegen(); fix #3690 2017-06-05 13:18:31 +09:00
Yukihiro "Matz" Matsumoto 788cea2b43 Revert "Simplify rescue stack management; ref #3683"
This reverts commit eb5a606fe2 and
079f310fbc.
The rescue stack works differently from ensure stack, so the change
caused #3686 and #3688. It might take long to solve the problems,
so that I would revert the changes for now. Fix #3688
2017-06-03 23:32:15 +09:00
Yukihiro "Matz" Matsumoto c9a4f8a63b Prohibit changing generational mode during GC disabled; fix #3689 2017-06-03 16:35:20 +09:00
Yukihiro "Matz" Matsumoto 935649b844 Check if a block is a lambda before marking it orphan; ref #3640 2017-06-03 13:48:09 +09:00
Yukihiro "Matz" Matsumoto c041206ad1 Add checks for break from proc-closure; fix #3640 2017-06-03 12:44:29 +09:00
Yukihiro "Matz" Matsumoto ab85d3c814 Make break in lambdas work as return according to CRuby behavior. 2017-06-02 14:22:18 +09:00
Yukihiro "Matz" Matsumoto 7f417ade42 Revert "Update NODE_BLOCK check logic in void_expr_error."
This reverts commit 31e30686b0.
2017-06-02 13:31:03 +09:00
Yukihiro "Matz" Matsumoto a8bf3742c6 Fixed a bug that make a loop in singleton_class clone; fix #3687 2017-06-02 13:25:15 +09:00
Yukihiro "Matz" Matsumoto 31e30686b0 Update NODE_BLOCK check logic in void_expr_error. 2017-06-02 13:01:29 +09:00
Yukihiro "Matz" Matsumoto 563036eaba Restore test/t/codegen.rb 2017-06-02 12:19:36 +09:00
Yukihiro "Matz" Matsumoto 0f2f021330 Fixed a bug in void_expr_error. 2017-06-02 12:06:40 +09:00
Yukihiro "Matz" Matsumoto b59d244c0d Add more precise void expression checks; ref #3686 2017-06-02 11:53:26 +09:00
Yukihiro "Matz" Matsumoto e0fbf25f90 Remove tests which can not be compiled on CRuby. 2017-06-02 11:51:59 +09:00
Yukihiro "Matz" Matsumoto 079f310fbc Adjust ridx if mrb_yield terminated by break; fix #3686
This issue is related to #3640.
2017-06-02 11:26:32 +09:00
Yukihiro "Matz" Matsumoto 51e0e690c2 Avoid invoking GC when disabled or iterating; fix #3681 2017-06-01 19:47:33 +09:00
Yukihiro "Matz" Matsumoto 87cc0344cd Call stack_clear() after stack_extend(); fix #3682 2017-06-01 19:35:15 +09:00
Yukihiro "Matz" Matsumoto eb5a606fe2 Simplify rescue stack management; ref #3683 2017-06-01 19:18:24 +09:00
Yukihiro "Matz" Matsumoto 7ff90b52d8 Simplify ensure stack management; fix #3683 2017-06-01 19:17:48 +09:00
Yukihiro "Matz" Matsumoto 72b635f7d2 Hide OP_EXEC lambda body from ObjectSpace#each_object; fix #3680 2017-06-01 15:40:07 +09:00
Yukihiro "Matz" Matsumoto 90fb4dd5b3 Print most recent call last as CPython does. 2017-06-01 09:48:04 +09:00
Yukihiro "Matz" Matsumoto a893877b0d Check for super using OP_ARGARY; fix #3678
It generates a wasted empty array for each `super` call though.
It should be fixed in the future, if possible.
2017-06-01 09:38:42 +09:00
Yukihiro "Matz" Matsumoto b0f2bc39db Clear VM stack in OP_EXEC; ref #3678 2017-06-01 08:45:56 +09:00
Yukihiro "Matz" Matsumoto eb69eebfd7 Simplify code since OP_EXEC never takes CFUNC Proc; #3678 2017-06-01 08:28:38 +09:00
Yukihiro "Matz" Matsumoto ff7df939ba Restore MRB_API function mrb_exc_backtrace(mrb, exc); ref 9644ad5 2017-05-31 23:15:17 +09:00
Yukihiro "Matz" Matsumoto 2837de95fe Prevent splicing big recursive arrrays; ref #3679
We know this is not perfect, but this change makes hack like #3679
bit harder. Harmless for useful cases.
2017-05-31 23:03:39 +09:00
Yukihiro "Matz" Matsumoto b4a4e3c09a Simplify the logic in mrb_realloc; ref #3679 2017-05-31 23:02:59 +09:00
Yukihiro "Matz" Matsumoto 7dbbd77407 Revert 4566c80; fix #3679
The patch deallocate the memory in `mrb_default_allocf` but that
hinders GC in `mrb_realloc`.
2017-05-31 23:01:04 +09:00
Yukihiro "Matz" Matsumoto 877f9d02e6 Avoid infinite loop on negative exponent; fix #3677 2017-05-31 09:53:19 +09:00
Yukihiro "Matz" Matsumoto acd3ac62a8 Reduce the size of VM stack clear window; ref #3676 2017-05-31 06:39:12 +09:00
Yukihiro "Matz" Matsumoto 2599c1932e Clear VM stack for top level; fix #3676
Top-level local variables contained junk after ab25eaea2
2017-05-31 00:18:32 +09:00
Yukihiro "Matz" Matsumoto ef1158485b Check env context before jump from OP_RETURN; fix #3673 2017-05-30 15:42:10 +09:00
Yukihiro "Matz" Matsumoto 27a5e10454 Avoid using C++ style comments (//). 2017-05-30 11:47:59 +09:00
Yukihiro "Matz" Matsumoto 4b15d5d1e3 Initialize String before Exception; fix #3672
The old order generated some strings with their class set to NULL.
2017-05-30 11:38:54 +09:00
Yukihiro "Matz" Matsumoto 650cfb9e4c Exceptions in fibers must be re-raised via #resume; fix #3675 2017-05-30 11:06:00 +09:00
Yukihiro "Matz" Matsumoto cbd4aae41c Mark the proc object representing top-level as an internal object; #3621 2017-05-29 14:13:17 +09:00
Yukihiro "Matz" Matsumoto abed375ea6 Mark proc objects representing methods as internal objects; fix #3621 2017-05-29 14:12:23 +09:00
Yukihiro "Matz" Matsumoto 02670ffa8d Protect the returning value in OP_RETURN; fix #3669
Even though the returning value is retrieved from the stack,
it may be freed if GC is caused during stack rewinding
(e.g. ensure calls).
2017-05-29 10:33:43 +09:00
Yukihiro "Matz" Matsumoto 9f634a6f8b Mark the current context (not root) in final marking. 2017-05-29 10:32:42 +09:00
Yukihiro "Matz" Matsumoto 8e390cccae Fixed rounding functions (round,ceil,floor,truncate) in MRB_INT64.
They didn't work well with inexact numbers (inf,nan). Fix #3671
2017-05-27 23:51:22 +09:00
Yukihiro "Matz" Matsumoto 34dd258c63 Unwind callinfo (mrb->c->ci) when a fiber termitates with error.
Fix #3668
2017-05-27 18:42:08 +09:00
Yukihiro "Matz" Matsumoto 57ffa1c150 Avoid unsharing env when context (mrb->c) differs; ref #3668 2017-05-27 18:40:15 +09:00
ksss a3a4f4d061 IO#sysread Check for readable 2017-05-27 13:34:11 +09:00
Yukihiro "Matz" Matsumoto 54b45f6a1b Use RData instead of String to represent backtrace. 2017-05-26 22:30:27 +09:00
Yukihiro "Matz" Matsumoto f269d1eb40 Distinguish OP_R_NORMAL and OP_R_RETURN. 2017-05-26 11:23:27 +09:00
Yukihiro "Matz" Matsumoto e3438f404a Invoke ensure clauses on Fiber termination; fix #3666
Related to #3662
2017-05-26 10:50:51 +09:00
Yukihiro "Matz" Matsumoto 83fc915213 Add new range check macro FIXABLE_FLOAT(); ref #3652
When MRB_INT64, valid value range of mrb_int is bigger than double,
which only has 53 bits significant precision.
2017-05-26 09:54:10 +09:00
Yukihiro "Matz" Matsumoto 3c31278236 Fix indentation in mrb_init_numeric() 2017-05-26 09:31:45 +09:00
Yukihiro "Matz" Matsumoto 535f13f3d7 fixup! Let Fixnum#{ceil,floor,round,truncate} to return itself; #3652 2017-05-26 09:29:39 +09:00
Yukihiro "Matz" Matsumoto c80696fcd3 Let Fixnum#{ceil,floor,round,truncate} to return itself; #3652 2017-05-26 09:25:16 +09:00
Yukihiro "Matz" Matsumoto 06c4933f90 Try our own ipow() if both base and exp are fixnums; fix #3652 2017-05-26 02:19:07 +09:00
Yukihiro "Matz" Matsumoto 9e40586d43 Add cast to mrb_int in mrb_fixnum() when MRB_WORD_BOXING.
Without this cast, `long int:63` can cause warnings.
2017-05-26 02:16:18 +09:00
Yukihiro "Matz" Matsumoto 7e4731655f Fixed off-by-one error in fiber_switch(); ref #3641 2017-05-26 01:24:28 +09:00
Yukihiro "Matz" Matsumoto f75f506181 Revert 01f7825; fix #3650
Redundant `mark_context() is far better than crashes.
2017-05-25 21:58:15 +09:00
Yukihiro "Matz" Matsumoto ac442bc1df Raise an exception when transfer arguments are too many; fix #3641
The fix was proposed by @block8437.  Thank you.
2017-05-25 21:39:13 +09:00
Yukihiro "Matz" Matsumoto de48d95c6d Avoid marking possibly freed stack; #3550 #3612 2017-05-25 19:58:06 +09:00
Yukihiro "Matz" Matsumoto c53747dbdf Revert "Use env preserved in Proc structure in ecall(); fix #3612"
This reverts commit e26e118604.
Fix #3664
2017-05-25 19:57:46 +09:00
Yukihiro "Matz" Matsumoto 517cd51cea Invoke ensure clauses before switching context from fibers; fix #3662 2017-05-25 14:36:25 +09:00
Yukihiro "Matz" Matsumoto ed16535c73 Clear top level env in mrb_top_run(); fix #3643 2017-05-25 14:13:54 +09:00
Yukihiro "Matz" Matsumoto f88cb88073 Avoid unsharing stack if env refers top-level; ref #3643 2017-05-25 14:13:16 +09:00
Yukihiro "Matz" Matsumoto e0931126ff Check env stack length before OP_SETUPVAR; ref #3643 2017-05-25 14:12:16 +09:00
Yukihiro "Matz" Matsumoto e969229b77 Check backtrace info may not be set (esp. NoMemError); fix #3663 2017-05-25 12:56:19 +09:00
Yukihiro "Matz" Matsumoto 5e1a6a2cc2 Make gen_assignment() to support NODE_SCALL; ref #3658 2017-05-25 12:40:49 +09:00
Yukihiro "Matz" Matsumoto 4566c80d7b Free given pointer if realloc() fails; fix #3658 2017-05-25 12:36:38 +09:00
Yukihiro "Matz" Matsumoto ff46957ef0 Avoid using mrb_raise() in mrb_vm_exec(); ref #3660 2017-05-25 11:11:40 +09:00
Yukihiro "Matz" Matsumoto 3ef97e3dd9 Under MRB_INT64, width may be bigger than INT_MAX; fix #3665 2017-05-25 10:40:35 +09:00
Yukihiro "Matz" Matsumoto 9bca887ac4 Preserve the current pc before method_missing(); fix #3660 2017-05-25 10:31:48 +09:00
Yukihiro "Matz" Matsumoto 9644ad51b4 Simplify backtrace mechanism; fix #3633 #3634 #3644
Instead of preserving a backtrace in `mrb_state`, `mrb_exc_set`
keeps packed backtrace in an exception object. `#backtrace` unpacks
it to an array of strings.
2017-05-23 23:50:42 +09:00
Yukihiro "Matz" Matsumoto d2458e66c2 Remove class info from backtrace lines. 2017-05-23 23:50:42 +09:00
Yukihiro "Matz" Matsumoto 497b19ce22 Support the case when the backtrace is not an array. 2017-05-23 23:50:42 +09:00
Yukihiro "Matz" Matsumoto a1ea2a670c Use index in each_object. 2017-05-23 23:50:42 +09:00
Yukihiro "Matz" Matsumoto 24a24a41dd Type check before print_backtrace() 2017-05-23 23:50:42 +09:00
Yukihiro "Matz" Matsumoto bb0b52a568 Update comments regarding Exception#to_str 2017-05-23 23:50:42 +09:00
Tomoyuki Sahara 0c0b34136e Merge pull request #78 from ksss/syswrite
Should raise SyscallError on IO#syswrite
2017-05-23 15:09:04 +09:00
Tomoyuki Sahara 87771ecf92 Merge pull request #79 from ksss/ioerror
Fix some spec for IO#sysread
2017-05-23 15:06:15 +09:00
ksss 0bbd60b523 IO#sysread should raise error when invalid pos 2017-05-22 11:47:45 +09:00
ksss 86edc9ab85 IO#sysread should raise IOError when closed 2017-05-21 22:54:46 +09:00
ksss 844b2c368f IO#sysread with 0 always return empty string 2017-05-21 22:54:12 +09:00
Yukihiro "Matz" Matsumoto 1bb6964db6 Merge pull request #3661 from ksss/string-concat
String#concat: Try to convert when not string
2017-05-21 22:53:01 +09:00
ksss c43795c664 Should raise SyscallError on IO#syswrite
instead of IOError
2017-05-21 17:10:15 +09:00
ksss 98f9c33fe0 String#concat: Try to convert when not string 2017-05-21 10:30:27 +09:00
Tomoyuki Sahara 6836f424c5 "open" error message should include pathname. fixes #77. 2017-05-19 17:14:43 +09:00
Yukihiro "Matz" Matsumoto 78add72812 Merge pull request #3659 from craiglrock/master
Avoid call to_s during backtrace traversal
2017-05-16 10:04:19 +09:00
Craig Lehmann 3de2da409b Avoid call to_s during backtrace traversal 2017-05-15 20:40:47 -04:00
Yukihiro "Matz" Matsumoto 82bc036a59 Merge pull request #3657 from ksss/str-embed
Make string embad from shared
2017-05-14 00:28:32 +09:00
ksss bdb36b3404 Make string embad from shared 2017-05-13 22:44:52 +09:00
Yukihiro "Matz" Matsumoto 171e732dc7 Merge pull request #3656 from clayton-shopify/fix-codegen-default
Change return back to break in the default case.
2017-05-13 09:37:34 +09:00
Clayton Smith bf30b8e8bf Change return back to break in the default case. 2017-05-12 14:43:12 -04:00
Yukihiro "Matz" Matsumoto 011e0bb0d9 Merge pull request #3649 from ksss/sprintf
Fix segmentation fault ref: #3648
2017-05-09 07:40:08 +09:00
ksss 30df7c8762 Fix segmentation fault ref: #3648 2017-05-08 23:18:14 +09:00
Yukihiro "Matz" Matsumoto ef305305b4 Merge pull request #3647 from ksss/split
Adjust to the optimum type
2017-05-05 21:34:59 +09:00
ksss 8cba9a9e42 Adjust to the optimum type 2017-05-05 14:20:21 +09:00
Yukihiro "Matz" Matsumoto 964a02f1fa Merge pull request #3645 from nobu/sprintf-refactor
Sprintf refactor
2017-04-29 13:10:34 +09:00
Nobuyoshi Nakada ef6e14ee2b Better error message
Raise argument error with the better message, at the only place
where the size to fill can be negative.
2017-04-29 10:17:24 +09:00
Nobuyoshi Nakada e05c30738e Use FILL and PUSH
Instead of loop or `memcpy` after `CHECK`, use dedicated macros,
`FILL` and `PUSH`, respectively.
2017-04-29 10:10:31 +09:00
Yukihiro "Matz" Matsumoto 3c10783769 Merge pull request #3639 from Asmod4n/patch-1
Add macOS support to mrb_ro_data_p
2017-04-26 07:49:14 +09:00
Asmod4n 9057a3f3be Add macOS support to mrb_ro_data_p
This adds macOS support to mrb_ro_data_p, fixes #3636
2017-04-25 20:34:07 +02:00
Yukihiro "Matz" Matsumoto cef523cc19 Avoid duplicated envadjust() of env stacks; fix #3637 2017-04-25 22:31:02 +09:00
Yukihiro "Matz" Matsumoto a3d80e8e73 Merge pull request #3637 from dabroz/fix-32-bit
Restore 32-bit OSX builds
2017-04-25 22:03:50 +09:00
Yukihiro "Matz" Matsumoto 3e07a2d77c Silence warnings caused by implicit type casting. 2017-04-25 21:00:16 +09:00
Yukihiro "Matz" Matsumoto 92dcfbaab3 Add explicit cast from double to long. 2017-04-25 17:43:03 +09:00
Yukihiro "Matz" Matsumoto b08dced2a6 Stop invoking GC before each_object to avoid test failure; #3616 2017-04-25 17:39:06 +09:00
Yukihiro "Matz" Matsumoto aa8e490fd5 Prevent GC during each_object; fix #3616 2017-04-25 17:25:48 +09:00
Tomoyuki Sahara 728d313b2c Merge pull request #76 from yyamano/issue-75
Make backquote work with the latest mruby. Fixed #75
2017-04-25 11:19:07 +09:00
Yukihiro "Matz" Matsumoto 88cd807379 Avoid use of snprintf() when DISABLE_STDIO is set; fix #3632
ref #3492 #3515 #3517
2017-04-25 10:41:50 +09:00
Yukihiro "Matz" Matsumoto 03cdb8e9dd Should terminate nested iterations in each_object; ref #3359 2017-04-25 10:41:50 +09:00
Yukihiro "Matz" Matsumoto 058da1fed2 Revert "Disable GC during gc_each_objects(); fix #3616"
This reverts commit d2cad9ac5b.
2017-04-25 10:41:50 +09:00
Yukihiro "Matz" Matsumoto 01f7825852 Use fiber marking instead of mark_context.
To avoid redundant `mark_context()`.
2017-04-25 10:41:50 +09:00
Tomasz Dąbrowski b1120464e0 Revert "Simplify pointer calculation in envadjust."
This reverts commit a1d32af916.
2017-04-24 23:57:39 +02:00
Yuji Yamano 311f4a230f Make backquote work with the latest mruby. Fixed #75 2017-04-24 02:40:01 -04:00
Yukihiro "Matz" Matsumoto 6088276cc8 Merge pull request #3630 from nobu/bug/sprintf-sp3inf
Fix space flag with inf/nan
2017-04-24 09:06:57 +09:00
Yukihiro "Matz" Matsumoto 72bdb6a93f Merge pull request #3631 from nobu/bug/embeddoc-terminator-word
Fix embedded document with unterminated terminator
2017-04-24 09:06:12 +09:00
Nobuyoshi Nakada d54f9f8f78 Fix embedded document with unterminated terminator
`skips()` is `mrb_bool` function, should return `FALSE` at EOF, not
`EOF`.
2017-04-23 11:41:00 +09:00
Nobuyoshi Nakada cd4e9a0518 Refactor "%f" % Inf/NaN
As for non-finite float, calculate the exact needed size with the
space flag.
2017-04-23 09:54:44 +09:00
Nobuyoshi Nakada 7314423bd1 Fix space flag when Inf/NaN and width==3
While `"% 2f"` and `"% 4f"` result in `" Inf"` and `" Inf"`
respectively, `"% 3f"` results in `"Inf"` (no space).
2017-04-23 09:54:20 +09:00
Yukihiro "Matz" Matsumoto 809b7ca3f4 Merge pull request #3628 from yyamano/libmruby-path
Add --libmruby-path support to mruby-bin-mruby-config.
2017-04-22 15:16:57 +09:00
Yukihiro "Matz" Matsumoto a4dfaaf1e8 Small cosmetic changes. 2017-04-22 15:09:41 +09:00
Yukihiro "Matz" Matsumoto e26e118604 Use env preserved in Proc structure in ecall(); fix #3612 2017-04-22 15:08:18 +09:00
Yukihiro "Matz" Matsumoto 5513fcee22 Keep reference to mrb_context from env; fix #3619 2017-04-22 14:35:36 +09:00
Yuji Yamano 52a03800d3 Add --libmruby-path support to mruby-bin-mruby-config. 2017-04-22 14:09:06 +09:00
Yukihiro "Matz" Matsumoto 3b0a36d399 Alias should push() extra stack space for blocks. 2017-04-22 12:03:56 +09:00
Yukihiro "Matz" Matsumoto a1d32af916 Simplify pointer calculation in envadjust. 2017-04-21 22:29:28 +09:00
Yukihiro "Matz" Matsumoto ad3b61f47b Revert e8dca6b03; fix #3550
Reopens #3612.
2017-04-21 22:29:28 +09:00
Yukihiro "Matz" Matsumoto 5d67d9b10d Fixed a possible memory leak. 2017-04-21 22:29:28 +09:00
Yukihiro "Matz" Matsumoto 15fba69710 Revert ae4217e81; fix #3619
Reopens #3550. Those 2 issues are exclusive.
2017-04-21 22:29:28 +09:00
Yukihiro "Matz" Matsumoto 95229ee164 Assign to local variable first; cosmetic change. 2017-04-21 22:29:28 +09:00
Yukihiro "Matz" Matsumoto c900fff9a1 Merge pull request #3623 from take-cheeze/struct_freeze
Support `freeze` method in `Struct`.
2017-04-21 22:28:32 +09:00
Yukihiro "Matz" Matsumoto c73da29aee Merge pull request #3624 from yyamano/fix-typo
Fix typo in usage message.
2017-04-21 22:27:52 +09:00
Yukihiro "Matz" Matsumoto 00770e2d3d Merge pull request #3625 from take-cheeze/pool_64bit
Align pool allocator with 8 byte in 64-bit environment.
2017-04-21 22:27:33 +09:00
Yukihiro "Matz" Matsumoto 02df2539df Merge pull request #3626 from take-cheeze/string_get_args_bug
Add missing `arg_i++` to fix bug of `s!` in mrb_get_args.
2017-04-21 22:27:07 +09:00
take_cheeze 3ce42a04e3 Add missing arg_i++ to fix bug of s! in mrb_get_args. 2017-04-21 17:52:29 +09:00
take_cheeze b2dc04393a Align pool allocator with 8 byte in 64-bit environment.
To avoid warnings from undefined sanitizer.
( https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html )
2017-04-21 17:34:31 +09:00
Yuji Yamano 33d09e4ad0 Fix typo in usage message. 2017-04-21 04:32:41 -04:00
take_cheeze da5b7fa769 Support freeze in Struct. 2017-04-21 17:23:54 +09:00
Yukihiro "Matz" Matsumoto 94bcdca64f VM stack may be reallocated in mrb_convert_type(); fix #3622 2017-04-21 09:11:28 +09:00
Yukihiro "Matz" Matsumoto 262fbaf566 mrb_int may overflow in bit-shifting; fix #3620 2017-04-21 08:55:19 +09:00
Yukihiro "Matz" Matsumoto 3567b26222 Bit-shifting zero should be zero; ref #3620 2017-04-21 08:36:29 +09:00
Yukihiro "Matz" Matsumoto d2cad9ac5b Disable GC during gc_each_objects(); fix #3616 2017-04-20 15:50:52 +09:00
Yukihiro "Matz" Matsumoto 62dae09bf6 Allow mrb_objspace_each_objects() to break iteration; ref #3359 2017-04-20 15:44:56 +09:00
Yukihiro "Matz" Matsumoto edd9fc6e75 Do not raise an exception for living closure; ref #3359 2017-04-20 13:14:01 +09:00
Yukihiro "Matz" Matsumoto 6a0b68f8b8 Use trampoline technique for instance_exec; ref #3359
A new function `mrb_yield_cont()` is provided. You have to call it
at the end of a C defined method, e.g. `return mrb_yield_cont()`.
2017-04-19 19:54:55 +09:00
Yukihiro "Matz" Matsumoto 77c2aa7b8a Need to raise "break from proc-closure" error; fix #3359 fix #3495
Some examples in #3359 still behave differently from CRuby.
2017-04-19 19:38:57 +09:00
Yukihiro "Matz" Matsumoto 283d145d3e Fixed a bug caused by last minute change; fix #3610
Omitted `goto L_RAISE` to raise an exception.
2017-04-19 09:28:58 +09:00
Yukihiro "Matz" Matsumoto fe3fe8fccc Merge pull request #3615 from clayton-shopify/fix-copy-class-null-pointer-deref
Check if sc->mt is initialized before copying it.
2017-04-19 07:07:03 +09:00
Clayton Smith de96994233 Check if sc->mt is initialized before copying it. 2017-04-18 11:18:58 -04:00
Yukihiro "Matz" Matsumoto 79e0314337 Call envadjust() before updating VM stack. 2017-04-18 16:49:43 +09:00
Yukihiro "Matz" Matsumoto ae4217e813 Fixed a wrong condition; fix #3550
Shared TT_ENV should be unshared. Reversed condition.
2017-04-18 16:49:14 +09:00
Yukihiro "Matz" Matsumoto e8dca6b034 Revert 6dd1a57; fix #3612; ref #3550
The fix was wrong. It causes a new problem #3612.
2017-04-18 16:48:50 +09:00
Yukihiro "Matz" Matsumoto a0143e148d Make mrb_codedump_all() to print type of Proc. 2017-04-18 12:40:36 +09:00
Yukihiro "Matz" Matsumoto f4119f518f Changed evaluation order of yield; ref #3613
So that `yield expr_with_error` will cause the error from the
argument rather than `LocalJumpError` when no block is given.
2017-04-18 12:00:52 +09:00
Yukihiro "Matz" Matsumoto f6c70bc6e8 super may call context switching method like send; fix #3611 2017-04-18 11:52:16 +09:00
Yukihiro "Matz" Matsumoto 05fceb5992 Call exc_debug_info() in mrb_exc_set(); ref #3610
Otherwise line number information is lacked from exceptions
raised in VM, e.g. "super called outside of method".
2017-04-18 10:28:49 +09:00
Yukihiro "Matz" Matsumoto 82ab46139e Add "no super" check to OP_ARGARY; fix #3610 2017-04-18 10:28:49 +09:00
Yukihiro "Matz" Matsumoto c3961847cf Hash#dup didn't check if internal khash is initialized; fix #3609 2017-04-18 09:55:32 +09:00
Yukihiro "Matz" Matsumoto 761493934e Mark whole root objects in final_marking_phase(); fix #3603
ref #1359 #1362
2017-04-17 16:06:18 +09:00
Yukihiro "Matz" Matsumoto 323121925a Merge pull request #3608 from clayton-shopify/fix-mirb-off-by-one
Fix an off-by-one causing a buffer overflow in mirb.
2017-04-14 07:07:52 +09:00
Clayton Smith 8e2279d1ff Fix an off-by-one causing a buffer overflow in mirb. 2017-04-13 10:51:26 -04:00
Yukihiro "Matz" Matsumoto 045e78c844 Proc#call needs to reserve at least 2 registers; fix #3606
One for the receiver, the other for the block.
2017-04-13 11:02:02 +09:00
Yukihiro "Matz" Matsumoto 17377af984 Struct may not be initialized in #to_h; fix #3607 2017-04-13 10:51:16 +09:00
Yukihiro "Matz" Matsumoto aec121f755 Update NODE_XSTR, NODE_DSXTR tests; ref #3605 2017-04-13 07:54:51 +09:00
Yukihiro "Matz" Matsumoto c0a4b1a0c6 Merge pull request #3604 from keizo042/fix_issue3598
Find Class/Module in nested singleton class; fix #3598
2017-04-13 00:42:26 +09:00
Yukihiro "Matz" Matsumoto 3123549bcb Fixed a bug in NODE_XSTR code generation; fix #3605 2017-04-13 00:38:47 +09:00
Kouichi Nakanishi d4205c9b20 Use while statement instead of for statement 2017-04-12 23:27:09 +09:00
Kouichi Nakanishi 4fca570a74 Find Class/Module in nested singleton class; fix #3598 2017-04-12 22:41:36 +09:00
Yukihiro "Matz" Matsumoto 4e84bdb507 Let 'mrb_vm_run()` to restore the calling fiber; ref #3537 2017-04-12 11:01:23 +09:00
Yukihiro "Matz" Matsumoto 0fb05eb55f Should not unshare env stack repeatedly; fix #3601 2017-04-12 10:41:06 +09:00
Yukihiro "Matz" Matsumoto 2a4db1a4be method_missing might have updated stack beyond boundary; fix #3599 2017-04-12 10:28:57 +09:00
Yukihiro "Matz" Matsumoto 326e043a64 Exceptions may be raised in yyparse(); fix #3600 2017-04-12 10:23:34 +09:00
Yukihiro "Matz" Matsumoto 918e7bb187 Refactor check before mrb_class_ptr(); ref #3602 2017-04-12 09:20:57 +09:00
Yukihiro "Matz" Matsumoto a25404c305 The attached object may not be a class; fix #3602 2017-04-12 09:18:44 +09:00
Yukihiro "Matz" Matsumoto 6dd1a570c2 Shared TT_ENV may need to be marked; fix #3550 2017-04-11 12:40:26 +09:00
Yukihiro "Matz" Matsumoto fff4a4ed34 OP_LAMBDA generation should honor VAL/NOVAL; fix #3580 2017-04-11 02:30:24 +09:00
Yukihiro "Matz" Matsumoto db47ae5de5 Fixed a bug in mrb_convert_to_integer(); fix #3581
Did not update the result from `mrb_check_string_type()` before
string-to-integer conversion.
2017-04-11 02:00:02 +09:00
Yukihiro "Matz" Matsumoto 03c849338f Fiber#yield should check C function boundary; fix #3582 2017-04-11 01:51:25 +09:00
Yukihiro "Matz" Matsumoto 9094415acf An object attached to a singleton class may not be a class; fix #3587
The fix for #3539 was incomplete.
2017-04-10 22:02:51 +09:00
Yukihiro "Matz" Matsumoto 0048dd118a Protect arguments from GC; fix #3597
GC may be called with OP_ENTER (especially when GC_STRESS is set).
2017-04-10 21:12:41 +09:00
Yukihiro "Matz" Matsumoto a55b237d89 Callinfo may be changed in ecall(); fix #3589 2017-04-10 20:39:49 +09:00
Yukihiro "Matz" Matsumoto ab25eaea23 Avoid clearing VM stack every time to gain performance.
VM stack is cleared by 5c114c9, 0cb501 and c063641.
2017-04-10 09:59:36 +09:00
Yukihiro "Matz" Matsumoto 5c114c91d4 Clear unused stack region that may refer freed objects; fix #3596 2017-04-10 09:46:09 +09:00
Yukihiro "Matz" Matsumoto 491d68bb30 Skip stack marking at all if c->stack is NULL. 2017-04-10 09:28:36 +09:00
Yukihiro "Matz" Matsumoto 0cb501545c Fill omitted arguments by nil for non-strict Proc. 2017-04-10 09:24:42 +09:00
Yukihiro "Matz" Matsumoto c063641ab0 Clear local (but non-argument) variables in OP_ENTER.
Otherwise, the following script prints an uninitialized value.

def f(*a)
  if false
    b = 15
  end
  p b
end
f(1,2,3)
2017-04-10 08:25:44 +09:00
Yukihiro "Matz" Matsumoto 47f181519f Avoid updating regs[] from function calls; ref #3588 2017-04-08 17:47:35 +09:00
Yukihiro "Matz" Matsumoto 1fd3cc9e1d Merge pull request #3595 from keizo042/name_stack_size
Attach a name to  embbeded value of rescue/ensure stack size
2017-04-08 17:47:20 +09:00
Kouichi Nakanishi 15b55c32e9 Attach a name to embbeded value of rescue/ensure stack size 2017-04-08 11:22:41 +09:00
Yukihiro "Matz" Matsumoto 7e28510725 Merge pull request #3594 from keizo042/fix_isssue_3575
Get constant of parent class even if child class is defined in signle…
2017-04-07 11:39:11 +09:00
Kouichi Nakanishi fd0f79ca67 Get constant of parent class even if child class is defined in signleton class; fix #3575 2017-04-06 23:31:34 +09:00
Tomoyuki Sahara 7e014efe45 Merge pull request #14 from ksss/to_int
Should use `to_int` instead of `to_i`
2017-04-06 10:25:06 +09:00
Yukihiro "Matz" Matsumoto e5b61d34f6 Fixed possible SEGV in Kernel#block_given?; ref #3593 2017-04-06 10:07:53 +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 a7b0ab3769 Save block argument position in e->cioff; fix #3593 2017-04-05 22:30:39 +09:00
Yukihiro "Matz" Matsumoto d9fb8b69b0 Fixed a bug in OP_SUPER block conversion; fix #3590 2017-04-05 18:22:26 +09:00
Yukihiro "Matz" Matsumoto bd7bf260e8 Should specify instance type of Structs; fix #3591 2017-04-05 17:52:26 +09:00
Yukihiro "Matz" Matsumoto 2daebfb6a7 Fixed a bug when method_missing take 126 args; fix #3592 2017-04-05 14:41:34 +09:00
Yukihiro "Matz" Matsumoto 60d20e1848 Should restore to the root fiber for each interaction; fix #3537 2017-04-05 13:53:43 +09:00
Yukihiro "Matz" Matsumoto 7f37c2fc57 Use stderr for debug prints in DEBUG(); fix #3584 2017-04-05 12:38:38 +09:00
Yukihiro "Matz" Matsumoto 74712c73ac Need to insert write barriers in struct updates; fix #3547 2017-04-05 11:53:20 +09:00
Uchio KONDO 38db5e550f Some adjustments 2017-04-04 12:16:53 +09:00
Uchio KONDO 9c2db2e134 Move class/module definitions to normal .rb files 2017-04-04 12:03:43 +09:00
Uchio KONDO 86b69d7c5d Initial skelton for class/module def 2017-04-04 11:57:17 +09:00
ksss d83e15e866 Should use to_int instead of to_i
For CRuby compatibility
2017-04-04 11:19:43 +09:00
Yukihiro "Matz" Matsumoto bdeb803f04 Merge pull request #3579 from clayton-shopify/fix-time-alloc-usec
Correctly handle large negative usec value.
2017-04-04 11:17:10 +09:00
ksss 0dbd1d5992 Add "U" template to doc 2017-04-04 11:07:15 +09:00
ksss f691a73c26 Should raise RangeError 2017-04-04 11:07:14 +09:00
ksss a80a745b69 Support unpack template "U" 2017-04-04 10:06:30 +09:00
Clayton Smith dc4fba28c5 Correctly handle large negative usec value. 2017-04-03 14:22:26 -04:00
Yukihiro "Matz" Matsumoto e2e2edae51 Merge pull request #3578 from bggd/appveyor_clone_depth
Change AppVeyor's clone_depth
2017-04-03 21:48:24 +09:00
bggd de114eb38d Change AppVeyor's clone_depth 2017-04-03 20:16:14 +09:00
Yukihiro "Matz" Matsumoto 12f6496ff8 Revert "Adjust VM stack window size; fix #3547"
This reverts commit 6dabb33635.
2017-04-03 19:49:42 +09:00
Yukihiro "Matz" Matsumoto 6dabb33635 Adjust VM stack window size; fix #3547 2017-04-03 19:12:13 +09:00
Yukihiro "Matz" Matsumoto ab63ee61ca Fixed out-of-bounds access of ensure[]; ref #3491 2017-04-03 18:47:38 +09:00
Yukihiro "Matz" Matsumoto b8461c8681 Protect ensure clause lambdas from GC; fix #3491 2017-04-03 18:38:49 +09:00
Yukihiro "Matz" Matsumoto 6a992a2579 Merge pull request #3577 from okkez/fix-return-value-of-each-slice
Change return value of Enumerable#each_slice
2017-04-03 18:04:57 +09:00
Yukihiro "Matz" Matsumoto fea8d00ef2 Merge pull request #3576 from okkez/fix-return-value-of-each-cons
Change return value of Enumberable#each_cons
2017-04-03 18:04:33 +09:00
Yukihiro "Matz" Matsumoto 0a1f15e57c Insert mrb_field_write_barrier() for GC; fix #3534 2017-04-03 18:01:43 +09:00
Yukihiro "Matz" Matsumoto 246db71139 Add struct REnv to union RVALUE; ref #3534 2017-04-03 18:01:17 +09:00
Yukihiro "Matz" Matsumoto 77331d127b Unify else clause style 2017-04-03 16:56:27 +09:00
Yukihiro "Matz" Matsumoto fbf4089d2f Remove spaces around parens 2017-04-03 16:49:18 +09:00
Kenji Okimoto cff54ab2f3 Change return value of Enumerable#each_slice
More compatibility to CRuby.
2017-04-03 16:46:47 +09:00
Kenji Okimoto 4975aa4c1c Change return value of Enumberable#each_cons
More compatibility to CRuby.
2017-04-03 16:42:53 +09:00
Yukihiro "Matz" Matsumoto 666787beb2 Adjust exit point in loop_pop(); fix #3541 2017-04-03 12:41:27 +09:00
Yukihiro "Matz" Matsumoto d35fcf1ea2 NODE_SPLAT to pass VAL/NOVAL; fix #3532 2017-04-03 12:02:39 +09:00
Yukihiro "Matz" Matsumoto f5632f2f12 Restrict recursion levels in method_missing(); fix #3556
Note this is a temporary fix. Error message generation
(including `inspect`) should be deferred until its use.
2017-04-03 10:50:31 +09:00
Yukihiro "Matz" Matsumoto d27a3d47cd String#initialize to make a string empty; ref #3574 2017-04-03 10:22:38 +09:00
Yukihiro "Matz" Matsumoto a14a930c80 Remove unnecessary indirection; ref #3557 2017-04-03 10:03:58 +09:00
Yukihiro "Matz" Matsumoto 8193c0b566 Check before generating special operators (e.g. OP_ADD); fix #3557 2017-04-03 10:01:44 +09:00
Yukihiro "Matz" Matsumoto a49c9f86e7 Update callinfo->target_class in mrb_exec_irep(); fix #3543 2017-04-03 00:05:16 +09:00
Yukihiro "Matz" Matsumoto 081535bf02 Merge pull request #3573 from ksss/parameters
Fix parameters when noname rest
2017-04-02 23:54:30 +09:00
ksss 7f983928b9 Reduce object allocation 2017-04-02 23:34:26 +09:00
ksss be5c304b4c Fix parameters when noname rest 2017-04-02 23:30:05 +09:00
Yukihiro "Matz" Matsumoto 5d00e85314 Fixed out of bounds access; fix #3572, ref #3553 2017-04-02 20:32:11 +09:00
Yukihiro "Matz" Matsumoto 5a445f012e Add alias "append" to Array#push, and "prepend" to Array#unshift.
According to CRuby [Feature#12746]
2017-04-01 21:27:23 +09:00
Yukihiro "Matz" Matsumoto 93d802987e Extend VM stack just in case; ref #3551 2017-04-01 21:21:57 +09:00
Yukihiro "Matz" Matsumoto 071164b799 Should not shrink VM stack; fix #3551 2017-04-01 18:54:37 +09:00
Yukihiro "Matz" Matsumoto 56322cd5dd Pacify signed warning; ref #3565 2017-04-01 18:41:55 +09:00
Yukihiro "Matz" Matsumoto dcbfe71625 NODE_ASGN arguments may be 127 (CALL_MAXARGS) accidentally; fix #3559 2017-04-01 14:11:15 +09:00
Yukihiro "Matz" Matsumoto e22f37a166 Argument order of __case_eqq was wrong; fix #3567 2017-04-01 13:42:44 +09:00
Yukihiro "Matz" Matsumoto 1e87dfdf48 The stack may be reallocated in the func call; fix #3560 2017-04-01 13:20:19 +09:00
Yukihiro "Matz" Matsumoto 8d9d7c929e Improve Time.new() performance using division; fix #3561 2017-04-01 13:03:34 +09:00
Yukihiro "Matz" Matsumoto 195af525fb Expand stack for method_missing; fix #3528 2017-04-01 12:42:11 +09:00
Yukihiro "Matz" Matsumoto 9eb2ed0879 Merge pull request #3571 from keizo042/fix_get_constant_of_module_from_sigleton
Modify to get constant of parent module in singleton class; fix #3568
2017-03-31 16:39:21 +09:00
Kouichi Nakanishi 507e00e86f Modify to get constant of parent module in singleton class; fix #3568 2017-03-31 13:43:20 +09:00
Yukihiro "Matz" Matsumoto 39ca4ef3bc Avoid crash if hv.n is greater than kh_size(h); fix #3565
The resulting behavior is different from CRuby, but modifying
hash key afterwards is undefined behavior in ISO spec.
2017-03-31 13:02:01 +09:00
Yukihiro "Matz" Matsumoto 952207d243 small cosmetic change; ref #3570 2017-03-30 17:10:44 +09:00
Yukihiro "Matz" Matsumoto 669b18383d Merge pull request #3570 from keizo042/fix_cv_definition_in_singleton
Modify class variable definition in singleton class; fix #3539
2017-03-30 17:09:43 +09:00
Kouichi Nakanishi 5efe77fede Modify class variable definition in singleton class; fix #3539 2017-03-30 16:29:47 +09:00
Yukihiro "Matz" Matsumoto 898077a2c2 Merge pull request #3566 from okkez/fix-enumerator-each-with-index
Fix Enumerator#each_with_index with block
2017-03-30 14:49:34 +09:00
Kenji Okimoto d93a5c1a84 Fix Enumerator#each_with_index with block
In previous version,

```
a = [3, 2, 1]
e = a.each
e.sort_by(&:to_i) # => []
```

In this version,

```
a = [3, 2, 1]
e = a.each
e.sort_by(&:to_i) # => [1, 2, 3]
```
2017-03-30 10:53:55 +09:00
Yukihiro "Matz" Matsumoto 905f46a129 Merge pull request #3558 from ksss/domain
Should raise FloatDomainError
2017-03-29 12:50:42 +09:00
ksss db3573e0bf Should raise FloatDomainError 2017-03-29 11:59:19 +09:00
Yukihiro "Matz" Matsumoto 1f6bf0e14f Merge pull request #3563 from clayton-shopify/dup-renumber-keys
Renumber hash keys during dup since there may be duplicates.
2017-03-29 09:43:33 +09:00
Yukihiro "Matz" Matsumoto 506c05f01d Merge pull request #3564 from okkez/set-proper-class-to-subclass-of-array
Set proper class to subclass of Array
2017-03-29 09:40:44 +09:00
okkez 6dbe2272cf Set proper class to subclass of Array
More compatibility to CRuby.
2017-03-29 08:02:21 +09:00
Clayton Smith a6e25f73a0 Renumber hash keys during dup since there may be duplicates. 2017-03-28 16:31:19 -04:00
Yukihiro "Matz" Matsumoto 5ec051fc34 Avoid inline local variable declarations; fix #3554 2017-03-28 18:22:05 +09:00
Yukihiro "Matz" Matsumoto 1bdaf9c840 Merge pull request #3553 from okkez/add-array-slice-bang
Implement Array#slice!
2017-03-28 15:24:52 +09:00
Kenji Okimoto 33f77fe367 Implement Array#slice! 2017-03-28 15:07:57 +09:00
Yukihiro "Matz" Matsumoto 0f5289326f Merge pull request #3552 from ksss/time
Fix infinity loop ref #3546
2017-03-28 14:47:23 +09:00
ksss 397f1fc946 Fix infinity loop
And some cases should raise FloatDomainError
2017-03-28 10:58:18 +09:00
Yukihiro "Matz" Matsumoto 66980493ae Merge pull request #3544 from ksss/lineno
Fix lost lineno
2017-03-27 11:50:18 +09:00
Yukihiro "Matz" Matsumoto f688de5803 Merge pull request #3545 from keizo042/ignore_tags
Ignore file generated by ctags
2017-03-27 11:49:37 +09:00
Kouichi Nakanishi d0e42eff00 Ignore file generated by ctags 2017-03-26 12:51:48 +09:00
ksss b1c5c3b0a5 Fix lost lineno 2017-03-25 15:56:27 +09:00
Yukihiro "Matz" Matsumoto 051e40c049 Use MRB_PRId for NODE_NTH_REF; ref #3530 2017-03-23 01:52:52 +09:00
Yukihiro "Matz" Matsumoto 9eb0c11afd Cast to mrb_int to silence a warning; fix #3530 2017-03-23 01:20:45 +09:00
Yukihiro "Matz" Matsumoto 41f5c5b2c7 Merge pull request #3529 from kou/hash-ext-sub-class
Hash sub class creates new sub class objects instead of Hash
2017-03-23 01:14:46 +09:00
Yukihiro "Matz" Matsumoto 8ca9823196 Merge pull request #3536 from ksss/string-sub
Fix result if pattern is empty
2017-03-23 00:49:06 +09:00
ksss 63c0044b11 Fix result if pattern is empty 2017-03-22 22:19:34 +09:00
Kouhei Sutou e72e50b5d5 Hash sub class creates new sub class objects instead of Hash 2017-03-21 23:25:36 +09:00
Yukihiro "Matz" Matsumoto 3703aed7ab Use snprintf() to stringify fixnum numbers; ref #3492 2017-03-20 11:47:15 +09:00
Yukihiro "Matz" Matsumoto 339c6aed64 Add explicit cast from float to mrb_int. 2017-03-20 02:54:21 +09:00
Yukihiro "Matz" Matsumoto 631de65e0c Merge pull request #3527 from ksss/string-gsub
Update String#gsub and String#gsub!
2017-03-20 02:23:11 +09:00
Yukihiro "Matz" Matsumoto dcf6a413ca Use snprintf() to stringify fixnum numbers; fix #3492 2017-03-20 01:39:33 +09:00
Yukihiro "Matz" Matsumoto cea6a16cf4 Fixed some compiler errors regarding PRId. 2017-03-19 23:42:49 +09:00
ksss 7a74a617ea Callback should yield with pattern every time 2017-03-19 23:04:22 +09:00
ksss 67a6982710 Support to return Enumerator for String#gsub,gsub! 2017-03-19 22:45:14 +09:00
Yukihiro "Matz" Matsumoto 09574922a9 Should not check/call to_str for immediate objects; ref #3515 2017-03-19 20:59:30 +09:00
Yukihiro "Matz" Matsumoto 527dcd5247 super class error formats the superclass by inspect; rerf #3515 2017-03-19 20:58:34 +09:00
Yukihiro "Matz" Matsumoto ef105b5ca4 Use MRB_PRId instead of "%d"; fix #3515 2017-03-19 20:43:25 +09:00
Yukihiro "Matz" Matsumoto 4cf38eb903 Fixed OP_RESCUE code generation bug; fix #3519
916b8e let code executed with mrb->exc set, and may cause a crash
like #3519. Instead modified OP_RESCUE again. To retrieve the exception
object, we use `OP_RESCUE R(A), 0, 0` (old behavior). To compare the
exception object and the class, we use `OP_RESCUE R(A), R(B), 1`.

The reason we use OP_RESCUE for two instruction switched by operand
C is to save the instruction space.

As a result, the following code:
```ruby
begin
  raise "a"
rescue TypeError
  p 1
rescue RuntimeError
  p 2
end
```
will be compiled as:
```
irep 0x55cd1f565cb0 nregs=4 nlocals=1 pools=1 syms=4 reps=0
file: -
    2 000 OP_ONERR	005
    2 001 OP_LOADSELF	R1
    2 002 OP_STRING	R2	L(0)	; "a"
    2 003 OP_SEND	R1	:raise	1
    2 004 OP_JMP	023
    2 005 OP_RESCUE	R1
    3 006 OP_GETCONST	R2	:TypeError
    3 007 OP_RESCUE	R1	R2	cont
    3 008 OP_JMPIF	R2	010
    3 009 OP_JMP	014
    4 010 OP_LOADSELF	R1
    4 011 OP_LOADI	R2	1
    4 012 OP_SEND	R1	:p	1
    4 013 OP_JMP	024
    5 014 OP_GETCONST	R2	:RuntimeError
    5 015 OP_RESCUE	R1	R2	cont
    5 016 OP_JMPIF	R2	018
    5 017 OP_JMP	022
    6 018 OP_LOADSELF	R1
    6 019 OP_LOADI	R2	2
    6 020 OP_SEND	R1	:p	1
    6 021 OP_JMP	024
    6 022 OP_RAISE	R1
    6 023 OP_POPERR	1
    6 024 OP_STOP
```
2017-03-19 18:42:53 +09:00
Yukihiro "Matz" Matsumoto d01118d261 OP_RESCUE refactored; ref #3519 2017-03-19 18:40:58 +09:00
Yukihiro "Matz" Matsumoto 8d1468eab4 Remove cname duplication from exc_inspect(). 2017-03-19 08:05:19 +09:00
Yukihiro "Matz" Matsumoto e6b5c75ec5 Avoid possible infinite recursion in mrb_print_error(); ref #3517 2017-03-19 07:20:44 +09:00
Yukihiro "Matz" Matsumoto 2cbbeba0e0 Check call depth when mrb_yield_class() is called; ref #3521 2017-03-19 00:28:52 +09:00
Yukihiro "Matz" Matsumoto 75c374cad3 Update stack only when callinfo is popped; fix #3521 2017-03-19 00:28:52 +09:00
Yukihiro "Matz" Matsumoto 6db38c3768 Need not to call mrb_obj_as_string() is sep is nil. 2017-03-19 00:28:52 +09:00
Yukihiro "Matz" Matsumoto ce8697523f Merge pull request #3526 from ksss/sprintf
sprintf: Should use mrb_int for any object
2017-03-18 23:30:35 +09:00
ksss 2005bf997f Should use mrb_int for any object
o=Object.new
def o.to_int
  1
end
p "%*d" % [o, 1]
2017-03-18 22:06:01 +09:00
Yukihiro "Matz" Matsumoto fa502b498e Need to setup singleton_class chain; fix #3509 2017-03-18 18:06:37 +09:00
Yukihiro "Matz" Matsumoto 38a3b89d39 Small cosmetic change ("* " -> "*"). 2017-03-18 17:38:07 +09:00
Yukihiro "Matz" Matsumoto 6ea26aafd5 Save/restore GC arena index to avoid arena overflow error. 2017-03-18 17:37:24 +09:00
Yukihiro "Matz" Matsumoto 00427d45f5 Fixed access of uninitialized C local variable; fix #3525 2017-03-18 17:34:29 +09:00
Yukihiro "Matz" Matsumoto b2916f1b5c Avoid mrb_check_string_type() in raising exception; fix #3506
The change may reduce flexibility, but I believe no one wants
that level of flexibility here.
2017-03-18 02:34:56 +09:00
Yukihiro "Matz" Matsumoto 27fc76f6c6 Merge pull request #3524 from ksss/timestamp
MiniRake::Task#timestamp should use Time.now only
2017-03-17 16:00:50 +09:00
Yukihiro "Matz" Matsumoto fca17b41c7 Avoid trampoline when #eval is called from mrb_funcall(); fix #3522 2017-03-17 15:55:18 +09:00
ksss f99e100187 MiniRake::Task#timestamp should use Time.now only 2017-03-17 12:41:06 +09:00
Yukihiro "Matz" Matsumoto 9ecebebf3e Merge pull request #3510 from ksss/string-each_line
Some update for `String#each_line`
2017-03-16 22:18:15 +09:00
Yukihiro "Matz" Matsumoto 47cc5d66e3 Singleton classes do not have outer class set; fix #3505 2017-03-16 22:13:58 +09:00
Yukihiro "Matz" Matsumoto b64f08784c Protect stack region before calling mrb_convert_type(); fix #3504 2017-03-16 21:40:22 +09:00
ksss 4ee79a8777 Support to return enumerator when no block given 2017-03-15 16:58:29 +09:00
ksss 673ce237c4 Suuport custom separator 2017-03-15 16:58:28 +09:00
ksss 6eb02a892d Use duplicated object for block args 2017-03-15 16:58:28 +09:00
Yukihiro "Matz" Matsumoto f8b31a0db6 instance_eval method does not introduce C function boundary; fix #3508 2017-03-15 09:00:03 +09:00
Yukihiro "Matz" Matsumoto 4b1e5d47b3 Merge pull request #3503 from nobu/bug/sprintf-oob
Fix out-of-bound access
2017-03-14 09:07:06 +09:00
Nobuyoshi Nakada d8c4fe7bcb Fix out-of-bound access
Get rid of out-of-bound access when single % at the end.
2017-03-13 23:56:33 +09:00
Yukihiro "Matz" Matsumoto 191ee2596c Need to copy argv since it may be reallocated; fix #3500
The argv for `mrb_yield_with_class()` should not be on mruby stack.
Note the result from `mrb_get_args("*")` is on the stack.
2017-03-13 22:51:53 +09:00
Yukihiro "Matz" Matsumoto 877f43bca5 OP_BLKPUSH is invalid outside of methods; fix #3501 2017-03-13 22:03:31 +09:00
Yukihiro "Matz" Matsumoto 916b8ed5c8 Generate new OP_RESCUE; fix #3487
The old OP_RESCUE took one operand A, which specifies a class
to match with the exception. The new OP_RESCUE takes tree operands:

A: the register to hold exception
B: the matching exception; the match result will be stored here.
C: the continuation; if C is zero, the exception will be stored to R(A)
   otherwise, the value from R(A) is used as a exception.

Thus,
```ruby
begin
  raise "a"
rescue TypeError
  p 1
rescue RuntimeError
  p 2
end
```
will be compiled as
```
irep 0x557a06667aa0 nregs=4 nlocals=1 pools=1 syms=4 reps=0
file: /tmp/e.rb
2 000 OP_ONERR  005
2 001 OP_LOADSELF R1
2 002 OP_STRING R2  L(0)  ; "a"
2 003 OP_SEND R1  :raise  1
2 004 OP_JMP  022
3 005 OP_GETCONST R2  :TypeError
3 006 OP_RESCUE R1  R2
3 007 OP_JMPIF  R2  009
3 008 OP_JMP  013
4 009 OP_LOADSELF R1
4 010 OP_LOADI  R2  1
4 011 OP_SEND R1  :p  1
4 012 OP_JMP  023
5 013 OP_GETCONST R2 :RuntimeError
5 014 OP_RESCUE R1 R2  cont
5 015 OP_JMPIF  R2  017
5 016 OP_JMP  021
6 017 OP_LOADSELF R1
6 018 OP_LOADI  R2  2
6 019 OP_SEND R1  :p  1
6 020 OP_JMP  023
6 021 OP_RAISE  R1
6 022 OP_POPERR 1
6 023 OP_STOP
```

The new VM can accept old OP_RESCUE. The mruby compatible VM (namely
mruby/c) should be updated to support the new OP_RESCUE behavior.
2017-03-12 01:10:20 +09:00
Yukihiro "Matz" Matsumoto 92f5becabe Update VM to support new OP_RESCUE behavior; ref #3487 2017-03-12 00:58:00 +09:00
Yukihiro "Matz" Matsumoto 26169f9e25 Enhance OP_RESCUE to take B operand fas matching exception; ref #3487 2017-03-12 00:50:38 +09:00
Yukihiro "Matz" Matsumoto 000c68da97 OP_RETRUN to take B as matching exception; ref #3487 2017-03-11 16:32:29 +09:00
Yukihiro "Matz" Matsumoto 4ab70294ea Revert 642ab8e; ref #3422
Also fix #3499.  The issue was solved by #3462.
2017-03-11 16:03:04 +09:00
Yukihiro "Matz" Matsumoto 94395e81c1 The width printf specifier may be negative; fix #3498 2017-03-11 15:22:54 +09:00
Yukihiro "Matz" Matsumoto f30ec2dfb0 fixup! Check return value from snprintf(); ref #3498 2017-03-11 15:22:42 +09:00
Yukihiro "Matz" Matsumoto e3922318bd Check return value from snprintf(); ref #3498 2017-03-11 15:18:41 +09:00
Yukihiro "Matz" Matsumoto f9ed15d899 Merge pull request #3496 from ksss/string-gsub
Avoid infinity loop when empty string pattern
2017-03-11 10:22:34 +09:00
Yukihiro "Matz" Matsumoto 7590482d48 Merge branch 'master' into string-gsub 2017-03-11 10:22:17 +09:00
Yukihiro "Matz" Matsumoto 431f474ba3 Merge pull request #3497 from ksss/subreplace
\1 sequences as empty strings
2017-03-11 10:19:59 +09:00
ksss b56ad8d122 \1 sequences as empty strings 2017-03-10 22:22:06 +09:00
ksss 4b3e6cf169 Avoid infinity loop when empty string pattern 2017-03-10 13:26:15 +09:00
Yukihiro "Matz" Matsumoto ff262f2133 Update ci->mid according to surrounding scope; fix #3490 2017-03-10 12:37:19 +09:00
Yukihiro "Matz" Matsumoto 2f299cf4dc Simplify expression; ref #3490 2017-03-10 12:36:58 +09:00
Yukihiro "Matz" Matsumoto e8f09f9393 Raise special Exception when exception class is redefined; fix #3493 2017-03-10 11:43:25 +09:00
Yukihiro "Matz" Matsumoto c6e5659fec Use string#upto() if available; fix #3489
Terminate loop if the value is longer than the last otherwise.
2017-03-10 10:39:43 +09:00
Yukihiro "Matz" Matsumoto 4763312fb8 Terminate loop if generated string longer than the last; ref #3489 2017-03-10 10:38:28 +09:00
Yukihiro "Matz" Matsumoto 63dbed0094 __FILE__ should not update p->filename; fix #3485 2017-03-07 15:01:09 +09:00
Yukihiro "Matz" Matsumoto 513f4fbf14 Merge pull request #3484 from ksss/string-frozen
Check modifiable for String `bang' methods
2017-03-06 07:38:56 +09:00
Yukihiro "Matz" Matsumoto 8a15abdac2 Avoid trampoline code if mrb_f_send is called from funcall; fix #3383 2017-03-06 07:35:41 +09:00
ksss eba4b1fd76 Check modifiable for String `bang' methods 2017-03-05 23:04:22 +09:00
Yukihiro "Matz" Matsumoto d050694580 Merge pull request #3483 from ksss/string-index
String#index shouldn't return nil when "".index ""
2017-03-05 20:27:28 +09:00
ksss 76e10351fa String#index shouldn't return nil when "".index "" 2017-03-05 14:15:18 +09:00
Yukihiro "Matz" Matsumoto 4f43db862a Unshare popped TT_ENV objects. 2017-03-04 22:45:44 +09:00
Yukihiro "Matz" Matsumoto 3b40a2f6b5 Limit ecall() recursion levels; fix #3466 2017-03-04 18:56:20 +09:00
Yukihiro "Matz" Matsumoto ecee8c51b0 Avoid tracing shared TT_ENV object. 2017-03-04 18:53:36 +09:00
Yukihiro "Matz" Matsumoto c789acbc36 Save/restore arena index in the loop. 2017-03-04 18:52:51 +09:00
Yukihiro "Matz" Matsumoto ffdf7be723 Define jmpbuf_id outside of extern "C"; ref #3470 2017-03-02 20:42:06 +09:00
Yukihiro "Matz" Matsumoto 2d858cab3d Use C++ ABI only when MRB_ENABLE_CXX_ABI is set; ref #3470 2017-03-02 20:37:21 +09:00
Yukihiro "Matz" Matsumoto 1ab7e7e4dc Fixed a bug in register size calculation; fix #3479 2017-03-02 18:14:36 +09:00
Yukihiro "Matz" Matsumoto 3390020fd0 The method_missing removal condition in a76dc04a was wrong. 2017-03-02 17:59:27 +09:00
Yukihiro "Matz" Matsumoto 27ec2437fd Fix possible stack overflow for method_missing; fix #3478
Instead of shifting mruby VM stack, we always use CALL_MAXARGS.
2017-03-02 17:55:15 +09:00
Yukihiro "Matz" Matsumoto 0bcf9e28fc Reorganize C++ exceptions; ref #3470
There are 3 levels of C++ exception handling:
* default - no C++ exception (use setjmp/longjmp)
* enable_cxx_exception (use C++ exceptions with C ABI)
* enable_cxx_abi (use C++ ABI including exceptions)
2017-03-02 10:58:26 +09:00
Yukihiro "Matz" Matsumoto fdd92750fe Create NoMethodError instance using mrb_obj_new(). 2017-03-02 10:56:23 +09:00
Yukihiro "Matz" Matsumoto 9b176a1ca8 Avoid using <mruby/throw.h> in mruby.c 2017-03-02 10:51:44 +09:00
Yukihiro "Matz" Matsumoto eca35df4ff ci may be moved during mrb_convert_type(); ref #3474 2017-03-01 12:06:18 +09:00
Yukihiro "Matz" Matsumoto 8b089c09f7 Keep space for safe navigation operator; fix #3475 2017-03-01 10:37:43 +09:00
Yukihiro "Matz" Matsumoto cd0ac59dd3 Newlines in strings should be counted; fix #3477 2017-03-01 00:05:54 +09:00
Yukihiro "Matz" Matsumoto 1a1f834ade Compile C files by C compiler when C++ files mixed.
ref #3267 #3470

By this commit, mruby do not use C++ ABI mode unless
you specify explicitly. It compiles C files by C
compilers, with C++ exception enabled when it sees
C++ files in your configured mrbgems.

I haven't tried visualcpp, so please submit an issue
if you see any problem with C++ gems on Windows.
2017-02-28 23:27:13 +09:00
Tomoyuki Sahara f8a3af8086 Merge pull request #74 from iij/run-test-outside-source-tree
run mrbtest outside of source tree.
2017-02-28 12:34:15 +09:00
Tomoyuki Sahara 3ae5fea2b8 run mrbtest outside of source tree. 2017-02-28 12:10:51 +09:00
Yukihiro "Matz" Matsumoto dc56bbecc8 Ignore empty ensure clause. 2017-02-28 11:51:17 +09:00
Yukihiro "Matz" Matsumoto fb3243e096 return (and break) should handle splat correctly; fix #3472 2017-02-28 11:34:54 +09:00
Yukihiro "Matz" Matsumoto 22eb41ab20 Fix NODE_DREGX dump; ref #3471 2017-02-28 10:56:34 +09:00
Yukihiro "Matz" Matsumoto c52bbe1b4e Fixed a bug in dregex option generation; fix #3471 2017-02-28 10:43:22 +09:00
Yukihiro "Matz" Matsumoto 89eac4f59d Update codegen.c comments 2017-02-28 10:32:40 +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
Yukihiro "Matz" Matsumoto a76dc04aa8 Remove default Kernel#method_missing.
Internal method_missing works without problems.
2017-02-27 23:11:39 +09:00
Yukihiro "Matz" Matsumoto b563bcb7ff Check if OP_RETURN cross C function boundary; fix #3462 2017-02-27 20:13:01 +09:00
Yukihiro "Matz" Matsumoto 50bbdbb11b Fixed ecall() invoked too early; fix #3464 2017-02-27 18:40:35 +09:00
Yukihiro "Matz" Matsumoto 3fc9bf3d5f Update local variable only after the value is checked. 2017-02-27 18:39:42 +09:00
Yukihiro "Matz" Matsumoto d219e63a74 Clear block arg when method_missing takes *args. 2017-02-27 18:38:56 +09:00
Yukihiro "Matz" Matsumoto 9e93d5dbf0 Stack may be reallocated in mrb_run(); fix #3465 2017-02-27 16:17:57 +09:00
Yukihiro "Matz" Matsumoto 736be0e98b Always keep block argument space in stack; fix #3469 2017-02-27 13:05:26 +09:00
Yukihiro "Matz" Matsumoto 83a6c0e0a4 Merge pull request #3458 from dabroz/gitlab-ci
GitLab.com tests for multiple configurations
2017-02-27 08:59:33 +09:00
Yukihiro "Matz" Matsumoto fecbde328a Merge pull request #3461 from iij/build-with-byacc
Build with byacc
2017-02-24 18:39:20 +09:00
Tomoyuki Sahara da4f8e19fa replace "yylval" with "pylval" to make it compile with byacc. 2017-02-24 11:47:48 +09:00
Tomoyuki Sahara 74fe87c289 Add a travis-ci badge. 2017-02-17 10:33:11 +09:00
Yukihiro "Matz" Matsumoto a9f7b41219 Merge pull request #3460 from AltimitSystems/android.rake-ndk-clang
Additional options for Android build script.
2017-02-17 01:13:37 +09:00
Felix Jones fd08e0ea3a Added example build script for Android armeabi-v7a NEON hardware FPU 2017-02-16 15:07:18 +00:00
Felix Jones 324231a733 Android toolchain separated target architecture compile flags (ctarget) from shared compile flags (cflags). Added support for custom mfpu and float-abi switches for the armeabi-v7a target. 2017-02-16 15:02:10 +00:00
Yukihiro "Matz" Matsumoto 73e5a19c39 Configure callinfo target_class as CRuby; ref #3429 2017-02-16 23:43:02 +09:00
Yukihiro "Matz" Matsumoto 4dae285325 Merge pull request #3457 from dabroz/fix-clang-32-64
Build fix for 32-bit clang 3.8/3.9 with MRB_INT64
2017-02-16 23:21:58 +09:00
Yukihiro "Matz" Matsumoto 097da2399a Avoid executing OP_STOP in eval(); fix #3429 2017-02-16 22:40:31 +09:00
Yukihiro "Matz" Matsumoto 5e3c329c98 Adjust callinfo env and target_class; ref #3429 2017-02-16 22:38:47 +09:00
Felix Jones d83aad8d57 Merge branch 'master' into android.rake-ndk-clang 2017-02-16 13:33:46 +00:00
Tomasz Dabrowski bc721ec45d Gitlab tests for multiple configurations
Gitlab testing is introduced, using GitLab CI, to test many different configurations:
 - 32/64 bit architecture
 - float/double
 - 16/32/64 bit int size
 - none/NaN/word boxing
 - ASCII/UTF8

using various compilers:
 - gcc-4.7
 - gcc-4.8
 - gcc-4.9
 - gcc-5
 - gcc-6
 - clang-3.5
 - clang-3.6
 - clang-3.7
 - clang-3.8
 - clang-3.9
2017-02-16 13:50:27 +01:00
Tomasz Dabrowski bd2b76ea85 Build fix for 32-bit clang 3.8/3.9 with MRB_INT64 2017-02-16 13:39:21 +01:00
Yukihiro "Matz" Matsumoto b165708c8d Move #instance_exec to Kernel module
CRuby defines #instance_exec in BasicObject, but we don't.
It's a small incompatibility that isn't worth accomplish at
the price of implementation complexity.
2017-02-15 13:24:03 +09:00
Yukihiro "Matz" Matsumoto 517e9313bf Move #__id__ to BasicObject; ref #3417 2017-02-15 13:19:21 +09:00
Yukihiro "Matz" Matsumoto 612d636b77 Move #instance_eval to BasicObject; ref #3417 2017-02-15 13:15:58 +09:00
Yukihiro "Matz" Matsumoto 3dbda91788 Move #__send__ to BasicObject; ref #3417 2017-02-15 13:12:05 +09:00
Yukihiro "Matz" Matsumoto 8b4bd3158b Move #== and #!= to BasicObject; ref #3417 2017-02-15 13:07:53 +09:00
Yukihiro "Matz" Matsumoto 3f9450e7b0 Move BasicObject#method_missing to Kernel#method_missing; ref #3417
More compatibility to CRuby.
Updated tests that assume old mruby behavior.
2017-02-15 12:56:27 +09:00
Yukihiro "Matz" Matsumoto 1e5b5b14d7 Prohibit too deep mrb_funcall() recursion; ref #3421
`mrb_funcall()` recursion can cause stack overflow easily,
so recursion depth is now limited to MRB_FUNCALL_DEPTH_MAX,
which default value is 512.
2017-02-15 12:06:32 +09:00
Yukihiro "Matz" Matsumoto 1e57fefbcf Do not funcall() Exception#set_backtrace from runtime.
This change reduce flexibility but makes mruby simpler and faster.
2017-02-15 12:01:52 +09:00
Yukihiro "Matz" Matsumoto 8efa7b00df Preallocate SystemStackError; ref #3421 2017-02-15 11:59:47 +09:00
Yukihiro "Matz" Matsumoto 0376d4d4c6 Merge pull request #3455 from crimsonwoods/fix-android-build-script
Update android build script.
2017-02-15 10:30:27 +09:00
Yukihiro "Matz" Matsumoto dd24f9f5cc Avoid calling hook methods if they are not overridden. 2017-02-15 09:25:09 +09:00
Yukihiro "Matz" Matsumoto 04296925ac Use mrb_funcall_argv() instead of mrb_funcall() 2017-02-15 09:24:35 +09:00
crimsonwoods 5395dbfb3a Add new two build config files. 2017-02-15 09:01:55 +09:00
crimsonwoods a6b1e964a3 Modify default cflags. 2017-02-15 03:03:47 +09:00
crimsonwoods 838fa69aa3 Add '-Wl,--fix-cortex-a8' linker option for 'armeabi-v7a' architecture. 2017-02-15 00:51:10 +09:00
crimsonwoods 83a3da4456 Set default linker 'flags' and 'flags_before_libraries'. 2017-02-15 00:36:02 +09:00
Yukihiro "Matz" Matsumoto ba812d25ad Merge pull request #3453 from palkan/fix/test-gems-setup
Separate compilers setup from config setup
2017-02-14 09:09:34 +09:00
palkan 131566753d Separate compilers setup from config setup
Fixes #3418.
2017-02-13 20:59:07 +03:00
Yukihiro "Matz" Matsumoto 30aa521854 Do not use mrb_funcall() if Hash#default is not overridden; ref #3421
This change reduces the recursion level, but does not solve the stack
overflow issue entirely.
2017-02-14 00:22:12 +09:00
Yukihiro "Matz" Matsumoto 719f700adf Extend mruby stack when keep is bigger than room; fix #3421
But #3421 still cause stack overflow error due to infinite recursion.
To prevent overflow, we need to add different stack depth check.
2017-02-14 00:15:58 +09:00
Yukihiro "Matz" Matsumoto ecb6ac8b4a Fixed codegen error of redo in rescue; fix #3422
The issue (and the fix) was reported by https://hackerone.com/dgaletic
2017-02-13 19:31:06 +09:00
Yukihiro "Matz" Matsumoto c2ddcd4517 Should handle break from funcall(); fix #3434
This issue was reported by https://hackerone.com/d4nny
2017-02-13 18:45:20 +09:00
Yukihiro "Matz" Matsumoto f198530444 Fixed too much value_copy() when block is not given; fix #3440
The issue was reported by https://hackerone.com/titanous
2017-02-13 18:18:09 +09:00
Yukihiro "Matz" Matsumoto b23874777d Merge pull request #3452 from dabroz/fix-kernel-caller-aspec
Fixed aspec for Kernel#caller
2017-02-12 20:46:10 +09:00
Tomasz Dabrowski e4fa59f5ed Fixed aspec for Kernel#caller 2017-02-12 11:15:40 +01:00
Yukihiro "Matz" Matsumoto 60664823ba Merge pull request #3451 from dabroz/revert-string-mul
Revert "Optimization for String#* for 1-byte strings"
2017-02-11 22:49:20 +09:00
Yukihiro "Matz" Matsumoto 1f2d786e32 Avoid direct return from ecall(); fix #3441
There's incompatibility left for mruby.

When you return from `ensure` clause, mruby simply ignores the return
value.  CRuby returns from the method squashing the exception raised.

```
def f
  no_such_method() # NoMethodError
ensure
  return 22
end

p f() # CRuby prints `22`
```
2017-02-11 21:58:47 +09:00
Tomasz Dabrowski 90f262f642 Revert "Optimization for String#* for 1-byte strings"
This reverts commit d1bc7caeca.
2017-02-11 13:02:48 +01:00
Yukihiro "Matz" Matsumoto ff03a9a61c Avoid integer overflow in sprintf(); fix #3439
This issue was reported by https://hackerone.com/aerodudrizzt
2017-02-11 20:35:52 +09:00
Yukihiro "Matz" Matsumoto 642ab8ecda ecall() should preserve stack address referenced from ci[1].
OP_RETURN accesses ci[1]->stackent that might be broken; fix #3442
2017-02-11 18:13:39 +09:00
Yukihiro "Matz" Matsumoto 0b143898c4 Remove historical comment; ref #3450 #3448 2017-02-11 16:52:45 +09:00
Yukihiro "Matz" Matsumoto 0ef51d83c2 Merge pull request #3450 from r-obert/patch-1
remove skip that shouldn't be necessary anymore.
2017-02-11 16:50:06 +09:00
robert b130f43298 remove skip that shouldn't be necessary anymore.
the test should pass after https://github.com/mruby/mruby/commit/8f4a929e1a01c8d6176fb53a9ef5dff6de632959.
2017-02-11 07:40:55 +00:00
Yukihiro "Matz" Matsumoto 8f4a929e1a String#replace should update s->flags for MRB_STR_NO_UTF.
Otherwise String#size may return wrong length; fix #3448
2017-02-11 16:27:07 +09:00
Yukihiro "Matz" Matsumoto 6cb7aef563 Add type cast to pacify warning 2017-02-11 16:00:26 +09:00
Yukihiro "Matz" Matsumoto b36495bcb5 Merge pull request #3449 from dabroz/fix-ljust-ruby
String#ljust and String#rjust reimplemented with optimized Ruby
2017-02-11 10:26:09 +09:00
Tomasz Dabrowski d1bc7caeca Optimization for String#* for 1-byte strings 2017-02-10 15:31:33 +01:00
Tomasz Dabrowski ac9d04f4af String#ljust and String#rjust reimplemented with optimized Ruby 2017-02-10 15:31:33 +01:00
Tomasz Dabrowski 24048cd998 Tests for UTF-8 String#ljust and String#rjust 2017-02-10 15:16:49 +01:00
Yukihiro "Matz" Matsumoto c802cd07ba Merge pull request #3446 from ksss/minirake
Fix build error when trace mode
2017-02-10 21:22:00 +09:00
Yukihiro "Matz" Matsumoto 0dc26f52a0 Merge pull request #3447 from dabroz/fix-ljust
String#ljust and String#rjust reimplementation (fix #3445)
2017-02-10 21:20:26 +09:00
Tomasz Dabrowski 981105b3e6 String#ljust and String#rjust reimplementation (fix #3445)
- String#ljust and String#rjust are now C functions to improve performance
 - infinite loop because of an empty padding argument is now prevented (ArgumentError is raised)
 - extra tests for ljust/rjust added
2017-02-10 12:59:28 +01:00
ksss cd8284fe0b Fix build error when trace mode
Rakefile

```
file "a.txt" do
  system "echo hello > a.txt"
end

file "b.txt" => "a.txt" do
  system "cp a.txt b.txt"
end

task :default => "b.txt"
```

```
$ touch b.txt
$ ruby minirake --trace
Invoke default (already=[], needed=[true])
rake aborted!
No such file or directory @ rb_file_s_stat - a.txt
minirake:241:in `stat'
minirake:241:in `timestamp'
minirake:233:in `block in needed?'
minirake:233:in `collect'
minirake:233:in `needed?'
minirake:91:in `invoke'
minirake:95:in `block in invoke'
minirake:95:in `each'
minirake:95:in `invoke'
minirake:467:in `block in run'
minirake:466:in `each'
minirake:466:in `run'
minirake:484:in `<main>'
```
2017-02-10 13:15:49 +09:00
Tomoyuki Sahara 86d58a2d37 File class does not have to include Enumerable.
Because IO class, which is the superclass of File class, includes it.
2017-02-10 11:22:52 +09:00
Tomoyuki Sahara 88a7fedea4 support "x". 2017-02-09 11:07:55 +09:00
Yukihiro "Matz" Matsumoto d0ecf862d9 Fixed mixture of signed/unsigned integers
in mrbgems/mruby-bin-debugger.
2017-02-08 23:27:17 +09:00
Yukihiro "Matz" Matsumoto 4b32e651a5 Check if irep is NULL before print_backtrace()
According to the valgrind log attached to #3438, proc->body.irep
may be NULL in some cases.
2017-02-08 23:10:25 +09:00
Yukihiro "Matz" Matsumoto af4d74fc7d Add MRB_TT_PROC check to OP_SUPER as well; fix #3432 2017-02-08 21:13:22 +09:00
Tomoyuki Sahara 3dad125a1c TCPSocket.new supports "local_host" and "local_service". 2017-02-08 19:04:11 +09:00
Yukihiro "Matz" Matsumoto 76135e757f Check if m->env is NULL before dereferencing it; fix #3436 2017-02-08 19:01:09 +09:00
Tomoyuki Sahara caab1c203c define IO#hash to override Enumerable#hash. fixes #73.
Current implementation of Enumerable#hash calls #each to collect
hash values of enumerated objects (then calculates the hash value
of the Enumerable object).  But IO#each is a method to read lines.
It is not expected that IO#hash reads all lines from the IO object.
Or even worse, program waits for the IO object to be readable if
it is a socket or something cannot be read immediately.
2017-02-08 18:31:50 +09:00
Yukihiro "Matz" Matsumoto b277c58e78 Mark classes referenced from saved backtrace.
Maybe related to #3438
2017-02-08 16:31:37 +09:00
Yukihiro "Matz" Matsumoto f3d4ff16d3 Fixed a bug in ci address shifting; fix #3423
Dinko Galetic and Denis Kasak reported the issue and the fix.
(via https://hackerone.com/dgaletic).
2017-02-08 16:22:48 +09:00
Yukihiro "Matz" Matsumoto be550f04e4 codedump.c: OP_POPERR does not have register access. 2017-02-08 09:45:55 +09:00
Yukihiro "Matz" Matsumoto 7eebbce42f Merge pull request #3437 from eboda/master
Fix interpolation escaping in String.inspect
2017-02-08 08:58:41 +09:00
Edgar Boda-Majer 46e4e342f4 Fix interpolation escaping in String.inspect 2017-02-07 13:33:53 +01:00
Yukihiro "Matz" Matsumoto 794de3317a Merge pull request #3430 from ksss/local_variables
Kernel#local_variables: Make result array unique
2017-02-06 15:58:53 +09:00
ksss bd72dba8c0 Kernel#local_variables: Make result array unique 2017-02-06 11:16:47 +09:00
Yukihiro "Matz" Matsumoto f2b18a604c Check maximum number of formal arguments.
http://hkdnet.hatenablog.com/entry/2017/02/06/080000 (Japanese)
2017-02-06 09:14:49 +09:00
Yukihiro "Matz" Matsumoto 48e0bbbfee Make eval to use trampoline technique; fix #3415
Now `eval()` can call Fiber.yield etc.
2017-02-04 16:19:31 +09:00
Yukihiro "Matz" Matsumoto bf4e79cc62 argv may be modified when mrb_funcall() is called; fix #3419
Calling `mrb_funcall()` and `mrb_yield()` (and their related
functions) are discouraged unless absolutely necessary, because
it can cause this kind of issues very easily.
2017-02-04 14:10:39 +09:00
Yukihiro "Matz" Matsumoto 8f52b88ee7 No need to make env unshared in the finalization; fix #3425 2017-02-04 13:48:23 +09:00
Yukihiro "Matz" Matsumoto 8e0f231330 Mark mrb->backtrace.exc as GC root; fix #3388 2017-02-04 12:59:08 +09:00
Yukihiro "Matz" Matsumoto 6e0ba0085d Jump address should fit in 16 bits range; fix #3426 2017-02-04 12:37:08 +09:00
Yukihiro "Matz" Matsumoto a746ebe96f Merge pull request #3420 from udzura/patch-1
Fix usage of Class#name in mruby-bin-mruby's bintest
2017-02-03 09:30:22 +09:00
Yukihiro "Matz" Matsumoto e0323dff8c Merge pull request #3427 from clayton-shopify/fix-mrb-random-init
Fetch arguments earlier in mrb_random_init to avoid a crash.
2017-02-03 09:29:46 +09:00
Clayton Smith a8ccda5692 Fetch arguments earlier to avoid a crash. 2017-02-02 16:35:59 -05:00
Uchio KONDO ab5812d0d8 Use standard Module(Class)#to_s 2017-02-02 18:09:27 +09:00
Yukihiro "Matz" Matsumoto 6420951463 Update example lines of mrbgems in build_config.rb; ref #3414 2017-01-25 15:38:25 +09:00
Yukihiro "Matz" Matsumoto ac88f85a9e Copy mrb_float values from pool when MRB_WORD_BOXING; ref #3396 2017-01-25 11:09:15 +09:00
Yukihiro "Matz" Matsumoto 51d7a69ab0 Clear (o).w first for MRB_WORD_BOXING; ref #3396 2017-01-25 11:07:57 +09:00
Yukihiro "Matz" Matsumoto b3ce364537 Outer class may be same as the class; fix #3382 2017-01-24 17:54:05 +09:00
Yukihiro "Matz" Matsumoto 72bff2932b Use size_t to avoid integer overflow in mrb_ary_splice(); fix #3413 2017-01-24 11:36:27 +09:00
Yukihiro "Matz" Matsumoto 28cf7a549d Change return type of mrb_range_beg_len() from int to mrb_int.
ref #3411
2017-01-23 22:18:29 +09:00
Yukihiro "Matz" Matsumoto f0f095bc13 Fix a double free problem in codegen.c; fix #3378
This issue was first reported by https://hackerone.com/geeknik
The fix was proposed by @titanous
2017-01-23 16:53:31 +09:00
Yukihiro "Matz" Matsumoto 3ce82603a5 Fix memory leak; ref #3378
The fix was proposed by @titanous
2017-01-23 16:48:18 +09:00
Yukihiro "Matz" Matsumoto ffb5e5ab08 The ensure clause should keep its ci after its execution; fix #3406
This issue was reported by https://hackerone.com/ston3
2017-01-23 16:44:11 +09:00
Yukihiro "Matz" Matsumoto 324887d0d6 Backtrace list must be an array of strings; fix #3408 2017-01-23 16:23:48 +09:00
Yukihiro "Matz" Matsumoto 28b7b9ec64 Skip non string values in backtraces; ref #3408 2017-01-23 16:22:55 +09:00
Yukihiro "Matz" Matsumoto 40ec03c8c2 Merge pull request #3412 from ksss/mrb_ary_splice
Refactoring: Use array_copy instead of for loop
2017-01-23 15:24:56 +09:00
ksss 78a395d446 Refactoring: Use array_copy instead of for loop 2017-01-23 15:18:48 +09:00
Yukihiro "Matz" Matsumoto 4d38cad31b Add MRB_API to mrb_range_beg_len(); ref #3411 2017-01-23 15:05:12 +09:00
Yukihiro "Matz" Matsumoto 5e1d923381 Changed the behavior of mrb_range_beg_len(); close #3411
The new API is:

int mrb_range_beg_len(mrb, range, &beg, &len, len, trunc)

The new argument `trunc` is a boolean value that specifies
whether the function truncates the range. The new return value
is an integer instead of a boolean, that is:

 0: not a range
 1: range with proper edges
 2: out of range

To get the old behavior, you have to rewrite:

  mrb_range_beg_len(mrb, range, &beg, &len, len)

to:

  mrn_range_beg_len(mrb, range, &beg, &len, len, TRUE) == 1

[Breaking Change]
2017-01-23 14:35:26 +09:00
Yukihiro "Matz" Matsumoto 708088c5fa Should not make empty strings shared; fix #3407 2017-01-23 10:52:40 +09:00
Yukihiro "Matz" Matsumoto 49fd7590df Use mrb_write_barrier() instead of mrb_field_write_barrier_value()
ref #3409
2017-01-23 10:32:33 +09:00
Yukihiro "Matz" Matsumoto fdec607cd0 Remove unnecessary inline declaration; ref #3409 2017-01-23 10:30:14 +09:00
Yukihiro "Matz" Matsumoto 9d0f07e6a7 Merge pull request #3409 from ksss/mrb_ary_splice
Rewrite mrb_ary_splice
2017-01-23 10:28:09 +09:00
Yukihiro "Matz" Matsumoto 39ce9fe585 Merge pull request #3410 from ksss/mrb_ary_aset
Should raise RuntimeError when object frozen
2017-01-23 00:24:00 +09:00
ksss b49bd70f59 Should raise RuntimeError when object frozen 2017-01-22 18:53:20 +09:00
ksss 65c9baae7c Rewrite mrb_ary_splice
Referenced to CRuby's array.c(rb_ary_splice)

fix #3405
2017-01-22 14:06:23 +09:00
Yukihiro "Matz" Matsumoto bd50273bbc Merge pull request #3404 from clayton-shopify/fix-block-params
Fix incorrect parsing of block parameters.
2017-01-21 23:52:26 +09:00
Clayton Smith 797ff625f3 Fix incorrect parsing of block parameters. 2017-01-21 09:08:37 -05:00
Yukihiro "Matz" Matsumoto c48aef0b65 Stack position may be bigger than stack bottom; fix #3401
This issue was reported by https://hackerone.com/titanous
2017-01-21 18:01:12 +09:00
Yukihiro "Matz" Matsumoto 873b96bebc Merge pull request #3402 from clayton-shopify/fix-masgn-optimization
Remove problematic optimization from NODE_MASGN codegen
2017-01-21 11:15:14 +09:00
Clayton Smith 2c0f8f1a23 Remove problematic optimization. 2017-01-20 18:40:18 -05:00
Yukihiro "Matz" Matsumoto b23fb45f9c Integral#step without arg should loop forever as CRuby does. 2017-01-20 17:58:29 +09:00
Yukihiro "Matz" Matsumoto fe0e45505b Initialize callinfo->acc; ref #3243 2017-01-18 17:53:08 +09:00
Yukihiro "Matz" Matsumoto c8536d977d Merge pull request #3362 from ksss/proc
Proc shouldn't have `initialize` method
2017-01-18 00:09:26 +09:00
Yukihiro "Matz" Matsumoto c83069860a Dots is not needed for base 10 negative numbers; fix #3400 2017-01-16 17:21:55 +09:00
Yukihiro "Matz" Matsumoto c59ef59ad9 Merge pull request #3399 from ksss/caller
Implement Kernel.#caller
2017-01-16 17:11:47 +09:00
ksss 59d9f313df Skip when backtrace doesn't get 2017-01-14 22:01:20 +09:00
ksss 6f9cb7406a Implement Kernel.#caller 2017-01-14 22:01:20 +09:00
Yukihiro "Matz" Matsumoto 8d61f2120c Add proper given argument number in the wrong-number-argument error. 2017-01-12 23:14:35 +09:00
Yukihiro "Matz" Matsumoto a3571240e5 Add proper stack size calculation; fix #3398
This issue was reported by https://hackerone.com/ssarong
2017-01-12 23:08:58 +09:00
Yukihiro "Matz" Matsumoto 38acb9ec36 Kernel#initialize should not break existing mt; fix #3397
This issue was reported by https://hackerone.com/icanthack
The solution is suggested by @clayton-shopify.
2017-01-12 21:43:23 +09:00
Yukihiro "Matz" Matsumoto 41eff635bf Merge pull request #3393 from clayton-shopify/fix-exc-initialize
Fix broken MRB_INT64
2017-01-12 15:31:32 +09:00
Yukihiro "Matz" Matsumoto fb1dad82aa Merge pull request #3394 from clayton-shopify/really-fix-nme
Fix 36fc1f14 not checking in the right location
2017-01-12 15:29:02 +09:00
Yukihiro "Matz" Matsumoto a69d92e819 Merge pull request #3395 from hhc0null/fix-typo
Fix a typo in string.h.
2017-01-12 15:04:13 +09:00
hhc0null af4f6e8dc6 Fix a typo. 2017-01-12 00:02:17 +09:00
Bouke van der Bijl 6be5160eb6 Fix 36fc1f14 not checking in the right location 2017-01-11 09:10:12 -05:00
Clayton Smith bc4c90de07 Use mrb_int for argc. 2017-01-11 09:05:02 -05:00
Yukihiro "Matz" Matsumoto db1bd078be Use temporary variable to avoid potential crash; fix #3387
This issue was original reported by https://hackerone.com/icanthack
https://hackerone.com/titanous suggested the solution.
`regs` may be reallocated in the function call.
2017-01-11 17:59:56 +09:00
Yukihiro "Matz" Matsumoto e1ff71029f String#replace should check replacing string; fix #3374
This issue was reported by https://hackerone.com/tunz
2017-01-11 17:51:11 +09:00
Yukihiro "Matz" Matsumoto 06b2e6a76c Check if ci->target_class is NULL before dereferencing
close #3389
This issue was reported by https://hackerone.com/ston3
2017-01-11 11:30:52 +09:00
Yukihiro "Matz" Matsumoto 44edc51612 Raises Exception if raising exception class is redefined
close #3384
This issue was reported by https://hackerone.com/brakhane
2017-01-11 10:29:55 +09:00
Yukihiro "Matz" Matsumoto 7523cdf340 Exception#initialize to take arbitrary number of args; ref #3384 2017-01-11 10:29:55 +09:00
Yukihiro "Matz" Matsumoto c4491e477b Validate tm values before timegm(); close #3368
This issue was reported by https://hackerone.com/volc
2017-01-09 10:42:11 +09:00
Yukihiro "Matz" Matsumoto d3a8ebfadf Merge pull request #3381 from sorah/asn
Put package's libs flag after %{objs}
2017-01-09 10:25:34 +09:00
Sorah Fukumori ee7fc56dd0 Put package's libs flag after %{objs}
In case LDFLAG contains "-Wl,--as-needed" or "--as-needed" is enabled by
default, "-l" flags should appear after objs specifiction.
2017-01-09 10:08:06 +09:00
Yukihiro "Matz" Matsumoto 147c5c5441 Merge pull request #3380 from syucream/fix-assert
Pass when assert returns a false value
2017-01-07 19:37:55 +09:00
Ryo Okubo f085baae06 Pass when assert returns a false value 2017-01-07 17:57:14 +09:00
Yukihiro "Matz" Matsumoto 392d7fbef9 Add ary_modify() checks; close #3379
This issue was reported by https://hackerone.com/an0n-j
2017-01-07 12:26:29 +09:00
Yukihiro "Matz" Matsumoto 8c11b04d5c Merge pull request #3377 from ksss/respond_to
Check intern object returned by mrb_check_string_type
2017-01-06 18:56:39 +09:00
Yukihiro "Matz" Matsumoto 3c2f101aa4 Merge pull request #3376 from bovi/2017-copyright
Update Copyright to 2017
2017-01-06 18:52:22 +09:00
ksss ddcb30d84b Check intern object returned by mrb_check_string_type 2017-01-06 16:27:19 +09:00
Daniel Bovensiepen 2c77dfab04 Update Copyright to 2017
Signed-off-by: Daniel Bovensiepen <daniel@bovensiepen.net>
2017-01-06 14:27:57 +08:00
Yukihiro "Matz" Matsumoto 885d929398 Improve capacity enhancing conditions 2017-01-06 14:53:00 +09:00
Yukihiro "Matz" Matsumoto c6a1172592 Add pointer cast to pacify warnings. 2017-01-06 14:52:04 +09:00
Yukihiro "Matz" Matsumoto 9a76a0bd80 Move mrb_assert() position. 2017-01-06 14:51:21 +09:00
Yukihiro "Matz" Matsumoto 5d0b9459ff Merge pull request #3371 from takjn/removed_unnecessary_escape_charcter
Removed ununnecessary escape character '\' in libmruby.flags.mak
2017-01-06 14:35:10 +09:00
Yukihiro "Matz" Matsumoto f53f73f30c Should not deallocate shared string referring static; fix #3373 2017-01-06 14:25:01 +09:00
Jun Takeda fe0884f37f Removed ununnecessary escape character '\' for MRUBY_XXX in libmruby.flags.mak 2017-01-05 22:42:25 +09:00
Yukihiro "Matz" Matsumoto 36f5b44578 Add new method Kernel#frozen?; ref #3370 2017-01-05 17:49:21 +09:00
Yukihiro "Matz" Matsumoto a10f85f855 Merge pull request #3369 from ksss/fix-str-prepend
Rewrite String#prepend with Ruby
2017-01-05 17:40:38 +09:00
Yukihiro "Matz" Matsumoto 2e0c2b5807 Add mrb_hash_modify() to Hash#{delete,clear}; ref #3370
This issue was reported by https://hackerone.com/an0n-j
2017-01-05 16:46:08 +09:00
ksss eeca6ec8f5 Rewrite String#prepend with Ruby
Fix #3357
2017-01-04 14:00:28 +09:00
Yukihiro "Matz" Matsumoto bc1259de3b add explicit casts 2017-01-02 17:48:44 +09:00
Yukihiro "Matz" Matsumoto f388b6d612 use size_t instead of int 2017-01-02 17:48:44 +09:00
Yukihiro "Matz" Matsumoto 158a6ab2ed Merge pull request #3367 from ksss/str-modify
Fix segv on str_buf_cat
2017-01-02 17:48:27 +09:00
ksss 8a9a24152a Fix memory error on str_buf_cat
Modify from nofree to embed string
2017-01-02 17:32:44 +09:00
ksss 30b6648b9c Small refactoring: should use RSTR_CAPA 2017-01-02 16:33:58 +09:00
Yukihiro "Matz" Matsumoto 07167b8f5e Initialize potentially uninitialized variable tsec. 2017-01-01 00:47:45 +09:00
Yukihiro "Matz" Matsumoto 8b77979667 Initialize potentially uninitialized variable z 2017-01-01 00:45:14 +09:00
Yukihiro "Matz" Matsumoto 1ed4de58d0 str_buf_cat(): better size check added; ref #3342 2016-12-31 23:33:34 +09:00
Yukihiro "Matz" Matsumoto 342b1de65c str_buf_cat(): should allocate at least RSTRING_EMBED_LEN_MAX+1. 2016-12-31 23:31:45 +09:00
Yukihiro "Matz" Matsumoto cfdd1e3cc6 ary_expand_capa(): refine conditions to avoid infinite loop; ref #3353 2016-12-31 23:22:17 +09:00
Yukihiro "Matz" Matsumoto 9d84f0d47b ary_expand_capa(): size calculation by size_t; fix #3353
Also more size checks added.
2016-12-31 23:09:56 +09:00
Yukihiro "Matz" Matsumoto 270ea41b37 method_missing() may have CALL_MAXARGS-1 arguments; fix #3351
The issue was reported by https://hackerone.com/ston3
2016-12-30 22:09:32 +09:00
Yukihiro "Matz" Matsumoto 803bf010ca save/restore arena index around yield; ref #3359 2016-12-28 13:00:28 +09:00
Yukihiro "Matz" Matsumoto 6af8cc36b9 Merge pull request #3366 from ksss/splice
Check array max size
2016-12-28 13:00:14 +09:00
ksss caba1a19dc Check array max size
Fix #3354
2016-12-27 15:48:53 +09:00
Yukihiro "Matz" Matsumoto 30d5424adf Merge pull request #3365 from ksss/freeze
Fix segv when primitive value
2016-12-26 18:12:44 +09:00
Tomoyuki Sahara 69623078a8 Merge pull request #72 from masahino/add_pointer_casting
Add pointer casting
2016-12-26 09:12:19 +09:00
ksss 5c1c002ac2 Fix segv when primitive value
Fix #3352
2016-12-25 16:52:10 +09:00
Yukihiro "Matz" Matsumoto 000a3119ca Merge pull request #3364 from ksss/string2
Check overflow string length
2016-12-25 01:35:44 +09:00
Yukihiro "Matz" Matsumoto ede04d68b3 Merge pull request #3363 from ksss/string
Do nothing when empty string
2016-12-25 00:43:01 +09:00
masahino 1fac605e3f Add pointer casting 2016-12-24 23:32:44 +09:00
ksss c626b823ca Check overflow string length
Fix #3360
2016-12-23 23:31:21 +09:00
ksss 0de65a88d4 Do nothing when empty string
Fix #3361
2016-12-23 23:13:23 +09:00
ksss a68b568911 Should call initialize method if defined 2016-12-22 10:40:13 +09:00
Yukihiro "Matz" Matsumoto 5e3077c00d One less argument for raisef(); fix #3355
This issue was reported by https://hackerone.com/mg36
2016-12-21 16:46:26 +09:00
ksss 3cba13c249 Proc shouldn't have initialize method
Fix #3356
2016-12-21 15:17:05 +09:00
Yukihiro "Matz" Matsumoto 987daa64e3 Merge pull request #3358 from takjn/add-example-rx630
Added example for cross-compiling on Renesas RX630
2016-12-21 04:03:34 +09:00
Jun Takeda 76eb7147a4 Added example for cross-compiling for Renesas RX630 2016-12-21 00:51:18 +09:00
Tomoyuki Sahara 458b517c6f Merge pull request #71 from eagletmt/readlink
Add File.readlink
2016-12-19 09:03:13 +09:00
Yukihiro "Matz" Matsumoto 432570723d Check if width is zero or negative before fill; fix #3347
Reported by https://hackerone.com/haquaman.
2016-12-18 02:02:30 +09:00
Yukihiro "Matz" Matsumoto 2edf15bed8 Prohibit mixture of posarg and nextarg; ref #3347 2016-12-18 02:02:30 +09:00
Yukihiro "Matz" Matsumoto 9781f7f0ea Add "not reached" mark in mrb_ary_concat() 2016-12-18 02:02:30 +09:00
Yukihiro "Matz" Matsumoto c2bbfa5b61 NODE_NEGATE cdr may not be code-node; fix #3348 ref #3324
Reported by Denis Kasak https://hackerone.com/dkasak
2016-12-18 02:02:30 +09:00
Yukihiro "Matz" Matsumoto b0886d5692 Zero length heredoc still crashed; ref Shopify/mruby-internal#81 2016-12-18 02:02:30 +09:00
Kohei Suzuki b31b8022db Fix memory leak in error case 2016-12-17 16:48:02 +09:00
Kohei Suzuki d1c48192cb Add File.readlink 2016-12-17 15:03:52 +09:00
Yukihiro "Matz" Matsumoto 5289b4ba11 Merge pull request #3346 from clayton-shopify/fix-float-read
Fix crash when exponent is -2147483648
2016-12-17 12:18:35 +09:00
Tomoyuki Sahara 7e89736291 Merge pull request #70 from eagletmt/chmod
Add File.chmod
2016-12-16 22:54:20 +09:00
Kohei Suzuki 698378f076 Add File.chmod 2016-12-16 01:20:08 +09:00
Clayton Smith 868d2e528f Fix crash when exponent is -2147483648 2016-12-15 09:36:22 -05:00
Yukihiro "Matz" Matsumoto 73cc08772f remove debug code; ref #3344 2016-12-14 13:34:24 +09:00
Yukihiro "Matz" Matsumoto eb2a52ac98 Merge pull request #3345 from clayton-shopify/fix-range-beg-len
Check type before calling mrb_range_ptr.
2016-12-14 01:19:49 +09:00
Clayton Smith 73ad7395c0 Check type before calling mrb_range_ptr. 2016-12-13 10:04:15 -05:00
Yukihiro "Matz" Matsumoto fead715cef tLABEL should not come after conditional ternary; fix #3344 2016-12-13 23:44:10 +09:00
Yukihiro "Matz" Matsumoto df35076602 Restore callinfo offset in mrb_yield_with_class() 2016-12-13 17:17:47 +09:00
Yukihiro "Matz" Matsumoto d196e4dd04 void_expr_error(): n may be NULL.
Reported from @clayton-shopify.
2016-12-13 11:18:05 +09:00
Yukihiro "Matz" Matsumoto 3bedd22d55 Add assertion to make sure new capacity does not overflow. 2016-12-13 10:50:04 +09:00
Yukihiro "Matz" Matsumoto 3a7c369536 Make sure str->capa is under MRB_INT_MAX; fix #3342 2016-12-13 10:48:36 +09:00
Yukihiro "Matz" Matsumoto 647ad29a7a Fixed wrong condition in new_sym() that breaks symbol data. 2016-12-13 02:33:28 +09:00
Yukihiro "Matz" Matsumoto a4ae22ae0c Failed to realloc irep->syms in certain condition.
Also msym size changed to 512 from 256.
2016-12-13 01:55:08 +09:00
Yukihiro "Matz" Matsumoto 9cef265402 should not try to set classpath for frozen classes; ref #3340 2016-12-12 10:34:21 +09:00
Tomoyuki Sahara f2d4880098 Merge pull request #11 from masahino/add_casting
Add pointer casting
2016-12-12 06:51:03 +09:00
Yukihiro "Matz" Matsumoto 6ac5473494 Merge pull request #3341 from kou/support-pkg-config-in-mrbgem-rake
Support pkg-config in mrbgem.rake
2016-12-12 01:07:27 +09:00
Yukihiro "Matz" Matsumoto 1164463a7c freeze classes/modules; ref #3340 2016-12-12 01:05:07 +09:00
Yukihiro "Matz" Matsumoto 761562b65f freeze instance variables; ref #3340 2016-12-12 01:00:24 +09:00
Yukihiro "Matz" Matsumoto 92c843dd07 rename prefix RBASIC_ to MRB_; ref #3340 2016-12-12 00:54:36 +09:00
Yukihiro "Matz" Matsumoto 1fbad32f8b Merge pull request #3340 from k0kubun/object-freeze
Implement Object#freeze
2016-12-12 00:49:23 +09:00
Kouhei Sutou 237d26fd86 Support pkg-config in mrbgem.rake
Example usage:

    MRuby::Gem::Specification.new('mruby-onig-regexp') do |spec|
      # ...
      if spec.search_package('onigmo')
        # Use onigmo.h when onigmo.pc exist.
        spec.cc.defines += ["HAVE_ONIGMO_H"]
      elsif spec.search_package('oniguruma')
        # Use oniguruma.h when oniguruma.pc exist.
        spec.cc.defines += ["HAVE_ONIGURUMA_H"]
      else
        # Use bundled Onigmo otherwise.
        # ...
      end
    end
2016-12-11 21:35:56 +09:00
Takashi Kokubun 10bb7ad693 Implement Object#freeze 2016-12-11 03:44:15 +09:00
Yukihiro "Matz" Matsumoto 3cc913490b Merge pull request #3329 from bouk/reuse
Mark all the built-in classes during GC sweep
2016-12-10 16:02:47 +09:00
Yukihiro "Matz" Matsumoto d93422315c Merge branch 'bouk-negate' 2016-12-10 15:55:45 +09:00
Yukihiro "Matz" Matsumoto 13979a4376 Merge pull request #3324 from bouk/mruby/bouk-negate
Don't generate code for NODE_NEGATE if the result isn't used
Reported by https://hackerone.com/haquaman
2016-12-10 15:52:41 +09:00
Yukihiro "Matz" Matsumoto 0af170fbec gc.c: dead_slot is boolean; ref #3339 2016-12-10 15:34:32 +09:00
Yukihiro "Matz" Matsumoto 965690c94a Merge pull request #3339 from kazuho/kazuho/retain-page-with-tt-env
do not destroy a page with an active TT_ENV
2016-12-10 15:32:55 +09:00
Kazuho Oku 2ef634edb5 do not destroy a page with an active TT_ENV (e.g. an env referred from TT_FIBER) 2016-12-10 15:11:07 +09:00
Yukihiro "Matz" Matsumoto 7b968ca893 Clear parsing_heredoc at the end of file 2016-12-10 12:35:12 +09:00
Yukihiro "Matz" Matsumoto 8c26efd7ed Merge pull request #3338 from bouk/break-127
Fix segfault in gen_values with NOVAL and more than 127 args
2016-12-10 11:21:54 +09:00
Bouke van der Bijl 1264219832 Fix segfault in gen_values with NOVAL and more than 127 args 2016-12-09 10:30:05 -05:00
masahino 906b516cfa Add pointer casting 2016-12-09 21:57:06 +09:00
Yukihiro "Matz" Matsumoto c85feaec56 Merge pull request #3337 from bouk/undef-127
Fix segfault when undef is called with more than 126 arguments
2016-12-09 16:42:54 +09:00
Bouke van der Bijl c8da3c4df4 Fix segfault when undef is called with exactly 127 arguments
The issue is that when there are more than 126 arguments an array needs
to be created to pass the arguments on with.

Reported by https://hackerone.com/revskills
2016-12-08 15:47:17 -05:00
Yukihiro "Matz" Matsumoto db6b6ff442 Merge pull request #3336 from AltimitSystems/string.const.macro
Removed unnecessary const macro - const keyword is already a dependency
2016-12-09 02:57:03 +09:00
Felix Jones 2827655b9c Removed unnecessary const macro - const keyword is already a dependency 2016-12-08 12:38:00 +00:00
Yukihiro "Matz" Matsumoto b84e005fc3 Merge pull request #3335 from mattn/fix-vs2013
fix build on vs2013-vs2015
2016-12-08 16:48:08 +09:00
Yasuhiro Matsumoto c27dbfedf4 disable define const on VS 2016-12-08 15:56:50 +09:00
Yasuhiro Matsumoto eda6c1dc05 fix build on vs2013-vs2015 2016-12-08 15:38:19 +09:00
Yukihiro "Matz" Matsumoto bcd91856fd Merge pull request #3331 from dabroz/feature-load-exec
Promote load_exec to mruby API as mrb_load_exec (fixes #3248)
2016-12-08 15:22:07 +09:00
Yukihiro "Matz" Matsumoto 0d38ede33b Merge pull request #3333 from kazuho/kazuho/mrb_gc_unregister
fix issues of mrb_gc_unregister introduced in 09b1185
2016-12-08 12:50:39 +09:00
Kazuho Oku c2e749f878 fix issues of mrb_gc_unregister introduced in 09b1185
* fixes partial copy of objects in GC root array (due to missing `* sizeof(mrb_value)`)
* restores the behavior that permitted an unregistered object to be used as an argument
2016-12-08 10:27:07 +09:00
Tomasz Dąbrowski 0360a744b5 Promote load_exec to mruby API as mrb_load_exec (fixes #3248) 2016-12-07 21:21:21 +01:00
Bouke van der Bijl d56a19cbf5 Don't generate code for NODE_NEGATE if the result isn't used
Reported by https://hackerone.com/haquaman
2016-12-07 15:14:17 -05:00
Bouke van der Bijl f7a891fa89 Mark all the built-in classes during GC sweep
Reported by https://hackerone.com/haquaman
2016-12-07 15:14:12 -05:00
Yukihiro "Matz" Matsumoto 5930a6ebc7 Merge pull request #3328 from shugo/hash-dup-default_proc
Copy default_proc by Hash#dup.
2016-12-08 01:04:25 +09:00
Yukihiro "Matz" Matsumoto edf26d4043 Merge pull request #3327 from AltimitSystems/errno.macro
Removed the errno declaration from string.c
2016-12-08 01:02:27 +09:00
Felix Jones fe86cf4c91 Removed the errno declaration from string.c 2016-12-07 14:17:09 +00:00
Shugo Maeda 338e0ff52d Copy default_proc by Hash#dup. 2016-12-07 22:39:20 +09:00
Felix Jones 6187c21bd9 Wrapped string.c errno with ifndef macro for platforms that use inbuilt errno macro 2016-12-07 12:46:47 +00:00
Yukihiro "Matz" Matsumoto 2b0dd1f481 Merge pull request #3325 from kazuho/kazuho/detect-64bit
set `MRB_64BIT` if the sizeof(size_t) is 8
2016-12-07 20:15:36 +09:00
Kazuho Oku b491f4b06a set MRB_64BIT if the sizeof(size_t) is 8 2016-12-07 15:31:32 +09:00
Yukihiro "Matz" Matsumoto dffb4d82dc Add type check for cls before allocation 2016-12-06 11:40:49 +09:00
Yukihiro "Matz" Matsumoto 3623a833a4 Protect exceptions within main() function 2016-12-06 11:23:23 +09:00
Yukihiro "Matz" Matsumoto 9a962ed2c3 Raise an exception in time_update_datetime().
The function used to return NULL on error, but not checked in the
caller site.
2016-12-06 10:27:35 +09:00
Yukihiro "Matz" Matsumoto 6ec14a2173 Merge pull request #3318 from bouk/splat-stack
Fix stack move segfaulting in OP_ARYCAT
2016-12-05 16:51:46 +09:00
Yukihiro "Matz" Matsumoto 43512cc7bd Reorganize heredoc rules; fix #3273
The following codes used to be SyntaxError:

(1)
  a = <<-EOD;
  hello
  EOD

(2)
  <<-EOD.bla begin
  k
  EOD
  end
2016-12-05 02:55:39 +09:00
Yukihiro "Matz" Matsumoto ac561a52f5 Add symbol type check for Module#undef_method 2016-12-04 10:41:01 +09:00
Yukihiro "Matz" Matsumoto 5c651d6ce9 add MRB_API to mrb_float_read(); ref #3270 2016-12-03 18:55:52 +09:00
Yukihiro "Matz" Matsumoto a0fbc46ccd Import locale insensitive strtod() from Ruby1.8; fix #3270
The function was renamed to `mrb_float_read(const char*, char**)`.
2016-12-03 18:47:04 +09:00
Yukihiro "Matz" Matsumoto 802e396466 Merge branch 'bouk-method-missing-segfault' 2016-12-03 18:23:25 +09:00
Yukihiro "Matz" Matsumoto 144006a20e update NoMethodError tests; ref #3291 2016-12-03 18:23:04 +09:00
Yukihiro "Matz" Matsumoto 8f510be211 Merge branch 'method-missing-segfault' of https://github.com/bouk/mruby into bouk-method-missing-segfault 2016-12-03 18:20:29 +09:00
Yukihiro "Matz" Matsumoto f6d199919d Needed to apply block from safe-navigation operators; fix #3310 2016-12-03 16:38:43 +09:00
Yukihiro "Matz" Matsumoto 6b84ff4a44 Print NODE_SCALL (&.) from mrb_parser_dump() 2016-12-03 16:21:15 +09:00
Yukihiro "Matz" Matsumoto c029c6c444 codegen: avoid unnecessary OP_MOVE after CASE 2016-12-03 14:50:36 +09:00
Yukihiro "Matz" Matsumoto 23c4ad0865 Merge pull request #3319 from bouk/apost-splatt
Fix segfault when using result of rest assignment
2016-12-03 12:53:21 +09:00
Yukihiro "Matz" Matsumoto 79a621dd73 Check before retrieving struct RRange pointer; fix #3320
range->edges may be NULL for example when #initialize_copy removed.
2016-12-03 12:30:01 +09:00
Yukihiro "Matz" Matsumoto 9776150263 Merge pull request #3317 from bouk/missing-to-s
Use mrb_ptr instead of mrb_cptr in Kernel#to_s
2016-12-03 12:01:43 +09:00
Yukihiro "Matz" Matsumoto d89cfca02c Merge pull request #3315 from ksss/enumerator-with_index
Fix some incompatibility for Enumerator#with_index
2016-12-03 11:58:39 +09:00
Yukihiro "Matz" Matsumoto e673fbb35a Merge pull request #3321 from clayton-shopify/fix-proc-crash-upstream
Fix segfault in mrb_proc_copy.
2016-12-03 11:54:22 +09:00
Yukihiro "Matz" Matsumoto d7589b10ed Merge pull request #3316 from clayton-shopify/fix-array-size-3
Fix more integer overflows.
2016-12-03 11:52:52 +09:00
Clayton Smith 1ff4b3f800 Fix segfault in mrb_proc_copy. 2016-12-02 09:36:26 -05:00
Bouke van der Bijl fe362c1f26 Fix segfault when using result of rest assignment
Reported by https://hackerone.com/haquaman
2016-12-01 15:49:36 -05:00
Bouke van der Bijl 9c61e1cd87 Use mrb_ptr instead of mrb_cptr in Kernel#to_s
This is to avoid segfault when WORD_BOXING is enabled

Reported by https://hackerone.com/brakhane
2016-12-01 15:23:56 -05:00
Bouke van der Bijl 7d07466b43 Fix stack move segfaulting in OP_ARYCAT
Reported by https://hackerone.com/haquaman

Testcase (couldn't get it to work as a test):

def nil.b
  b *nil
end
nil.b
2016-12-01 15:23:31 -05:00
Clayton Smith 2bc3a5fb78 Fix more integer overflows. 2016-12-01 09:08:38 -05:00
Yukihiro "Matz" Matsumoto 2cca9d3688 avoid comparison between signed and unsigned integer; ref #3312 2016-12-01 18:49:39 +09:00
Yukihiro "Matz" Matsumoto f1cf6ef817 Merge pull request #3312 from nobu/feature/multi-unicode-escape
Feature/multi unicode escape
2016-12-01 18:42:40 +09:00
Yukihiro "Matz" Matsumoto 4d807fc619 Merge pull request #3313 from yhara/add-test
Add test for recently fixed bugs
2016-12-01 18:41:23 +09:00
Yukihiro "Matz" Matsumoto ab4ab7c8a0 Fix compile error by #3309 2016-12-01 18:37:03 +09:00
Nobuyoshi Nakada 0f08914ac0 Support multiple elements \u syntax 2016-12-01 16:48:43 +09:00
Nobuyoshi Nakada fed40b44b8 Extract read_escape_unicode from read_escape 2016-12-01 16:48:43 +09:00
Nobuyoshi Nakada bd9bc7786f Fix assertion argument orders 2016-12-01 16:48:43 +09:00
Nobuyoshi Nakada e4086d4014 Fix compile error by #3309 2016-12-01 16:46:59 +09:00
ksss 2718fed124 Support svalue 2016-12-01 16:13:24 +09:00
ksss 0f774ff4df Support nil argument as no argument 2016-12-01 15:33:27 +09:00
Yutaka HARA 3f83ec64a8 Add test for recently fixed bugs 2016-12-01 14:55:26 +09:00
Yukihiro "Matz" Matsumoto 61ac564c99 Merge pull request #3309 from clayton-shopify/fix-array-size-2
Prevent array size calculation overflows.
2016-12-01 11:46:57 +09:00
Yukihiro "Matz" Matsumoto c37c255f19 Merge pull request #3311 from ksss/enum-generator
Support Enumerable methods
2016-12-01 11:46:10 +09:00
ksss 31f0ffeac8 Support Enumerable methods 2016-12-01 10:42:57 +09:00
Clayton Smith acdddb4f14 Prevent array size calculation overflows. 2016-11-30 13:55:09 -05:00
Yukihiro "Matz" Matsumoto 8461a31cb4 Fixed too much void_expr_error(); fix #3307 2016-11-30 13:04:50 +09:00
Yukihiro "Matz" Matsumoto 0e9c9acc11 Merge branch 'ksss-enumerator-lazy' 2016-11-30 12:54:29 +09:00
Yukihiro "Matz" Matsumoto 779c2629fe resolve conflict; ref #3306 2016-11-30 12:54:20 +09:00
Yukihiro "Matz" Matsumoto 3cf66a8218 Merge pull request #3305 from ksss/lazy-to_enum
Implement Enumerable::Lazy#to_enum and enum_for
2016-11-30 12:48:28 +09:00
ksss 0f90227907 Change Lazy class outer
Lazy class should be under Enumerator instead of Enumerable
2016-11-30 12:36:22 +09:00
ksss 8675975ba2 Implement Enumerable::Lazy#to_enum and enum_for 2016-11-30 11:02:02 +09:00
Yukihiro "Matz" Matsumoto 2bb47addad Prohibit instantiation of immediate objects 2016-11-30 10:36:17 +09:00
Yukihiro "Matz" Matsumoto f7c0024b8e Merge pull request #3278 from bouk/dup-class
Copy over INSTANCE_TT when duping class
2016-11-30 03:52:56 +09:00
Yukihiro "Matz" Matsumoto 5771c9778e add a test for #3296 2016-11-30 03:51:23 +09:00
Yukihiro "Matz" Matsumoto 37743111d9 should not refer Struct class by name; fix #3296 2016-11-30 03:49:56 +09:00
Yukihiro "Matz" Matsumoto 630733f346 check ttype before object allocation; fix #3294 2016-11-30 03:38:55 +09:00
Yukihiro "Matz" Matsumoto 27d166d4e2 Merge pull request #3304 from clayton-shopify/fix-array-size
Use size_t to calculate bytes needed for array.
2016-11-30 03:00:43 +09:00
Yukihiro "Matz" Matsumoto 66f64d4ee8 Merge pull request #3303 from bouk/empty-nil
Interpret argument in 'f ()' as nil instead of nothing
2016-11-30 02:52:39 +09:00
Clayton Smith b633aa9ad4 Use size_t to calculate bytes needed for array. 2016-11-29 10:26:02 -05:00
Bouke van der Bijl 523c267020 Interpret argument in 'f ()' as nil instead of nothing 2016-11-29 09:23:53 -05:00
Yukihiro "Matz" Matsumoto 246a9a8acd ary_concat: support self concatenation; fix #3302 2016-11-29 22:36:11 +09:00
Yukihiro "Matz" Matsumoto 9fc62d28d0 pre-allocate arena overflow error 2016-11-28 09:52:57 +09:00
Yukihiro "Matz" Matsumoto 27ceb84818 parse.y: use opt_paren_args to simplify yield rule 2016-11-27 22:43:46 +09:00
Yukihiro "Matz" Matsumoto 36fc1f1431 Added Exception check in mrb_exc_set(); close #3292
PR #3293 just checks for NoMethodError.
2016-11-27 22:17:51 +09:00
Yukihiro "Matz" Matsumoto 5ea1bb0eea Merge pull request #3301 from dabroz/feature-64-bit-word
Safeguard against using MRB_INT64 with MRB_WORD_BOXING in 32-bit mode
2016-11-27 21:00:34 +09:00
Yukihiro "Matz" Matsumoto f9f19f34dd replace _cstr by _lit for litral C strings; ref #3300 2016-11-27 20:53:25 +09:00
Tomasz Dabrowski 3fdfd8cb4a Safeguard against using MRB_INT64 with MRB_WORD_BOXING in 32-bit mode 2016-11-27 12:49:36 +01:00
Yukihiro "Matz" Matsumoto 3d9aa463f7 Add NULL checks for Time data retrieval 2016-11-27 20:47:20 +09:00
Yukihiro "Matz" Matsumoto c70e206330 Merge pull request #3300 from herwinw/doc
Added documentation on function for globals
2016-11-27 20:46:58 +09:00
Herwin Weststrate afee618c1b Added documentation on function for globals 2016-11-27 09:50:30 +01:00
Tomoyuki Sahara 0eafb089c9 Merge pull request #69 from eagletmt/explicit-cast
Add explicit cast from void* to struct mrb_io*
2016-11-27 13:53:50 +09:00
Yukihiro "Matz" Matsumoto 72915cab52 Merge pull request #3299 from dabroz/feature-16-bit-nan
Fixed NaN boxing when MRB_INT16 is set
2016-11-27 09:27:03 +09:00
Tomasz Dąbrowski 626648dc41 Fixed NaN boxing when MRB_INT16 is set 2016-11-26 13:05:02 +01:00
Kohei Suzuki 905203ef5e Add explicit cast from void* to struct mrb_io*
For compatibility with C++.
2016-11-26 14:18:28 +09:00
Yukihiro "Matz" Matsumoto 277e81a7c9 removed failing test for Time#initialize; ref #3295 2016-11-26 12:02:46 +09:00
Yukihiro "Matz" Matsumoto 4256130ecd Merge pull request #3293 from ksss/enum-first
Fix incompatibility for Enumerable#first
2016-11-26 09:59:50 +09:00
Yukihiro "Matz" Matsumoto f666350694 Merge pull request #3295 from bouk/time-seg
Fix null pointer dereference in mrb_time_initialize
2016-11-26 09:57:48 +09:00
Yukihiro "Matz" Matsumoto 0ee58a0fff Merge pull request #3298 from dabroz/patch-1
Fix typo in istruct.h
2016-11-26 09:50:37 +09:00
Tomasz Dąbrowski be5223371b Fix typo in istruct.h 2016-11-25 23:15:37 +01:00
Bouke van der Bijl b7f9a58757 Fix null pointer dereference in mrb_time_initialize
Reported by https://hackerone.com/raydot
2016-11-25 11:15:57 -05:00
ksss 1bf565ea04 Argument more strictly 2016-11-25 22:25:48 +09:00
ksss c28a963bf4 Like a Enumerable#take 2016-11-25 22:20:33 +09:00
Yukihiro "Matz" Matsumoto 743c1e7be1 stop warnings in the test; ref #3280 2016-11-25 09:44:22 +09:00
Yukihiro "Matz" Matsumoto 1329529f3b Merge branch 'bouk-nested-empty-heredoc' 2016-11-25 09:33:40 +09:00
Yukihiro "Matz" Matsumoto 55842c5a34 resolve conflict; ref #3279 2016-11-25 09:33:20 +09:00
Yukihiro "Matz" Matsumoto d3ff9d31f0 Merge branch 'bouk-struct-array-members' 2016-11-25 09:32:01 +09:00
Yukihiro "Matz" Matsumoto 79e3980a7f resolve conflict; ref #3281 2016-11-25 09:31:51 +09:00
Yukihiro "Matz" Matsumoto 7f05ba86f2 Merge branch 'bouk-127-segfaults' 2016-11-25 09:27:32 +09:00
Yukihiro "Matz" Matsumoto 30f12ba4bc resolve conflict; ref #3283 2016-11-25 09:27:24 +09:00
Yukihiro "Matz" Matsumoto 9f7701e27a Merge branch 'bouk-retry-codegen-misalign' 2016-11-25 09:26:01 +09:00
Yukihiro "Matz" Matsumoto cc2786c84e resolve conflict; ref #3285 2016-11-25 09:25:51 +09:00
Yukihiro "Matz" Matsumoto 0d48a9786f Merge branch 'bouk-empty-ternary' 2016-11-25 09:24:09 +09:00
Yukihiro "Matz" Matsumoto 0b4017fd69 resolve conflict; ref #3286 2016-11-25 09:23:47 +09:00
Yukihiro "Matz" Matsumoto d77b254108 Merge pull request #3287 from bouk/proc-arity
Fix calling .arity on Proc with undefined `initialize`
2016-11-25 09:20:47 +09:00
Yukihiro "Matz" Matsumoto 6905597f5b Merge pull request #3284 from bouk/remove-method-segfault
Fix segfault on remove_method with invalid argument
2016-11-25 09:19:22 +09:00
Yukihiro "Matz" Matsumoto a28fa35ea9 Merge pull request #3282 from bouk/fix-break-instance-class
Fix segfault when defining class inside instance_exec on primitive
2016-11-25 09:17:59 +09:00
Yukihiro "Matz" Matsumoto 1e892c0ffa Merge pull request #3280 from bouk/struct-redefine
Remove constant when a struct is redefined.
2016-11-25 09:15:57 +09:00
Yukihiro "Matz" Matsumoto b4d501750c Merge pull request #3288 from bouk/chomp-bang-len
Get String length after args in String#chomp!
2016-11-25 08:01:41 +09:00
Yukihiro "Matz" Matsumoto 54921aa671 Merge pull request #3289 from bouk/setbyte-len
Read length after args in String#setbyte
2016-11-25 08:01:06 +09:00
Yukihiro "Matz" Matsumoto 99f6de529e Merge pull request #3290 from bouk/unsafe-peep
Fix unsafe peephole optimization
2016-11-25 08:00:33 +09:00
Francois Chagnon a384bcce35 Fix instances where return value of mrb_method_search_vm is unchecked
Reported by @charliesome
2016-11-24 10:51:29 -05:00
Francis Bogsanyi 964427f82c Fix unsafe peephole optimization
Reported by https://hackerone.com/dkasak
2016-11-24 10:32:34 -05:00
Craig Lehmann 83005d83d8 Read length after args in String#setbyte
Prevents RCE
Reported by https://hackerone.com/raydot
2016-11-24 10:31:29 -05:00
Clayton Smith 76a1bdfa29 Get String length after args in String#chomp!
Fixes RCE issue
Reported by @bouk
2016-11-24 10:28:21 -05:00
Francois Chagnon 1ec5994377 Fix calling .arity on Proc with undefined initialize
Reported by @bouk
2016-11-24 10:23:31 -05:00
Bouke van der Bijl 71641bbf73 Fix segfault caused by empty condition in ternary
Reported by https://hackerone.com/jpenalbae
2016-11-24 10:20:42 -05:00
Bouke van der Bijl 1253982577 Fix codegen issue causing misaligned register
Reported by https://hackerone.com/haquaman
2016-11-24 10:18:48 -05:00
Bouke van der Bijl 22f5504054 Fix segfault on remove_method with invalid argument
Reported by https://hackerone.com/jpenalbae
2016-11-24 10:13:47 -05:00
Bouke van der Bijl 75b31d7438 Fix segfault on method call with exactly 127 arguments
Reported by https://hackerone.com/dkasak
2016-11-24 10:09:37 -05:00
Bouke van der Bijl 4523aaec01 Fix segfault when defining class inside instance_exec on primitive 2016-11-24 10:06:15 -05:00
Clayton Smith b60d6c42aa Don't allow array parameter in Struct.new 2016-11-24 10:05:05 -05:00
Clayton Smith 82731d9ee0 Remove constant when a struct is redefined. 2016-11-24 10:04:09 -05:00
Bouke van der Bijl 73e4f069be Fix nested empty heredoc causing segfault
As reported by https://hackerone.com/jpenalbae
2016-11-24 09:54:18 -05:00
Bouke van der Bijl 73bb30c2f4 Copy over INSTANCE_TT when duping class 2016-11-24 09:52:30 -05:00
Yukihiro "Matz" Matsumoto a630c4f413 use MRB_PRId instead of %d for mrb_int 2016-11-24 22:10:54 +09:00
Yukihiro "Matz" Matsumoto 8602789067 Merge pull request #3277 from dabroz/feature-float-tolerance
Fixed float tolerance in tests when MRB_USE_FLOAT is set
2016-11-24 21:48:14 +09:00
Yukihiro "Matz" Matsumoto e289ba3eff Merge pull request #3276 from dabroz/author
Update AUTHORS
2016-11-24 21:28:55 +09:00
Yukihiro "Matz" Matsumoto 22f73250db redo should work well in for statement; fix #3275 2016-11-24 21:25:27 +09:00
Tomasz Dąbrowski 72ed7eebc3 Fixed Range.size to use proper floating point tolerance 2016-11-24 12:50:49 +01:00
Tomasz Dąbrowski a8b8abbd82 Fixed float tolerance in tests when MRB_USE_FLOAT is set 2016-11-24 12:48:41 +01:00
Tomasz Dąbrowski 3943ab5368 Update AUTHORS 2016-11-24 12:34:36 +01:00
Yukihiro "Matz" Matsumoto 0c924b9287 fixed a bug in self modifying Array#[]=; fix #3274 2016-11-24 19:30:21 +09:00
Yukihiro "Matz" Matsumoto cb5c9d3415 always call Hash#default if no key found; fix #3272 2016-11-24 18:09:04 +09:00
Yukihiro "Matz" Matsumoto 23c73ff399 Time#initialize_copy: Check if source time is initialized.
To prevent crash from nasty code like:

  class Time
    def initialize
    end
  end

  a = Time.new
  b = Time.new
  a.initialize_copy b
2016-11-24 13:50:36 +09:00
Yukihiro "Matz" Matsumoto cef7bd5416 Merge pull request #3271 from ksss/enum-take
Fix Enumeable#take some incompatibility
2016-11-24 11:31:28 +09:00
Yukihiro "Matz" Matsumoto 227daa8811 Relax 'void value expression' check that was too strict 2016-11-24 11:22:54 +09:00
ksss 5134734541 Shouldn't call each method if size is 0 2016-11-24 10:35:15 +09:00
ksss 9e2faec8e4 Support object does'n have < method 2016-11-24 10:34:14 +09:00
Yukihiro "Matz" Matsumoto 1c9593954b Add "void value expression" check to the parser. 2016-11-24 10:32:28 +09:00
Yukihiro "Matz" Matsumoto dc4be19aab Add forgotten loop_pop() in NODE_OP_ASGN codegen 2016-11-24 10:01:03 +09:00
Yukihiro "Matz" Matsumoto f5a86ca530 Add pointer casting from mrb_malloc(); ref #3267 2016-11-24 09:28:00 +09:00
Yukihiro "Matz" Matsumoto 798c69d1be Avoid casting from int to unsigned char for C++; ref #3267 2016-11-24 09:28:00 +09:00
Tomasz Dąbrowski d7a6070d22 Fixed language standard mode for GCC (cannot use gnu99 with C++, c++03 used instead) 2016-11-24 09:28:00 +09:00
Tomasz Dąbrowski c2a60eb8af Fix for Windows-specific mruby C++ issues 2016-11-24 09:28:00 +09:00
Tomasz Dąbrowski 44c3859a97 Fix for compiling mruby as C++ on Visual Studio toolchain 2016-11-24 09:28:00 +09:00
Tomasz Dąbrowski 18757c8f7b Different method of compiling C as C++ (-x c++) 2016-11-24 09:28:00 +09:00
Tomasz Dąbrowski 00e6121260 Safeguard against trying to use C++ exception handling in C code 2016-11-24 09:28:00 +09:00
Tomasz Dąbrowski 401ad4586f Add constant export declaration for MRBC output compiled as C++
Otherwise, C++ compilers will skip this constant when producing object files.
2016-11-24 09:28:00 +09:00
Tomasz Dąbrowski 1af9e363f2 Fixes for compiling mruby as C++ 2016-11-24 09:28:00 +09:00
Yukihiro "Matz" Matsumoto 477e12c182 Merge pull request #3269 from bouk/fix-printf-segfault
Fix segfault when Fixnum#chr doesn't return a string
2016-11-24 09:16:43 +09:00
Yukihiro "Matz" Matsumoto 2c28d00356 Merge pull request #3268 from bouk/fix-random-segfault
Fix segfault in Array#sample
2016-11-24 09:13:34 +09:00
Bouke van der Bijl 9bf1c0e1dc Fix segfault when Fixnum#chr doesn't return a string 2016-11-23 15:18:52 -05:00
Bouke van der Bijl c7262be0ae Fix segfault in Array#sample 2016-11-23 11:21:14 -05:00
Yukihiro "Matz" Matsumoto 669bbc70b0 codegen_scope should not keep old iseq ptr from irep 2016-11-23 21:08:35 +09:00
Yukihiro "Matz" Matsumoto bfbc6b9ea4 local_variables() should not touch unshared env 2016-11-23 20:50:14 +09:00
Yukihiro "Matz" Matsumoto efebbbbf26 Implement Float shift methods in C 2016-11-23 09:45:50 +09:00
Yukihiro "Matz" Matsumoto f414ed03d6 Merge pull request #3265 from dabroz/feature-fixexternc
Fixed C declaration in re.h
2016-11-22 22:22:47 +09:00
Tomasz Dąbrowski 52b40cb4d0 Fixed extern "C" to use MRB_BEGIN/END_DECL in re.h 2016-11-22 13:34:40 +01:00
Yukihiro "Matz" Matsumoto 8cba708854 int64_value(): use FIXABLE() 2016-11-22 19:11:54 +09:00
Yukihiro "Matz" Matsumoto fb7776586e hash value may be overflown from Integer
mruby special.
2016-11-22 18:00:04 +09:00
Yukihiro "Matz" Matsumoto be73905c9c accept floats as bit operator operands; fix #3260 2016-11-22 17:59:41 +09:00
Yukihiro "Matz" Matsumoto 8112295031 Removed fix_shift_get_width()
Fixnum is usually big enough for shift width.
2016-11-22 17:45:07 +09:00
Yukihiro "Matz" Matsumoto 740bf09740 add bit operators ~,&,|,^ to Float class (mruby special) 2016-11-22 17:36:26 +09:00
Yukihiro "Matz" Matsumoto a70104798e remove unnecessary ".!"; ref #3261 2016-11-22 16:55:18 +09:00
Yukihiro "Matz" Matsumoto bbaf3c242d Merge pull request #3261 from ksss/range-first
Reimplements Range#first
2016-11-22 16:38:24 +09:00
Yukihiro "Matz" Matsumoto 03e399accf Merge pull request #3262 from dabroz/feature-nanbox64fix
Fixed NaN boxing for 64-bit configrations
2016-11-22 16:36:43 +09:00
Yukihiro "Matz" Matsumoto de415b7bc0 Merge pull request #3264 from naclyhara/patch-1
Fix typo in test
2016-11-22 16:34:45 +09:00
Yutaka HARA aaa86a1fd5 Fix typo in test 2016-11-22 16:25:18 +09:00
Tomasz Dąbrowski b21b02465e asserts checking validity of pointer and TT added for mrb_obj_value
Useful for testing when using boxing on different platforms.
2016-11-21 12:37:45 +01:00
Tomasz Dąbrowski c385782cfe mrb_assert definition moved to the beggining of mruby.h
So that other files can immediately use it.
2016-11-21 12:37:45 +01:00
Tomasz Dąbrowski 8cdaf1ed35 Fixed NaN boxing for 64-bit configrations on platforms that use full 48-bit usermode pointers
Definition of boxed pointer is following:
`111111111111TTTT TTPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP`

Previously, only the last 32-bit were set, and remaining 14 bits were zeroed when setting `ttt`.
2016-11-21 12:37:45 +01:00
Tomasz Dąbrowski d86f5d2dca mruby architecture detection 2016-11-21 12:37:45 +01:00
ksss 682237be6e Reimplements Range#first
Range#first shouldn't call `Range#to_a` on infinity range.
2016-11-21 16:55:49 +09:00
Yukihiro "Matz" Matsumoto a3f8206ce6 Merge pull request #3259 from dabroz/feature-16bitfix1
Fix for sprintf test exceeding bounds with MRB_INT16
2016-11-21 10:22:47 +09:00
Tomasz Dąbrowski 4289e0cd81 Fix for sprintf test exceeding bounds with MRB_INT16 2016-11-21 00:37:03 +01:00
Yukihiro "Matz" Matsumoto 3ce51cbc7c Merge pull request #3257 from ksss/range-size
Fix Range#size results
2016-11-21 01:15:37 +09:00
ksss 22390aa1c8 Use mrb_float instead of double 2016-11-19 23:25:08 +09:00
ksss a2fbd80a47 Fix Range#size results 2016-11-19 23:25:07 +09:00
Yukihiro "Matz" Matsumoto 0ff3ae1fba Range#include?: simplify condition; ref #3255 2016-11-18 11:54:24 +09:00
Yukihiro "Matz" Matsumoto b03b1e37d9 Merge pull request #3255 from ksss/range-include
Fix condition of Range#include?
2016-11-18 11:48:49 +09:00
ksss 4ef591c897 Fix condition of Range#include? 2016-11-18 10:01:03 +09:00
Yukihiro "Matz" Matsumoto 2a38bf9116 Merge pull request #3254 from herwinw/doc
Doc
2016-11-18 00:02:58 +09:00
Herwin Weststrate 18d6994f78 Documented most methods in mruby/hash.h 2016-11-17 11:52:28 +01:00
Herwin Weststrate d20c56c7fa Documented most methods in mruby/array.h 2016-11-17 11:41:49 +01:00
Herwin Weststrate c043dc631e Typo fix: poped => popped 2016-11-17 11:05:27 +01:00
Yukihiro "Matz" Matsumoto 57900d809f String#include? does not take integers 2016-11-17 18:02:10 +09:00
Yukihiro "Matz" Matsumoto 92be276d76 String#{strip,lstrip,rstrip} may cause OOB access 2016-11-17 18:00:21 +09:00
Yukihiro "Matz" Matsumoto 2e8ed9514f Removed mruby-inline-struct gem from default.gembox; ref #3251
bundled testing gems do not need to be included in default.gembox.
all gems under mrbgems are linked automatically in the test process.
2016-11-17 17:19:49 +09:00
Yukihiro "Matz" Matsumoto 8438792d27 renamed "inline" to "istruct" to represent inline struct; ref #3251 2016-11-17 17:19:49 +09:00
Tomasz Dąbrowski 4cca8bac6b inline structures data type for mruby (MRB_TT_INLINE) (fix #3237)
Inline structures have no instance variables, no finalizer, and offer as much space as possible in RBASIC object. This means 24 bytes on 64-bit platforms and 12 bytes on 32-bit platforms.
mruby-inline-struct gem is only provided for testing.
2016-11-17 17:19:49 +09:00
Yukihiro "Matz" Matsumoto 784e07f902 Merge pull request #3252 from BanzaiMan/patch-1
Remove webhook notification for Travis CI
2016-11-17 16:46:26 +09:00
Yukihiro "Matz" Matsumoto c8b028027f Merge pull request #3253 from ksss/range
Ranges should not rewrite
2016-11-17 16:44:58 +09:00
ksss 176d93d72a Ranges should not rewrite 2016-11-17 14:57:30 +09:00
Hiro Asari 1ba61f055c Remove webhook notification for Travis CI
As travis-rubies now uses 3 Mac jobs to create archives for various OS
releases.

This is a bit wasteful if multiple builds pass in a short period.

Instead, Travis CI is now running a nightly build of mruby-head
(around 22:30 UTC). This will happen regardless of the state of the
master branch.
2016-11-16 19:41:40 -05:00
Yukihiro "Matz" Matsumoto 5208ee534f Merge pull request #3250 from dabroz/feature-correct-aspec
Correct argument specifications for few methods
2016-11-17 00:41:54 +09:00
Tomasz Dąbrowski 8e0dc6fa8d Correct argument specifications for few methods:
- Struct#values_at
 - Module#define_method
 - String#chop
 - String#chop!
2016-11-16 15:46:28 +01:00
Yukihiro "Matz" Matsumoto 1685eff2a5 Fixed off-by-one error in String#[]= with Ranges 2016-11-16 10:16:14 +09:00
Yukihiro "Matz" Matsumoto 1f554ff854 Fixed rindex calling into mrb_equal bug
Fixed by Alex Snaps and reported by Mathieu Leduc-Hamel,
both from shopify.com.  Thank you!
2016-11-16 02:10:44 +09:00
Yukihiro "Matz" Matsumoto 242b219471 Fixed memory disclosure in String#lines
Reported from from Alex Snaps via Mathieu Leduc-Hamel,
both from shopify.com.  Thank you!
2016-11-16 02:05:19 +09:00
Yukihiro "Matz" Matsumoto 92f72c7490 make String#[]= to take Ranges as position argument 2016-11-16 02:04:56 +09:00
Yukihiro "Matz" Matsumoto 739dad6e87 Fixed a memory problem in Array#to_h
Reported from Alex Snaps via Mathieu Leduc-Hamel,
both from shopify.com.  Thank you!
2016-11-16 01:29:04 +09:00
Yukihiro "Matz" Matsumoto 4f6cce059b class/module statement should re-open; fix #3225 2016-11-15 04:15:24 +09:00
Yukihiro "Matz" Matsumoto 1422e57630 move mrb_str_dup() to mrb_class_path; ref #2470
Class#to_s used to return same string repeatedly,
that mean you can modify "class name" by modifying
the return value from Class#to_s.
2016-11-13 16:17:44 +09:00
Yukihiro "Matz" Matsumoto 01dddaf385 rename mruby-module-ext to mruby-class-ext; ref #2470 2016-11-13 16:17:44 +09:00
take_cheeze 451985d44b Implement Module#name.
Solves #2132.
2016-11-13 16:17:36 +09:00
Yukihiro "Matz" Matsumoto 88604e39ac Hash#[] to call Hash#default 2016-11-12 05:23:05 +09:00
Yukihiro "Matz" Matsumoto feb9b3debd Merge pull request #3224 from ksss/define_method
Module#define_method supports proc argument
2016-11-11 22:57:52 +09:00
Yukihiro "Matz" Matsumoto 752ca514f6 do not dump_node if parser failed 2016-11-11 22:51:48 +09:00
Yukihiro "Matz" Matsumoto 185dad3a6e node_dump() to print NODE_HEREDOC terminator 2016-11-11 22:50:41 +09:00
Yukihiro "Matz" Matsumoto 45aadd7e60 HEREDOC could fail with NUL terminated lines; fix#3244 2016-11-11 22:49:23 +09:00
Yukihiro "Matz" Matsumoto e86ead436a Merge pull request #3246 from ksss/cycle
Reimplement Enumerable#cycle
2016-11-11 20:43:22 +09:00
ksss 7685783af4 Add regression test for Enumerable#cycle 2016-11-11 16:53:42 +09:00
ksss 126d55480d Reimplement Enumerable#cycle
Fix pattern of infinite loop
And support all specs in https://github.com/ruby/spec/blob/27960d06e0ce92c37f074450f0eab4b0519b118c/core/enumerable/cycle_spec.rb without Enumerable#size
2016-11-11 16:53:42 +09:00
Yukihiro "Matz" Matsumoto 3d946a8044 Merge pull request #3240 from dabroz/feature-fixtest
test/assert.rb should not use puts
2016-11-11 13:36:53 +09:00
Yukihiro "Matz" Matsumoto 570cbbdf3d Merge pull request #3234 from AltimitSystems/mrb.class_under_defined
Add mrb_class_defined_under
2016-11-11 08:24:52 +09:00
Felix Jones 70aa6dc38d Merge branch 'master' into android.rake-ndk-clang 2016-11-10 20:01:59 +00:00
Felix Jones 178816626d Merge branch 'mrb.class_under_defined' 2016-11-10 19:52:27 +00:00
Felix Jones e3c8092ccd Renamed class_under_defined to class_defined_under 2016-11-10 19:51:56 +00:00
Yukihiro "Matz" Matsumoto 3f002b6993 fixed a bug when number of LHS and RHS differs; fix #3239 2016-11-11 04:37:42 +09:00
Tomasz Dąbrowski 617050450e test/assert.rb should not use puts 2016-11-10 13:17:59 +01:00
Yukihiro "Matz" Matsumoto 872517dff3 class variables in higher order have a priority; fix #3235 2016-11-08 23:51:15 +09:00
Yukihiro "Matz" Matsumoto 1142cf2037 fixed a bug with [] in RHS of multiple assignments; fix #3236 2016-11-08 22:18:41 +09:00
Yukihiro "Matz" Matsumoto 6c299aae67 fixed wrong stack adjustment for ensure clauses; fix #3175 2016-11-07 00:44:08 +09:00
Felix Jones cc5f40b2db mrb_class_under_defined docs renamed parent and child to outer and inner 2016-11-06 13:19:14 +00:00
Felix Jones 8d6aa06548 Added mrb_class_under_defined 2016-11-06 13:01:21 +00:00
Yukihiro "Matz" Matsumoto 0b8d8dd379 associate REnv to the executing block; fix #3214 2016-11-05 02:52:34 +09:00
Yukihiro "Matz" Matsumoto 46995c3264 add quoted symbol tests; ref #3231 2016-11-04 14:21:46 +09:00
Yukihiro "Matz" Matsumoto 2960c69435 Merge pull request #3232 from lukaselmer/patch-1
Update documentation of fetch
2016-11-03 13:39:24 +09:00
Lukas Elmer f02694ecc7 Update documentation of fetch
The sentence `Negative values of +index+ count from the end of the array.` can be interpreted that it only holds if a block is given. Clarify it.
2016-11-02 19:45:43 +01:00
Yukihiro "Matz" Matsumoto cc3f1b7f5c allow single quoted labels in hashes; ref #3231 2016-11-02 16:14:20 +09:00
Yukihiro "Matz" Matsumoto 13d0832965 allow quoted labels in hashes; fix #3231 2016-11-02 08:41:43 +09:00
Yukihiro "Matz" Matsumoto 9a126278b6 should not unshare() reclaimed env objects; fix #3230 2016-10-28 09:21:14 +09:00
Yukihiro "Matz" Matsumoto c45ed46f28 macro mrb_bool() may evaluate arg multiple times; ref #3228 2016-10-24 01:30:31 +09:00
Yukihiro "Matz" Matsumoto 7061658b5b Merge pull request #3228 from ksss/respond_to_missing
Kernel#respond_to? should return true|false only
2016-10-24 01:27:13 +09:00
ksss 022e147b78 Kernel#respond_to? should return true|false only 2016-10-23 18:25:47 +09:00
Yukihiro "Matz" Matsumoto 6fd0e601cf Move to_proc conversion from OP_ENTER to OP_SENDB; fix #3227 2016-10-20 23:49:40 +09:00
Tomoyuki Sahara b5e2dc9097 raise an exception when we cannot close "fd" but can close "fd2". 2016-10-13 16:57:38 +09:00
ksss efe4f30b39 Module#define_method supports proc argument 2016-10-12 22:19:54 +09:00
Yukihiro "Matz" Matsumoto 8488425e50 Merge pull request #3223 from AltimitSystems/android.rake-ndk-clang
Android Task GCC support re-added
2016-10-08 23:34:48 +09:00
Felix Jones c3f271a861 Merge branch 'master' of github.com:mruby/mruby 2016-10-08 15:12:45 +01:00
Felix Jones b83bcd12df Removed GCC TODO 2016-10-08 15:10:46 +01:00
Felix Jones 3e9fe81591 Android GCC support re-added 2016-10-08 15:09:08 +01:00
Yukihiro "Matz" Matsumoto 364761f473 Merge pull request #3222 from AltimitSystems/android.rake-ndk-clang
Android mips/mips64 support
2016-10-08 10:33:54 +09:00
Felix Jones 5d2795c00d Fixed mips and mips64: GCC Toolchain now points to GCC. 2016-10-08 00:23:55 +01:00
Felix Jones 5fd068eb4d Android task: NDK default search paths now favour ndk-bundle. Added macOS NDK search paths. 2016-10-07 22:31:24 +01:00
Tomoyuki Sahara f6a82772e6 eof? should raise an IOError if it is not opened for reading. 2016-09-30 17:10:55 +09:00
Tomoyuki Sahara 2229a2aa0f reimplement #eof. fixes #66. 2016-09-30 16:27:11 +09:00
Yukihiro "Matz" Matsumoto 2d335daeeb Merge pull request #3218 from nobu/trailing-space
Removed trailing spaces
2016-09-28 15:51:02 +09:00
Nobuyoshi Nakada 6511bfd79a Removed trailing spaces 2016-09-28 12:29:41 +09:00
Yukihiro "Matz" Matsumoto 9d3167cabe Merge pull request #3217 from ksss/break
Fix unexpected behavior with break
2016-09-27 10:31:48 +09:00
Yukihiro "Matz" Matsumoto afbe211c60 mrb_str_strlen() should be MRB_API; ref #3216 2016-09-27 10:29:56 +09:00
Yukihiro "Matz" Matsumoto 6bc4b47c46 Merge pull request #3216 from kou/remove-needless-mrbapi
Remove needless MRB_API
2016-09-27 10:28:04 +09:00
ksss b1fa180ea3 Fix unexpected behavior with break
```
def yie
  yield
end

def bre
  yie {
    1+1
    break
  }
end

p bre #=> display 2, but should be nil
```
2016-09-26 12:17:46 +09:00
Kouhei Sutou 91bd3ebd32 Remove needless MRB_API
ref #3215

If a function (such as mrb_read_irep_file()) is declared without MRB_API
in header file (such as include/mruby/dump.h), implementation of the
function in source file (such as src/load.c) should also defined without
MRB_API.

If MRB_API is mismatch, Visual C++ reports link error with C2375 error
code: https://msdn.microsoft.com/en-us/library/5k6kw95a.aspx
2016-09-25 21:47:49 +09:00
Yukihiro "Matz" Matsumoto 7a382e8bdf Remove unnecessary MRB_API from read_irep related functions; ref #3215 2016-09-24 05:26:51 +09:00
Yukihiro "Matz" Matsumoto 77d004e835 Merge pull request #3213 from unak/print-visualc
Visual C++ support of UTF-8 hack on mruby-print
2016-09-22 00:41:04 +09:00
U.Nakamura 36c08476d9 Use non-underscore'ed names
Accept @mattn's comment.
2016-09-21 14:39:08 +09:00
U.Nakamura 37d2d57d63 Use underbar'ed name to get rid of warnings 2016-09-21 12:59:36 +09:00
U.Nakamura e5fedaf67f Not only for MINGW but also for Visual C++ 2016-09-21 12:58:58 +09:00
Kazuaki Tanaka cb29c9b415 Fix return value type of bytecode_decoder 2016-09-20 23:15:49 +00:00
Kazuaki Tanaka 968ebac001 Bytecode decoder support, MRB_BYTECODE_DECODE_OPTION 2016-09-20 23:07:28 +00:00
Yukihiro "Matz" Matsumoto c698c67e10 Merge pull request #3211 from eregon/fix_limitation_typos
Fix a couple typos in limitations.md
2016-09-18 08:58:51 +09:00
Benoit Daloze 5f37d8bd89 Fix a couple typos in limitations.md 2016-09-17 23:14:55 +02:00
Yukihiro "Matz" Matsumoto 6498970d81 Merge pull request #3210 from AltimitSystems/android.rake-ndk-clang
Fixed regex order falling early in arch cases, causing x86_64 and arm…
2016-09-16 08:33:01 +09:00
Felix Jones 04ae2960f4 Fixed regex order falling early in arch cases, causing x86_64 and arm-v7a to use wrong target. 2016-09-15 18:14:27 +01:00
Yukihiro "Matz" Matsumoto 07e905ef02 Merge pull request #3209 from AltimitSystems/master
Re-written android.rake task for latest Android NDK clang. Currently …
2016-09-16 00:33:50 +09:00
Felix Jones 18662ff576 Re-written android.rake task for latest Android NDK clang. Currently loses support for GCC and mips, mips64. Addresses issue #3208 2016-09-15 15:57:44 +01:00
Tomoyuki Sahara 51cf6b6048 Merge pull request #65 from ksss/join
Support Array argument
2016-09-13 09:57:05 +09:00
ksss ff845be72c Support Array argument 2016-09-11 22:01:45 +09:00
ksss 7c9d941003 Show value of expect and actual each assertion 2016-09-11 17:00:19 +09:00
Yukihiro "Matz" Matsumoto 08a1dd2ac8 Merge pull request #3207 from ksss/splat
Fix SEGV when splat object
2016-09-08 21:13:12 +09:00
ksss d467022347 Add testing for regression 2016-09-08 16:35:41 +09:00
ksss d265c03da0 Fix SEGV when splat object
Splat operation should return an array.
And raise an error if result of convert by to_a is not array or nil.
2016-09-08 16:35:17 +09:00
Yukihiro "Matz" Matsumoto cd5133c570 Merge pull request #3205 from yurie/abort-header
surpress warning when MRB_DISABLE_STDIO
2016-09-06 23:14:25 +09:00
Yukihiro "Matz" Matsumoto 028dcfe881 Merge pull request #3206 from ksss/env
Fix SEGV when unshared env
2016-09-06 23:13:58 +09:00
yuri c9d4d96872 surpress warning when MRB_DISABLE_STDIO 2016-09-06 22:41:50 +09:00
ksss e66b35c6ee Fix SEGV when unshared env 2016-09-06 17:11:18 +09:00
Yukihiro "Matz" Matsumoto 9040086e92 Merge pull request #3204 from ksss/mid
Should clear method name
2016-09-05 22:36:19 +09:00
ksss a5c2e95b10 Should clear method name
- Fix method name in top-level
- Fix SEGV when call Exception#backtrace if callinfo over CALLINFO_INIT_SIZE(32)
2016-09-05 21:58:08 +09:00
Yukihiro "Matz" Matsumoto d58c2585d4 Merge pull request #3202 from pbosetti/master
In mrbgem_spec.rake, added support for @mrblib_dir @objs_dir, so that a gem can have custom source directory names
2016-09-05 13:06:40 +09:00
Yukihiro "Matz" Matsumoto 495545ab09 Merge pull request #3203 from nozomiS/mrbc_filename-fix
Fix mrbc_filename leak
2016-09-05 13:02:32 +09:00
Nozomi SATO 068b46d5e2 - fix mrbc_filename leak; cxt->filename would not be freed until the state is closed. 2016-09-04 18:35:23 +09:00
Paolo Bosetti ac9b6f2a11 In mrbgem_spec.rake, added support for @mrblib_dir @objs_dir, so that a gem can have custom source directory names 2016-09-02 17:38:40 +02:00
Yukihiro "Matz" Matsumoto bf0893586a Merge pull request #3192 from ksss/instance_eval
instance_eval env should remake Fix #3191
2016-08-31 23:15:42 +09:00
Yukihiro "Matz" Matsumoto b3236b2a71 mruby-random: fixed typos 2016-08-30 10:52:44 +09:00
Yukihiro "Matz" Matsumoto fa76bbeb07 mruby-random: add reporting URL since we modified the source 2016-08-30 09:03:14 +09:00
Yukihiro "Matz" Matsumoto 22dc84f72a Fixed spell errors in test/t/lang.rb; ref #3199 2016-08-20 21:57:20 +09:00
Yukihiro "Matz" Matsumoto c313fdfed0 Merge pull request #3199 from miura1729/original
Add new test for optimize VM
2016-08-20 21:35:17 +09:00
Miura Hideki 1751d8fd3b Add new test for optimize VM 2016-08-20 20:30:37 +09:00
Yukihiro "Matz" Matsumoto ff3e4b91f2 Move Module#include and #prepend to class.c; ref #3197
To avoid VM nesting with mrb_funcall()
2016-08-20 00:03:30 +09:00
Yukihiro "Matz" Matsumoto b2fceae461 renamed class.rb and error.rb to ensure they are read first; ref #3197 2016-08-19 14:10:23 +09:00
Yukihiro "Matz" Matsumoto 67ad1ff11e Merge pull request #3198 from nobu/feature/lparen_arg-stmt
parse.y: lparen_arg statement
2016-08-19 12:52:40 +09:00
Nobuyoshi Nakada 73dd82e30a parse.y: lparen_arg statement
allow parenthesised statement as a method argument.
reported [Feature:12686] in bugs.ruby-lang.org fixed in CRuby 2.4.
2016-08-19 11:11:54 +09:00
Yukihiro "Matz" Matsumoto 0597f66b23 Merge pull request #3196 from mimaki/fix-negative-ord
Fix String#ord failure which return a negative value
2016-08-17 17:00:01 +09:00
Hiroshi Mimaki 861b0eed7b Fix String#ord failure which return a negative value 2016-08-17 15:29:59 +09:00
Yukihiro "Matz" Matsumoto ee40f9bbbd Merge pull request #3195 from franckverrot/master
Correct method name
2016-08-16 13:44:23 +09:00
Franck Verrot f6a2f67648 Correct method name 2016-08-15 20:49:32 -07:00
Yukihiro "Matz" Matsumoto 86821379fd Merge pull request #3194 from nobu/chained-rhs
parse.y: fix chained assignments
2016-08-13 14:06:35 +09:00
Nobuyoshi Nakada bdd7e2bc8c parse.y: fix chained assignments
fix syntax errors with chained assignment with op assign.
reported [Bug:12669] in bugs.ruby-lang.org fixed in CRuby 2.4.
2016-08-13 13:56:14 +09:00
Yukihiro "Matz" Matsumoto bee34fb9bd Merge pull request #3193 from nobu/rhs-rescue
parse.y: simplify 90e8ce5
2016-08-12 10:29:46 +09:00
Nobuyoshi Nakada a06940daa9 parse.y: simplify 90e8ce5
simplify tOP_ASGN rules by command_rhs and arg_rhs rules with
%prec.
2016-08-12 10:14:35 +09:00
Yukihiro "Matz" Matsumoto 90e8ce5c30 parse.y: rescue modifiers for OP_ASGN should protect rhs only
reported in [Bug:12402] in bugs.ruby-lang.org fixed in CRuby 2.4
2016-08-11 16:27:14 +09:00
Tomoyuki Sahara d8189c2b19 Merge pull request #64 from asfluido/master
Apparently, in mruby-process gem, Process is now a Module, not a Class
2016-08-10 09:12:44 +09:00
Carlo - PERI 024b09de0c Apparently, in mruby-process gem, Process is now a Module, not a Class 2016-08-09 11:23:49 +02:00
ksss ada264a513 instance_eval env should remake Fix #3191 2016-08-08 12:41:19 +09:00
Yukihiro "Matz" Matsumoto 7a7fac8412 removed ChangeLog that has not been updated for long time; ref #3190 2016-08-08 12:38:21 +09:00
Yukihiro "Matz" Matsumoto af4567bb41 update copyright notice and license description for mt19937ar.[ch]
despite the fact original authors agreed to distribute their work
under MIT license, it does not mean mt19937ar.[ch] became the work
of mruby developers. To clarify, we updated copyright and license
notice of the source files.
2016-08-08 12:38:21 +09:00
Tomoyuki Sahara b341ee7c12 Merge pull request #63 from ksss/opt
Enable option :in, :out, :err to IO.popen
2016-08-08 10:12:20 +09:00
Tomoyuki Sahara 9ccf03e5ae Merge pull request #62 from ksss/global
Should use global variable
2016-08-08 09:38:22 +09:00
ksss d2c1f4d10b Enable Fixnum option 2016-08-07 22:19:21 +09:00
ksss b462ef4506 Enable option :in, :out, :err 2016-08-07 21:21:01 +09:00
ksss 4cac5e9c70 Should use global variable 2016-08-06 23:11:31 +09:00
Yukihiro "Matz" Matsumoto 501e1ef260 Merge pull request #3189 from wrl/public-hash-values
make mrb_hash_values() a public API function
2016-08-03 02:26:04 +09:00
William Light e02a88e031 make mrb_hash_values() a public API function 2016-08-01 11:05:46 +02:00
Yukihiro "Matz" Matsumoto eb7422af58 Merge pull request #3188 from guoxiao/warning
intptr_t should be used instead of uint32_t to hold a pointer.
2016-07-31 14:37:39 +09:00
Guo Xiao 339005e1d5 intptr_t should be used instead of uint32_t to hold a pointer.
Fix warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
2016-07-31 12:53:39 +08:00
Yukihiro "Matz" Matsumoto 42fefef916 Merge pull request #3186 from rmalizia44/patch-2
Update mirb.c
2016-07-28 10:59:32 +09:00
Malizia R 1c7572bc6a Update mirb.c 2016-07-27 16:51:10 -03:00
Yukihiro "Matz" Matsumoto 2b4ed40fc9 Merge pull request #3185 from kou/string-reduce-needless-array
Reduce needless Array generation in some String methods
2016-07-27 14:03:52 +09:00
Kouhei Sutou 6bb0775d76 Reduce needless Array generation in some String methods
Here are some benchmarks:

each_char:

    # /tmp/each_char.rb
    a = "a" * 1000000
    a.each_char do |x|
    end

Without this change:

    % time bin/mruby /tmp/each_char.rb
    bin/mruby /tmp/each_char.rb  1.07s user 0.02s system 99% cpu 1.088 total

With this change:

    % time bin/mruby /tmp/each_char.rb
    bin/mruby /tmp/each_char.rb  0.52s user 0.01s system 99% cpu 0.530 total

2 times faster with this change.

codepoints:

    # /tmp/codepoints.rb
    a = "a" * 1000000
    a.codepoints do |x|
    end

Without this change:

    % time bin/mruby /tmp/codepoints.rb
    bin/mruby /tmp/codepoints.rb  1.16s user 0.05s system 99% cpu 1.216 total

With this change:

    % time bin/mruby /tmp/codepoints.rb
    bin/mruby /tmp/codepoints.rb  0.56s user 0.02s system 99% cpu 0.589 total
2016-07-27 13:58:07 +09:00
Yukihiro "Matz" Matsumoto 3757b16dab Merge pull request #3184 from ksss/each_char
Support to call without block to String#each_char
2016-07-27 02:32:04 +09:00
ksss bef63a4f91 Support to call without block to String#each_char 2016-07-26 18:46:23 +09:00
Yukihiro "Matz" Matsumoto 32ad74f4d1 Merge pull request #3182 from sdottaka/fix-broken-msvc-build
Fix broken msvc build
2016-07-26 00:13:53 +09:00
Yukihiro "Matz" Matsumoto e635dc2a47 Merge pull request #3181 from sdottaka/fix-crash-on-mrb_parser_free
Fix crash in mrb_parser_free() due to freed memory access
2016-07-26 00:12:54 +09:00
Yukihiro "Matz" Matsumoto 62a16673a6 Merge pull request #3183 from Mav7/mav7/docs
yard docs for string.h
2016-07-25 15:07:30 +09:00
Yukihiro "Matz" Matsumoto a66a1e92e7 Merge pull request #3179 from ksss/struct
Should not define to `Struct` class
2016-07-25 14:19:10 +09:00
Yukihiro "Matz" Matsumoto 34ac707ea3 OP_ASGN vsp may be negative
reported by https://gist.github.com/miura1729/53fbd8af889c289a79108e38635b2378
fix proposed by @miura1729 in
https://github.com/miura1729/mruby/commit/b1b7933f7aa950cfb747b06327a0d0340f3e4ff8
2016-07-25 11:34:55 +09:00
Yukihiro "Matz" Matsumoto 417092360d Fixed crash error when #initialize is redefined for Struct; fix #3177
refactored redundant functions; removed optimized accessors for safety
this fix also close #3178
2016-07-25 10:32:10 +09:00
Ralph Desir(Mav7) 189ad47346 yard docs for string.h 2016-07-23 02:47:32 -04:00
Takashi Sawanaka fb1c4b3ba7 Fix broken msvc build 2016-07-23 11:57:36 +09:00
Takashi Sawanaka 2eefbfed9d Fix crash in mrb_parser_free() due to freed memory access 2016-07-23 11:34:04 +09:00
ksss bf21063a72 Add regression test 2016-07-22 15:26:17 +09:00
ksss 1a8074accf Should not define to Struct class 2016-07-22 15:26:11 +09:00
Tomoyuki Sahara cc66bf94d1 Merge pull request #9 from ksss/pointer-sign
Suppress compiler warning [-Wpointer-sign]
2016-07-19 09:45:32 +09:00
Tomoyuki Sahara 13650747e7 Merge pull request #10 from dabroz/master
Added 'U' pack support.
2016-07-19 09:44:14 +09:00
Tomasz Dąbrowski 26c1dedcab Added 'U' pack support. 2016-07-18 16:06:01 +02:00
Yukihiro "Matz" Matsumoto 97283faa16 Merge pull request #3176 from ksss/string-insert
String#insert should be destructive
2016-07-15 01:22:02 +09:00
ksss d83d9cd164 String#insert should be destructive 2016-07-14 21:33:15 +09:00
Yukihiro "Matz" Matsumoto 72b28f1ed6 Merge pull request #3174 from ksss/local-jump-error
Should raise LocalJumpError when no block given
2016-07-14 17:10:54 +09:00
ksss 9dc820590f Should raise LocalJumpError when no block given 2016-07-14 13:03:25 +09:00
Yukihiro "Matz" Matsumoto d4d807b774 relax string length limitation to 64KB; fix #2725 2016-07-13 03:22:15 +09:00
Yukihiro "Matz" Matsumoto 2e74a93112 Merge pull request #3171 from kjunichi/c-has-no-try
C doesn't have try-catch
2016-07-08 12:14:46 +09:00
Junichi Kajiwara f67631afb4 C doesn't have try-catch 2016-07-08 06:30:45 +09:00
Yukihiro "Matz" Matsumoto 0d9aa830aa Merge pull request #3169 from ksss/Wshift-negative-value
Fix warning shift-negative-value
2016-07-02 00:55:00 +09:00
ksss b9f7daf5b6 Suppress compiler warning [-Wpointer-sign] 2016-07-01 22:27:02 +09:00
ksss e3bc81e75e Fix warning shift-negative-value 2016-07-01 22:00:55 +09:00
Yukihiro "Matz" Matsumoto 3c406d54be Merge pull request #3166 from yyamano/fix-gc-profile
Fix compilation error with GC_PROFILE.
2016-06-30 14:32:53 +09:00
Yuji Yamano 00faf3d317 Fix compilation error with GC_PROFILE. 2016-06-29 03:57:02 -04:00
Tomoyuki Sahara 93d481d4b4 update $? when IO object is closed. closes #58. 2016-06-22 10:29:49 +09:00
Tomoyuki Sahara e90ecff671 Merge pull request #60 from drbrain/test_io_setup_failure
Test io setup failure
2016-06-21 09:52:30 +09:00
Tomoyuki Sahara 2af2a4fff8 add IO#isatty and IO#tty? 2016-06-21 09:49:34 +09:00
Yukihiro "Matz" Matsumoto fa1c1ab487 Merge pull request #3163 from mattn/fix-public_methods
Fix public methods
2016-06-18 11:40:32 +09:00
Yasuhiro Matsumoto 8a15ab0c0c add test for public_methods(false) 2016-06-18 01:21:21 +09:00
Yasuhiro Matsumoto 8764bd282c fix public_methods(false) 2016-06-18 01:18:24 +09:00
Yukihiro "Matz" Matsumoto a8af43f61e Merge pull request #3162 from udzura/patch-1
Update doc, write about add_test_dependency
2016-06-14 19:10:04 +09:00
Uchio KONDO 481aa31f93 Update doc, write about add_test_dependency 2016-06-14 16:37:06 +09:00
Yukihiro "Matz" Matsumoto 09b11850a5 mrb_gc_unregister() to remove one registration; close #3160
when multiple mrb_gc_register() were called for the same object
2016-06-10 10:12:48 +09:00
Yukihiro "Matz" Matsumoto 44de80f76d fix a compiler warning for uninitialized variable 2016-06-10 10:11:58 +09:00
Yukihiro "Matz" Matsumoto 8dde647a51 add temporary workaround for irep memory corruption
need to find out real memory bug that appears in full-debug/mrbtest
2016-06-10 10:04:52 +09:00
Tomoyuki Sahara b2a0c9c6bf Merge pull request #30 from rhykw/tcpserver-reuseaddr
Use TCPServer SO_REUSEADDR
2016-05-30 10:42:30 +09:00
rhykw 4f6703203b TCPServer use SO_REUSEADDR if possible 2016-05-28 09:33:53 +09:00
rhykw 2a80cccf30 TCPServer use SO_REUSEADDR 2016-05-23 21:44:34 +09:00
Yukihiro "Matz" Matsumoto 6b0299f72b fixed remaining bugs in OP_ASGN stack adjustment; close #3159 2016-05-16 15:36:36 +09:00
Yukihiro "Matz" Matsumoto 29d3a40418 stack adjustment after NODE_OP_ASGN with NODE_CALL was wrong; fix #3159 2016-05-16 01:49:24 +09:00
Yukihiro "Matz" Matsumoto 2e81fee731 parser_dump() to show symbol number for NODE_SYM 2016-05-16 01:49:24 +09:00
Eric Hodel 11961b42ac Create socket in /tmp for security
Some systems do not allow UNIX sockets from arbitrary directories.
Instead of trying to `#define SOCKET_PATH` correctly I assume the /tmp/
directory is accessible and use it.
2016-05-12 17:55:14 -07:00
Eric Hodel 777cf70cc5 Include reason in test failure message
I am seeing this test fail in some environments but can't determine why.
The extra information will help me determine the reason bind(2) is
failing.
2016-05-12 16:02:09 -07:00
Yukihiro "Matz" Matsumoto 5933651ac7 Merge pull request #3157 from cremno/add-mrb_int_mul_overflow
add function for checked mrb_int multiplication
2016-05-11 09:41:19 +09:00
cremno 7453a5dfea use mrb_int_mul_overflow() 2016-05-10 19:12:02 +02:00
cremno 6369374f79 add mrb_int_mul_overflow(); close #3149
- call __builtin_mul_overflow() if it's available
- perform a 64-bit multiplication for 32-bit mrb_int (default)
- otherwise a much slower method is used
2016-05-10 19:10:49 +02:00
Yukihiro "Matz" Matsumoto 0be4b8960e Merge pull request #3156 from cremno/fix-mruby_version-value
fix MRUBY_VERSION value
2016-05-10 10:04:31 +09:00
Yukihiro "Matz" Matsumoto 4fd0cb61d7 Merge pull request #3154 from cremno/improve-checked-mrb_int-arithmetic-implementation
improve checked mrb int arithmetic implementation
2016-05-10 10:04:04 +09:00
Yukihiro "Matz" Matsumoto bc715f9938 Merge pull request #3155 from cremno/fix-3152
fix #3152
2016-05-10 09:18:25 +09:00
cremno bf63cff46e fix MRUBY_VERSION value
RUBY_ENGINE_VERSION and MRUBY_VERSION should refer to the same string.
2016-05-09 17:19:47 +02:00
cremno 309791b3ae raise the error at runtime; fix #3152 2016-05-09 16:57:56 +02:00
cremno 7276e84637 use type-generic checked arithmetic builtins
Version checking is not reliable - especially with Clang.
E.g. Apple's Clang (Xcode) uses different version numbers.
A feature check (__has_builtin) is the recommened way.

Add the MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
macro which may be used in other files.
2016-05-09 16:52:57 +02:00
cremno 39b6a9dafc define macros only if builtins are n/a 2016-05-09 16:34:20 +02:00
Yukihiro "Matz" Matsumoto b4e1889813 Merge pull request #3153 from kou/remove-needless-assignment
Remove needless assignment
2016-05-09 17:35:19 +09:00
Kouhei Sutou 51cc35dc09 Remove needless assignment
d4ee409ae9 should remove this line.
2016-05-09 14:05:51 +09:00
Yukihiro "Matz" Matsumoto ea033526fb Merge pull request #3151 from okkez/use-stack-directly
Use stack directly
2016-04-27 12:14:54 +09:00
Kenji Okimoto d4ee409ae9 Use stack directly
See https://github.com/mruby/mruby/pull/3142#issuecomment-201138873
2016-04-27 10:18:13 +09:00
Yukihiro "Matz" Matsumoto 8f0c1c7d3c mruby-sprintf:fix double negative signs in printf; fix #3148
MRB_INT_MAX does not have corresponding positive integer
2016-04-23 23:50:01 +09:00
Yukihiro "Matz" Matsumoto c5229074bb mruby-sprintf: format specifiers o,u,x,b ignore sign(+); ref #3148 2016-04-23 22:20:11 +09:00
Yukihiro "Matz" Matsumoto e5c2013829 Merge pull request #3147 from ksss/1.8
Avoid Syntax Error on CRuby v1.8
2016-04-16 23:27:15 +09:00
ksss 451523ff02 Avoid Syntax Error on CRuby v1.8
CRuby v1.8 dose not support named capture
2016-04-16 22:39:09 +09:00
Yukihiro "Matz" Matsumoto fa1a17cbc4 Merge pull request #3145 from timoschilling/patch-1
fix syntax highlighting
2016-04-14 00:04:54 +09:00
Timo Schilling 1863f325c0 fix syntax highlighting 2016-04-13 13:41:31 +02:00
Yukihiro "Matz" Matsumoto 8c67e915b4 mruby-eval: instance_eval should keep target_class; close #3141 2016-04-11 14:28:44 +09:00
Yukihiro "Matz" Matsumoto ae5b5ce575 vm.c: mrb_hash_set() may reallocate VM stack; close #3133 2016-04-11 14:11:44 +09:00
Yukihiro "Matz" Matsumoto d97a37eb7b fix possible memory leak in mruby-time gem 2016-04-04 21:58:46 +09:00
Yukihiro "Matz" Matsumoto e1e888e354 fix too much optimization for ||= 2016-04-01 01:22:16 +09:00
Yukihiro "Matz" Matsumoto d098d823de fix duplicated eval in op_asgn
`a` in `a.m += c` or `a[b] += c` should be evaluated only once.
2016-03-30 20:43:57 +09:00
Yukihiro "Matz" Matsumoto 4979b52d61 reduce OP_ARRAY in argument splat 2016-03-30 01:35:11 +09:00
Yukihiro "Matz" Matsumoto 0e03a7f2a3 mruby-enum-ext: refine minmax 2016-03-30 01:12:18 +09:00
Yukihiro "Matz" Matsumoto 4d909d8b2b Merge pull request #3142 from kou/add-missing-regs-update
Add missing regs update
2016-03-25 13:41:35 +09:00
Kouhei Sutou c69cba2ad9 Add missing regs update
mrb_vm_define_class() may realloc() mrb->c->stack because it calls
mrb_funcall() for inherited hook. If mrb->c->stack is realloc()-ed, regs
refers orphan address.
2016-03-25 00:25:48 +09:00
Yukihiro "Matz" Matsumoto dd072b5364 remove wrong ISO section from safe navigation test; ref 4c1ce0f6 2016-03-24 23:35:04 +09:00
Yukihiro "Matz" Matsumoto 3886becec5 better code generation for ||=; #3138 2016-03-24 16:03:58 +09:00
Yukihiro "Matz" Matsumoto 1ce471c1cc ||= with cvars and constants should work with false values; #3138 2016-03-24 07:59:58 +09:00
Yukihiro "Matz" Matsumoto 4fcff34747 ||= reference error can happen with constants as well; #3138 2016-03-23 23:51:23 +09:00
Yukihiro "Matz" Matsumoto 817b884343 add #dig tests 2016-03-23 12:34:32 +09:00
Yukihiro "Matz" Matsumoto daf83946bb add #dig to Array,Hash and Struct 2016-03-23 11:49:28 +09:00
Yukihiro "Matz" Matsumoto 4c1ce0f61c add safe-navigation operator tests 2016-03-23 08:51:25 +09:00
Yukihiro "Matz" Matsumoto 21a3ae08f7 add safe-navigation (aka lonely) operator &. 2016-03-23 08:51:25 +09:00
Yukihiro "Matz" Matsumoto 7d0612528e Merge pull request #3139 from cremno/fix-vs2010-build
deprecate and fix VS2010/2012 build
2016-03-23 00:22:26 +09:00
cremno 30b0100e6c fix VS2010/2012 build
They don't have <inttypes.h>, only <stdint.h>.
2016-03-22 11:46:49 +01:00
cremno bfc7b2e30f deprecate Visual Studio 2010 and 2012 2016-03-22 11:41:16 +01:00
cremno 611e99e741 remove unnecessary array/each 2016-03-22 11:38:09 +01:00
Yukihiro "Matz" Matsumoto 2b0baec32a fixed silly class variable/constant confusion; #3138 2016-03-22 00:06:32 +09:00
Yukihiro "Matz" Matsumoto a02acf2635 rescue NameError from class variable access like @@foo ||= 42; fix #3138 2016-03-21 03:49:08 +09:00
Yukihiro "Matz" Matsumoto 643d967b10 Merge pull request #3131 from bggd/fix_bintest_on_windows
Fix doesn't work bintest on :visualcpp toolchain
2016-03-16 16:29:14 +09:00
Yukihiro "Matz" Matsumoto 52d388515f Merge pull request #3132 from pbosetti/edison
Added example for cross-compiling on Intel Edison
2016-03-16 16:28:35 +09:00
Yukihiro "Matz" Matsumoto 273eac6b64 Merge pull request #3136 from bggd/add_appveyor
Add appveyor.yml
2016-03-16 16:27:58 +09:00
bggd 51cb72962d Create appveyor_config.rb 2016-03-15 20:43:51 +09:00
bggd 87e5b0f30c Add appveyor.yml for Visual Studio 2015/2013 2016-03-15 20:41:15 +09:00
Yukihiro "Matz" Matsumoto 4f20d58ac2 Merge pull request #3135 from wanabe/reduce-include-paths
Reduce compiler include_paths
2016-03-14 09:35:53 +09:00
wanabe 2aa6b449a2 Reduce compiler include_paths 2016-03-13 17:06:39 +09:00
Paolo Bosetti a27426aa8d Added example for cross-compiling on Intel Edison 2016-03-07 17:50:03 +01:00
bggd a138ae3506 Fix doesn't work bintest on :visualcpp toolchain 2016-03-07 14:50:21 +09:00
Yukihiro "Matz" Matsumoto 41d6ba23b5 fix dump_prefix() with wrong type argument; fix #3128 2016-03-07 10:59:34 +09:00
Yukihiro "Matz" Matsumoto 0c28c7d754 change backtrace sep from const char* to char 2016-03-07 10:59:34 +09:00
Yukihiro "Matz" Matsumoto 4e95779851 Merge pull request #3125 from zzak/default-benchmark-build-config
Add default benchmark build config
2016-03-07 10:27:36 +09:00
Yukihiro "Matz" Matsumoto b4d946f6bc Merge pull request #3129 from kou/fix-segv-by-backtrace-and-gc
Fix SEGV by backtrace and GC
2016-03-06 12:15:55 +09:00
Yukihiro "Matz" Matsumoto 1a4540fb4a Merge pull request #3127 from kou/suppress-warning
Suppress a warning
2016-03-06 12:13:05 +09:00
Kouhei Sutou f1eb3aea11 Fix segmentation fault by backtrace and GC
GitHub: fix #3122

It reverts #3126. #3126 fixes the segmentation fault but generates
broken backtrace.

This change fixes the segmentation fault and generates correct
backtrace. The strategy of this change is "generating backtrace while
irep is alive".

/tmp/test.rb:
    def gen
      e0 = nil
      begin
        1.times {
          raise 'foobar'
        }
      rescue => e
        e0 = e
      end
      e0
    end

    e = gen
    GC.start
    gen
    GC.start

    puts e.backtrace.join("\n")

Run:

    % bin/mruby /tmp/test.rb
    /tmp/test.rb:5:in Object.gen
    /home/kou/work/ruby/mruby.kou/mrblib/numeric.rb:77:in Integral#times
    /tmp/test.rb:4:in Object.gen
    /tmp/test.rb:13

FYI:

    % ruby -v /tmp/test.rb
    ruby 2.3.0p0 (2015-12-25) [x86_64-linux-gnu]
    /tmp/test.rb:5:in `block in gen'
    /tmp/test.rb:4:in `times'
    /tmp/test.rb:4:in `gen'
    /tmp/test.rb:13:in `<main>'
2016-03-06 11:58:54 +09:00
Kouhei Sutou d77c72dac5 Revert "Merge pull request #3126 from jbreeden/backtrace_irep_null_check"
This reverts commit bf7719fe8d, reversing
changes made to 4f4fa0ade0.

We should get backtrace while irep is alive.
2016-03-06 11:51:04 +09:00
Kouhei Sutou e5cce388ff Suppress a warning
mrbgems/mruby-eval/src/eval.c: In function ‘create_proc_from_string’:
    mrbgems/mruby-eval/src/eval.c:152:10: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
         file = "(eval)";
              ^
2016-03-06 10:05:14 +09:00
Yukihiro "Matz" Matsumoto bf7719fe8d Merge pull request #3126 from jbreeden/backtrace_irep_null_check
Null check for irep & initialize loc.lineno
2016-03-06 08:44:15 +09:00
jbreeden d2a8f7e0cc Fix Travis CI 2016-03-05 14:22:31 -08:00
jbreeden e02ff850fe Null check for irep & initialize loc.lineno 2016-03-05 13:45:56 -08:00
Zachary Scott aa90ad57fe Add default benchmark build config 2016-03-04 16:14:13 +09:00
Yukihiro "Matz" Matsumoto 4f4fa0ade0 Merge pull request #3121 from asfluido/master
The original code crashed when mrb->backtrace.n grew to 16.
2016-02-29 10:22:00 +09:00
Carlo Prelz d6cbe1bfc6 The original code crashed when mrb->backtrace.n grew to 16.
It looks like the logic to reallocate the backtrace was flawed,
based on the wrong variable (loc_raw->i, which, as I have verified,
decreases from 16 to 0 instead of increasing)

I am not sure if this is the correct fix
2016-02-26 09:21:33 +01:00
Yukihiro "Matz" Matsumoto 0c23d5a353 Merge pull request #3120 from rmalizia44/patch-1
Avoid Error when Compiling with -std=c99 flag
2016-02-25 08:55:41 +09:00
Malizia R 52aba8a706 Avoid Error when Compiling with -std=c99 flag 2016-02-24 16:39:38 -03:00
Yukihiro "Matz" Matsumoto b8479b62d8 too many register push for else-less condtions; fix #3117 2016-02-22 09:55:51 +09:00
Yukihiro "Matz" Matsumoto 81acbd2dd1 cosmetic change for OP_EQ 2016-02-22 09:38:20 +09:00
Yukihiro "Matz" Matsumoto cf5ca03676 mruby-struct: copied Struct length is not initialized; fix #3114 2016-02-19 11:46:18 +09:00
Yukihiro "Matz" Matsumoto 819c9da8d2 peephole optimization for LOADNIL before STRCAT; ref #3110 2016-02-17 11:03:27 +09:00
Yukihiro "Matz" Matsumoto d8fc09cf92 push value for NULL AST when value is required; fix #3110 2016-02-17 11:02:29 +09:00
Yukihiro "Matz" Matsumoto ec35e549ad need to free context when reclaiming fiber object in GC; fix #3109 2016-02-17 10:19:14 +09:00
Yukihiro "Matz" Matsumoto da96c335fe syntax error in interpolated symbol; fixed #3108 2016-02-16 11:33:58 +09:00
Yukihiro "Matz" Matsumoto 5596d14c00 Merge pull request #3107 from mame/fix-enum-hash
[255, 255, 255, 255, 255].hash raises "can't convert Float into Integer"
2016-02-16 10:43:12 +09:00
Yukihiro "Matz" Matsumoto 683ff0cbd0 Merge pull request #3106 from mame/fix-eval-no-filename
Fix segfault when `eval("__FILE__")` is executed
2016-02-16 10:42:28 +09:00
Yusuke Endoh a1a157b27e suppress "can't convert Float into Integer" in Enumerable#hash 2016-02-16 00:07:50 +09:00
Yusuke Endoh 668cc1b435 Fix segfault when eval("__FILE__") is executed 2016-02-15 23:57:18 +09:00
Yukihiro "Matz" Matsumoto 74d52a11f2 Merge pull request #3101 from deuwert/fix-test-build
Fix bug in mruby-test gem (fix #3094)
2016-02-12 08:27:55 +09:00
Yukihiro "Matz" Matsumoto 60c1ed4461 Merge pull request #3102 from deuwert/add-limits
Add more limitations
2016-02-12 08:27:04 +09:00
Daniel Bovensiepen 299cb5a7b9 Fix formatting again... 2016-02-12 03:37:36 +08:00
Daniel Bovensiepen 46fbd5349b Add more limitations:
- defined?
  - alias on global variables
  - Operator modification
  - Kernel.binding missing
2016-02-12 03:32:41 +08:00
Daniel Bovensiepen 5976185c0a Fix bug in mruby-test gem.
In an used build path mruby-test wasn't updating mrbtest.c in the
case that the mgem selection was changed. This lead to:
  - a missing reference in case a GEM was removed
  - ignoring all new GEMs added to the build configuration

This fix keeps track of the active gems and demands a rebuild of
mrbtest.c in case that the gem selection changed.
2016-02-12 02:19:18 +08:00
Yukihiro "Matz" Matsumoto 37344ecaad fixed typos in limitations.md 2016-02-12 00:54:07 +09:00
Yukihiro "Matz" Matsumoto 473827d1d1 Merge pull request #3100 from deuwert/toolchain-openwrt
Add toolchain support for OpenWRT
2016-02-12 00:48:13 +09:00
Yukihiro "Matz" Matsumoto f40fc9ab69 Merge pull request #3099 from deuwert/more-limits
Addition to mruby limitation documentation
2016-02-12 00:46:28 +09:00
Daniel Bovensiepen fcbaafaa2c Add toolchain support for OpenWRT 2016-02-11 21:32:42 +08:00
Daniel Bovensiepen e7eb40f9d6 Fix formatting 2016-02-11 21:23:29 +08:00
Daniel Bovensiepen 44d26dd994 Add more limitations 2016-02-11 21:19:48 +08:00
Yukihiro "Matz" Matsumoto 18870428bc add 1/2 description to limitations.md file 2016-02-11 16:50:01 +09:00
Yukihiro "Matz" Matsumoto b3a2d8bec5 Merge pull request #3098 from deuwert/limitations
Limitations
2016-02-11 15:34:04 +09:00
Daniel Bovensiepen 983948c5be Small format fix 2016-02-11 04:48:57 +08:00
Daniel Bovensiepen 3bbc486cf9 Add limitation file 2016-02-11 04:38:29 +08:00
Yukihiro "Matz" Matsumoto 62b06ab4d4 [cppcheck] mrb_str_rindex() remove unnecessary len update by chars2bytes() 2016-02-05 21:54:07 +09:00
Yukihiro "Matz" Matsumoto af4dd3d579 [cppcheck] remove duplicated break 2016-02-05 21:48:44 +09:00
Yukihiro "Matz" Matsumoto 3c73c315f4 Hash: check flags before accessing ifnone; ref #980 2016-02-05 10:08:28 +09:00
Yukihiro "Matz" Matsumoto 25e4ec3f37 cache UTF8 status for utf8_strlen(); ref #980 2016-02-04 23:33:16 +09:00
Yukihiro "Matz" Matsumoto 5e514c910f cache mrb_regexp_p(); ref #980 2016-02-04 23:22:01 +09:00
Yukihiro "Matz" Matsumoto 4344ca0aca Merge pull request #3096 from hlogmans/master
Fix missing dependency on mruby-print to support 'puts'
2016-02-04 10:15:08 +09:00
Hugo Logmans ed5bf72bcf Fix missing dependency on mruby-print to support 'puts' 2016-02-03 15:05:44 +01:00
Yukihiro "Matz" Matsumoto ce84e42f41 Merge pull request #3093 from retrage/retrage/dev
Add String#rjust to mruby-string-ext
2016-01-31 11:41:01 +09:00
Yukihiro "Matz" Matsumoto ac5649700c Merge pull request #3092 from kenhys/fix-suported
Fix a typo
2016-01-31 11:26:20 +09:00
HAYASHI Kentaro 9442cb9652 Fix a typo
su ported ->
supported
  ^
2016-01-31 00:48:12 +09:00
Tomoyuki Sahara 18f7b45ad1 Merge pull request #29 from rmalizia44/patch-1
Add _WIN32_WINNT definition to Avoid Windows Compilation Errors
2016-01-30 22:39:20 +09:00
Akira Moroo cb1a80e741 Add String#rjust test to mruby-string-ext 2016-01-30 14:28:00 +09:00
Akira Moroo e86bc6bb47 Add String#rjust to mruby-string-ext 2016-01-30 14:25:53 +09:00
rmalizia44 be2ec608e2 Add _WIN32_WINNT definition to Avoid Windows Compilation Errors
the line #define _WIN32_WINNT 0x0501 will cause ws2tcpip.h to implement the missing functions freeaddrinfo, getaddrinfo and getnameinfo on windows
2016-01-28 03:28:05 -02:00
Yukihiro "Matz" Matsumoto c35a25c51e Merge pull request #3091 from visualsayed/fix_hash_replace_method
protect NoMethodError from calling to_hash in replace
2016-01-28 12:17:51 +09:00
Sayed Abdelhaleem f5f48d9400 protect NoMethodError from calling to_hash in replace 2016-01-27 21:17:33 +02:00
Yukihiro "Matz" Matsumoto 2723b10a01 Merge pull request #3090 from kou/fix-segv-by-stack-extension-in-mrb-get-args
Fix SEGV by stack extension in mrb_get_args()
2016-01-22 00:50:15 +09:00
Kouhei Sutou c77123d20a Fix SEGV by stack extension in mrb_get_args()
mrb_get_args() keeps pointer of the current stack. But address of the
current stack maybe changed by method call.

'i' format character calls #to_i when the argument isn't integer but
has #to_i.

Here is a code that may call #to_i in mrb_get_args():

    case 'i':
      // ...
            default:
              *p = mrb_fixnum(mrb_Integer(mrb, ARGV[arg_i]));
              break;
     // ...

Here is a code #to_i is called:

    class X
      def initialize(i)
        @i = i
      end

      def to_i
        @i
      end
    end

    [][X.new(0), 0] # X#to_i is called

So, mrb_get_args() shouldn't keep pointer and use it. mrb_get_args()
should always refer mrb->ci->stack to use valid address of the current
stack.
2016-01-22 00:20:00 +09:00
Tomoyuki Sahara 1c4428880b Merge pull request #57 from MaximAbramchuck/patch-1
Add installation instructions
2016-01-21 22:09:17 +09:00
Yukihiro "Matz" Matsumoto 8a74e68552 mruby-random: fixed wrong fixnum conversion 2016-01-21 03:31:08 +09:00
Maxim Abramchuk 7d6f2beaaa Add installation instructions 2016-01-20 13:40:30 +03:00
Yukihiro "Matz" Matsumoto 8d78c49e9a Merge pull request #3088 from maclover7/patch-1
Small grammar fix
2016-01-20 15:14:46 +09:00
Jon Moss 793a62954e Small grammar fix
[ci skip]
2016-01-19 22:37:44 -05:00
Yukihiro "Matz" Matsumoto 17bd40a566 Merge pull request #3087 from kou/fix-segv-on-rerasing-no-memory-error
Fix SEGV on re-raising NoMemoryError
2016-01-19 17:36:51 +09:00
Kouhei Sutou 1d84b3205a Fix SEGV on re-raising NoMemoryError
Think about the following Ruby script:

segv.rb:

    begin
      lambda do
        lambda do
          "x" * 1000 # NoMemoryError
        end.call
      end.call
    rescue
      raise
    end

If memory can't allocate after `"x" * 1000`, mruby crashes.

Because L_RAISE: block in mrb_vm_exec() calls mrb_env_unshare() via
cipop() and mrb_env_unshare() uses allocated memory without NULL check:

L_RAISE: block:

    L_RAISE:
      // ...
      while (ci[0].ridx == ci[-1].ridx) {
        cipop(mrb);
        // ...
      }

cipop():

    static void
    cipop(mrb_state *mrb)
    {
      struct mrb_context *c = mrb->c;

      if (c->ci->env) {
        mrb_env_unshare(mrb, c->ci->env);
      }

      c->ci--;
    }

mrb_env_unshare():

    MRB_API void
    mrb_env_unshare(mrb_state *mrb, struct REnv *e)
    {
      size_t len = (size_t)MRB_ENV_STACK_LEN(e);
      // p is NULL in this case
      mrb_value *p = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*len);

      MRB_ENV_UNSHARE_STACK(e);
      if (len > 0) {
        stack_copy(p, e->stack, len); // p is NULL but used. It causes SEGV.
      }
      e->stack = p;
      mrb_write_barrier(mrb, (struct RBasic *)e);
    }

To solve the SEGV, this change always raises NoMemoryError even when
realloc() is failed after the first NoMemoryError in
mrb_realloc(). mrb_unv_unshare() doesn't need to check NULL with this
change.

But it causes infinite loop in the following while:

    L_RAISE:
      // ...
      while (ci[0].ridx == ci[-1].ridx) {
        cipop(mrb);
        // ...
      }

Because cipop() never pops ci.

This change includes cipop() change. The change pops ci even when
mrb_unv_unshare() is failed by NoMemoryError.

This case can be reproduced by the following program:

    #include <stdlib.h>
    #include <mruby.h>
    #include <mruby/compile.h>

    static void *
    allocf(mrb_state *mrb, void *ptr, size_t size, void *ud)
    {
      static mrb_bool always_fail = FALSE;

      if (size == 1001) {
        always_fail = TRUE;
      }
      if (always_fail) {
        return NULL;
      }

      if (size == 0) {
        free(ptr);
        return NULL;
      } else {
        return realloc(ptr, size);
      }
    }

    int
    main(int argc, char **argv)
    {
      mrb_state *mrb;
      mrbc_context *c;
      FILE *file;

      mrb = mrb_open_allocf(allocf, NULL);
      c = mrbc_context_new(mrb);
      file = fopen(argv[1], "r");
      mrb_load_file_cxt(mrb, file, c);
      fclose(file);
      mrbc_context_free(mrb, c);
      mrb_close(mrb);

      return EXIT_SUCCESS;
    }

Try the following command lines:

    % cc -I include -L build/host/lib -O0 -g3 -o no-memory no-memory.c -lmruby -lm
    % ./no-memory segv.rb
2016-01-19 16:37:42 +09:00
Tomoyuki Sahara c165e50193 Merge pull request #28 from zzak/port-ntop-pton-win32
Port inet_ntop and inet_pton for WIN32
2016-01-18 16:12:35 +09:00
Tomoyuki Sahara a25ec0a749 Merge pull request #27 from zzak/fix-udpsock-warning
Fix warning: variable 'udpsock' set but not used
2016-01-18 16:09:55 +09:00
Zachary Scott bdc118304c Port inet_ntop and inet_pton for WIN32
Without these functions, compilation fails on MinGW
2016-01-18 15:34:26 +09:00
Zachary Scott c8a2c636e0 Fix warning: variable 'udpsock' set but not used 2016-01-18 15:27:32 +09:00
Yukihiro "Matz" Matsumoto 70d24a9e5f Merge pull request #3086 from pra85/2016
Update license year range to 2016
2016-01-18 13:08:17 +09:00
Prayag Verma 70283a94a5 Update license year range to 2016 2016-01-18 08:55:12 +05:30
Yukihiro "Matz" Matsumoto 2e49a13163 Merge pull request #3084 from syohex/all-zeros
Fix passing all zero string to Kernel#Integer
2016-01-14 16:38:58 +09:00
Syohei YOSHIDA 787685a0b9 Fix all zero string case 2016-01-14 11:07:07 +09:00
Syohei YOSHIDA 2a661ac612 Add tests which passes all zero string to Kernel#Integer 2016-01-14 11:05:03 +09:00
Yukihiro "Matz" Matsumoto 4924856949 Merge pull request #3082 from jefffederman/feature/install-mruby-with-ruby-install
Update README to mention ruby version management tools
2016-01-14 00:49:25 +09:00
Jeff Federman d2961203b5 Update README to mention ruby version management tools 2016-01-13 10:30:15 -05:00
Yukihiro "Matz" Matsumoto 2f7efda346 Merge pull request #3081 from val00274/fix_toolchains_params
Fix build error in ruby 1.8.
2016-01-13 17:02:38 +09:00
asatou d0668cf9c9 Fix build error in ruby 1.8.
Apply change of #2978 to :clang, :gcc, :visualcpp toolchains
2016-01-13 16:02:58 +09:00
Yukihiro "Matz" Matsumoto 8143285956 Merge pull request #3080 from kou/fix-class-variable-in-module
Fix class variable reference in module
2016-01-11 10:00:34 +09:00
Kouhei Sutou ad492eb9f3 Fix class variable reference in module
Fix #3079
2016-01-11 00:34:15 +09:00
Yukihiro "Matz" Matsumoto fb2e0b721f fixed a problem with upvar access from instance_eval; ref #3072 2016-01-08 09:07:58 +09:00
Yukihiro "Matz" Matsumoto 0000192710 Merge pull request #3077 from sgnr/output-backtrace-segfault
Fix segfault on mrb_exc_backtrace.
2016-01-08 08:40:30 +09:00
Simon Génier 146a9eeb38 Fix segfault on mrb_exc_backtrace.
The code to iterate over backtrace locations was changed in #3065, but
unfortunately output_backtrace was not correctly updated to forward the
callback.
2016-01-07 11:24:16 -05:00
Yukihiro "Matz" Matsumoto f3cce24035 replace mrb_toplevel_run() by mrb_top_run() 2016-01-07 22:48:22 +09:00
Yukihiro "Matz" Matsumoto 258cb2093c mruby-eval: fixed receiver value in eval context; close #3072 2016-01-07 22:37:58 +09:00
Yukihiro "Matz" Matsumoto f7afe1d82a change mrb_run related API names; compatibility macros provided 2016-01-07 22:36:29 +09:00
Yukihiro "Matz" Matsumoto 725b3ca5a7 move KHASH_DECLARE(ht..) to mruby/hash.h; close #3073 2016-01-07 12:46:38 +09:00
Yukihiro "Matz" Matsumoto 7c82bfa7fe mruby-sprintf to use mrb_int formatting macros; ref #3076 2016-01-07 12:23:17 +09:00
Yukihiro "Matz" Matsumoto 3cf5af681a Merge pull request #3074 from syohex/precision-parameter-type
printf precision parameter must be 'int' type
2016-01-07 11:19:43 +09:00
Syohei YOSHIDA 931cc0359a printf precision parameter must be 'int' type
There is a problem when MRB_INT64 is enabled.
2016-01-07 11:06:20 +09:00
Yukihiro "Matz" Matsumoto ec711914a4 Merge pull request #3071 from ksss/symbol
symname_p support `!~`
2016-01-06 13:45:26 +09:00
Yukihiro "Matz" Matsumoto 20ebe9c5eb Merge pull request #3070 from kazuho/kazuho/printf-specifiers
provide macro to ease using printf mrb_int
2016-01-06 12:17:05 +09:00
Kazuho Oku cd131d18a7 define MRB_PRI? that map to PRI?NN depending on the size of mrb_int 2016-01-06 12:00:56 +09:00
ksss af21b365d2 symname_p support !~ 2016-01-06 11:59:09 +09:00
Yukihiro "Matz" Matsumoto 9145aed85e bytes2chars() conversion to fail if target byte offset is not on the character boundary; ref #3067
that means String#index matches first byte of a multi-byte character. this behavior is different
from CRuby, but a compromise for mruby which does not have encoding stuffs.
2016-01-05 18:05:25 +09:00
Yukihiro "Matz" Matsumoto aec825a64c stack_extend before eval_under() 2016-01-04 10:22:38 +09:00
Yukihiro "Matz" Matsumoto aa1f668b80 instance_eval should pass the receiver as a block parameter; close #3029 2016-01-02 22:01:00 +09:00
Yukihiro "Matz" Matsumoto 879e27d0f1 mirb: enlarge code buffer size to 4KB 2016-01-02 16:58:42 +09:00
Yukihiro "Matz" Matsumoto bd462c5edc mruby-fiber: fiber_switch() to use nesting VM when it's called from C API or mrb_funcall(); close #3056 2016-01-02 13:48:45 +09:00
Yukihiro "Matz" Matsumoto 4683b89b84 Merge pull request #3068 from kazuho/kazuho/osx-_setjmp
use _setjmp/_longjmp on OS X
2016-01-01 10:15:55 +09:00
Kazuho Oku 121c6e30aa use _setjmp/_longjmp on other BSD flavors 2016-01-01 06:48:53 +09:00
Kazuho Oku f4bb329c74 use _setjmp/_longjmp on OS X 2016-01-01 06:24:49 +09:00
Yukihiro "Matz" Matsumoto 38b9c2d308 mruby-fiber: add Fiber.yield description; close #3066
Fiber.yield cannot be called from #initialize which is called by
mrb_funcall().  It is mruby limitation.
2015-12-31 21:25:53 +09:00
Yukihiro "Matz" Matsumoto 31b8469bff Merge pull request #3067 from ksss/use-memchr
Use memchr for performance
2015-12-31 21:20:51 +09:00
ksss 6c1b6ef7a5 Use memchr for performance
```ruby
s = "b"
str = ("a" * 100 + s)

t = Time.now
str.index(s)
puts Time.now - t
```

before => 0.000788
after  => 0.000508

---

```ruby
s = "b"
str = ("a" * 100 * 1024 * 1024 + s)

t = Time.now
str.index(s)
puts Time.now - t
```

before => 0.225474
after  => 0.008658
2015-12-31 17:52:22 +09:00
Yukihiro "Matz" Matsumoto 1d7d7062fc __t_printstr__ may not be available for tests 2015-12-31 00:55:07 +09:00
Yukihiro "Matz" Matsumoto 3531fe179c GC must scan env from fibers even when it's not yet copied to heap; fix #3063 2015-12-31 00:11:37 +09:00
Yukihiro "Matz" Matsumoto 4fdec33ff4 simpler t_print 2015-12-30 14:25:05 +09:00
Yukihiro "Matz" Matsumoto ee3fa1be49 Merge pull request #3065 from kou/support-backtrace-after-method-calls
Support backtrace after method calls
2015-12-29 23:49:33 +09:00
Kouhei Sutou 0ebac02813 Skip backtrace related tests when backtrace isn't available 2015-12-29 23:26:31 +09:00
Kouhei Sutou a561bdb25f Support backtrace after method calls
GitHub: fix #2902, #2917

The current implementation traverses stack to retrieve backtrace. But
stack will be changed when some operations are occurred. It means that
backtrace may be broken after some operations.

This change (1) saves the minimum information to retrieve backtrace when
exception is raised and (2) restores backtrace from the minimum
information when backtrace is needed. It reduces overhead for creating
backtrace Ruby objects.

The space for the minimum information is reused by multiple
exceptions. So memory allocation isn't occurred for each exception.
2015-12-29 20:36:12 +09:00
Yukihiro "Matz" Matsumoto e132de9e8e Merge pull request #3064 from kou/fix-indent
Fix indent
2015-12-29 14:25:10 +09:00
Kouhei Sutou 1eeeecb08a Fix indent 2015-12-29 14:20:10 +09:00
Yukihiro "Matz" Matsumoto d3c6fafaf3 Merge pull request #2331 from take-cheeze/struct_test
Improve `Struct` test.
2015-12-26 15:46:49 +09:00
Yukihiro "Matz" Matsumoto 825ced12de remove duplicated local variable declaration 2015-12-26 11:23:28 +09:00
Yukihiro "Matz" Matsumoto d10e304d79 Merge pull request #3062 from suzukaze/refactor-array-each
Refactor Array#each
2015-12-26 10:49:20 +09:00
Yukihiro "Matz" Matsumoto 6218b2e098 Merge pull request #3061 from mattn/fix-ctrl-c
mirb: Don't exit on Ctrl-C
2015-12-26 10:28:50 +09:00
Jun Hiroe 88076901fd Refactor Array#each 2015-12-26 10:12:01 +09:00
kyab 1e34b12a02 mirb: Don't exit on Ctrl-C 2015-12-26 10:03:28 +09:00
Yukihiro "Matz" Matsumoto 76d44b1b48 remove execute bit from mrbgems/mruby-bin-debugger files 2015-12-26 00:07:16 +09:00
Yukihiro "Matz" Matsumoto 6e09abceaf Merge pull request #3058 from mattn/fix-include-blocker
rename include blocker
2015-12-26 00:04:24 +09:00
Yasuhiro Matsumoto f0205e1182 rename include blocker 2015-12-25 13:43:01 +09:00
Yukihiro "Matz" Matsumoto a060bd5114 Merge pull request #3057 from yuuu/add_next_command
mrdb: Added 'next' command.
2015-12-23 22:35:48 +09:00
Yuhei Okazaki 887a56ba80 fix bug that doesn't stop program when execute next command. 2015-12-23 22:16:36 +09:00
Yuhei Okazaki a08439a7c0 fixed next command's comment. 2015-12-23 22:16:36 +09:00
Yuhei Okazaki e1cc814ec4 add next command to mrdb. 2015-12-23 22:16:36 +09:00
Yukihiro "Matz" Matsumoto 7e4a7abf5f Merge pull request #3055 from mattn/fix-msvc-warnings
fix build on VS2012
2015-12-22 18:02:31 +09:00
Yasuhiro Matsumoto 7cc33af2dc fix build on VS2012 2015-12-22 17:46:20 +09:00
Yukihiro "Matz" Matsumoto d0727be6eb Merge pull request #3054 from kazuho/kazuho/adjust-column-offset-in-peekc_n
fix miscalculation of column number in `peekc_n`
2015-12-21 18:12:06 +09:00
Kazuho Oku adadbf5792 in peekc_n, adjust column number after calling nextc 2015-12-21 15:08:56 +09:00
Yukihiro "Matz" Matsumoto 2ca825a212 Merge pull request #3051 from zzak/ambiguous-first-argument
Fix "ambiguous first argument" warning
2015-12-17 01:23:34 +09:00
Zachary Scott 3f228c1da4 Fix "ambiguous first argument" warning 2015-12-17 00:12:19 +09:00
Yukihiro "Matz" Matsumoto 0720aac250 Merge pull request #3050 from remore/fix-minor-bug-about-objectspace
Add case statement of MRB_TT_SCLASS in mrb_obj_is_kind_of()
2015-12-16 21:04:43 +09:00
Kei Sawada d69b5c3fc7 Add case statement of MRB_TT_SCLASS in mrb_obj_is_kind_of() 2015-12-16 15:54:03 +09:00
Yukihiro "Matz" Matsumoto f54a98ff15 mrb_str_len_to_inum(): fixed a bug with MRB_INT_MIN conversion; fix #3048 2015-12-16 14:49:43 +09:00
Yukihiro "Matz" Matsumoto d18c55fca7 mrb_str_len_to_inum(): fixed a bug with underscores in digits; fix #3049 2015-12-16 14:49:08 +09:00
Yukihiro "Matz" Matsumoto 80c1c60762 Merge pull request #3047 from csouls/rafactor_array_ruby_extension
Remove redundant conditions of Array#each in ruby extension
2015-12-16 01:03:20 +09:00
Yusuke Tanaka d3f59db597 Remove redundant conditions of Array#each in ruby extension 2015-12-15 19:54:29 +09:00
Yukihiro "Matz" Matsumoto 2a234a93d7 mrb_str_len_to_inum(): string may not be NUL terminated; ref #3043 2015-12-14 10:59:56 +09:00
Yukihiro "Matz" Matsumoto 19c744e14d mrb_str_len_to_inum(): fixed a bug with separating _ in the digits; ref #3043 2015-12-14 10:59:56 +09:00
Yukihiro "Matz" Matsumoto 4a6a11486c Merge pull request #3045 from Mav7/master
Added YARD docs in new mruby.h
2015-12-13 15:49:43 +09:00
Ralph Desir af33394281 Undid newline and whitespace on YARD doc 2015-12-12 20:21:53 -05:00
Ralph Desir e27985416f One space indentation. 2015-12-12 18:28:42 -05:00
Yukihiro "Matz" Matsumoto 26a25e1666 mrb_str_len_to_inum: should not raise "string contains null byte" error on "0x"; fix #3043 2015-12-12 16:33:48 +09:00
Yukihiro "Matz" Matsumoto ad333cd191 mrb_str_len_to_inum: converting may not be terminated by NUL; fix #3044 2015-12-12 16:33:48 +09:00
Ralph Desir(Mav7) 4e267d74c6 Added YARD docs in new mruby.h 2015-12-11 01:52:44 -05:00
Tomoyuki Sahara 99e10b8dc4 File::ALT_SEPARATOR is always defined (some string or nil). 2015-12-08 16:44:13 +09:00
Tomoyuki Sahara 4acfd1c7d2 Merge pull request #56 from takahashim/fix-flock
Fix for windows(mingw)
2015-12-08 12:55:38 +09:00
takahashim dd754220ce Fix for windows(mingw)
* File.expand_path: support drive letter and ALT_SEPARATOR

* File.dirname: support ALT_SEPARATOR
* File.basename: ditto.

* IO.popen: raise NotImplementedError
* IO.pipe: ditto.
* `cmd`:  ditto.
* File#flock: ditto.
* FileTest.pipe?: ditto.
* FileTest.symlink?: ditto.
* FileTest.socket?: ditto.
2015-12-08 00:29:42 +09:00
Tomoyuki Sahara 68de1e4fc5 Merge pull request #55 from takahashim/separator
fix file separator
2015-12-07 16:00:46 +09:00
Yukihiro "Matz" Matsumoto b9e5be6a1c Merge pull request #3041 from zzak/travis-osx
Test against latest xcode
2015-12-07 15:27:33 +09:00
Zachary Scott 95edcc8f58 Test against latest xcode
/cc @banzaiman

https://github.com/mruby/mruby/commit/bfcc55fbf98665b33ca7110349aeb66d3ef0df1d#commitcomment-14812510
2015-12-07 15:10:58 +09:00
takahashim 0f5b8b66b0 fix file separator
* File::SEPARATOR should be "/"
* File::ALT_SEPARATOR should be "\\" or nil.
2015-12-04 15:36:41 +09:00
Tomoyuki Sahara 6c67120ed4 Merge pull request #54 from takahashim/win-crlf
fix tests for Win: use binary mode
2015-12-03 12:22:59 +09:00
takahashim b19c315148 fix tests for Win: use binary mode 2015-12-02 21:47:46 +09:00
Tomoyuki Sahara 7337bfa497 Merge pull request #53 from takahashim/build-win32
build on Win32
2015-12-02 10:13:15 +09:00
takahashim 07ceb138fa build on Win32 2015-12-02 00:10:43 +09:00
Yukihiro "Matz" Matsumoto 9a21aa2d3c preserve original string for error message 2015-12-01 21:42:07 +09:00
Yukihiro "Matz" Matsumoto ca417dac26 mrb_str_len_to_inum(): inspect string in error message 2015-12-01 21:41:53 +09:00
Yukihiro "Matz" Matsumoto 36fabe104b new API function mrb_string_value_len() 2015-12-01 16:18:01 +09:00
Yukihiro "Matz" Matsumoto 0701236dac mrb_str_to_inum(): should treat null byte in strings properly; fix #3040 2015-12-01 16:11:47 +09:00
Yukihiro "Matz" Matsumoto d3a56a6949 mrb_cstr_to_inum(): should ignore trailing white spaces even when badcheck set 2015-12-01 11:14:22 +09:00
Yukihiro "Matz" Matsumoto dbb8cf637e mrb_str_to_inum(): should raise error when string contains null byte 2015-12-01 11:13:32 +09:00
Yukihiro "Matz" Matsumoto 9f2fca6ebe mrb_str_to_inum(): no need to call mrb_string_value_cstr() here; ref 05411ee 2015-12-01 10:54:00 +09:00
Yukihiro "Matz" Matsumoto 05411ee15e mrb_string_value_cstr() should not raise error for frozen strings
cf. http://qiita.com/tsahara@github/items/b2a442af95ac893e10a1 (Japanese).
2015-12-01 10:45:43 +09:00
Yukihiro "Matz" Matsumoto 85bd99757c avoid comparison between signed and unsigned 2015-12-01 10:18:01 +09:00
Yukihiro "Matz" Matsumoto 1636ad41a6 C++ compiler does not like cast from pointer to enum; ref #3039 2015-12-01 10:17:35 +09:00
Yukihiro "Matz" Matsumoto c2996514d3 should ignore block to next, break, etc. fix #3039 2015-12-01 09:38:42 +09:00
Yukihiro "Matz" Matsumoto 81a7b4039b Merge pull request #3038 from zzak/gc-arena-docs
GC Arena docs pass for fixups
2015-11-30 10:34:11 +09:00
Zachary Scott dce300517f GC Arena docs pass for fixups 2015-11-30 10:09:43 +09:00
Yukihiro "Matz" Matsumoto 065966dae4 common.h are supposed to be included from other header, so call it with quotes; ref #3032 2015-11-28 00:10:38 +09:00
Yukihiro "Matz" Matsumoto 6f831ef21c Merge pull request #3037 from pbosetti/mruby-time
Implemented round(double) function when _MSC_VER < 1800
2015-11-27 23:31:56 +09:00
Paolo Bosetti 67e3cdfa76 Implemented round(double) function within mruby-time gem, for it is missing on
VisualStudio compilers where _MSC_ver < 1800
2015-11-27 10:54:03 +01:00
Yukihiro "Matz" Matsumoto 9a41db6f3a Merge pull request #2950 from mattn/mirb-file-args
mirb should take filename and arguments.
2015-11-27 17:49:35 +09:00
Yukihiro "Matz" Matsumoto 5c405dea3d include changed from by quotes ("") to by brackets (<>); close #3032 2015-11-27 17:48:23 +09:00
Yukihiro "Matz" Matsumoto 2e0519de89 Merge pull request #3036 from zzak/remove-mrbtest_irep
Remove mrbtest irep
2015-11-26 01:03:55 +09:00
Yukihiro "Matz" Matsumoto 6dbc314ad2 Merge pull request #3035 from iij/pr-yard-mrb_str_to_cstr
YARD doc for mrb_str_to_cstr.
2015-11-26 01:03:08 +09:00
Yukihiro "Matz" Matsumoto 2fb12bd90e Merge pull request #3034 from takahashim/try_convert
add {Array|Hash|String}.try_convert
2015-11-26 01:02:38 +09:00
Tomoyuki Sahara 07f1ebd26d symlink(2) returns -1 when it fails. 2015-11-24 17:09:00 +09:00
Tomoyuki Sahara 11ffb93852 assert_nothing_raised is not available on mruby 1.0.0. 2015-11-24 17:00:12 +09:00
Tomoyuki Sahara ca495944b6 Merge pull request #51 from ksss/io-pipe
Implement IO.pipe
2015-11-24 16:49:34 +09:00
Zachary Scott 1ef2faf1a6 Remove unnecessary dependencies for assert_rb codegen and test_rbireps 2015-11-24 16:33:40 +09:00
Zachary Scott e7a301828f Remove mrbtest_irep from mrbtest
If we make the core tests a dependency on the mruby-test gem,
we don't need to worry about maintaining the core test irep alone.
2015-11-24 16:32:17 +09:00
Tomoyuki Sahara 90b7ec88dc YARD doc for mrb_str_to_cstr. 2015-11-24 16:03:58 +09:00
ksss a55accd736 Implement IO.pipe 2015-11-24 14:24:24 +09:00
Tomoyuki Sahara c9a4091b83 arguments can be shared strings. 2015-11-24 09:54:03 +09:00
Tomoyuki Sahara 1f4bd9fd9f Merge pull request #50 from takahashim/file-symlink
add File.symlink
2015-11-24 09:47:09 +09:00
takahashim 621487a0cd add {Array|Hash|String}.try_convert 2015-11-24 08:39:39 +09:00
Yukihiro "Matz" Matsumoto 625a3fee77 Merge pull request #3033 from sgnr/compiler-fix-mrb-disable-stdio-typo
Fix MRB_DISABLE_STDIO typo.
2015-11-24 07:44:54 +09:00
Simon Génier 058ffcb29c Fix MRB_DISABLE_STDIO typo. 2015-11-23 11:05:33 -05:00
takahashim 2cc674e58e add File.symlink 2015-11-22 13:13:52 +09:00
Tomoyuki Sahara 14cdff075d Merge pull request #48 from takahashim/file-path
add File.path
2015-11-22 07:12:23 +09:00
takahashim 44473fecdd add File.path 2015-11-21 22:03:40 +09:00
Yukihiro "Matz" Matsumoto 18190fa77e Merge pull request #3030 from takahashim/nonzero
Support Numeric#zero? and Numeric#nonzero?
2015-11-21 00:09:17 +09:00
takahashim 40a9700ef8 support Numeric#zero? and Numeric#nonzero? 2015-11-20 23:39:45 +09:00
Yukihiro "Matz" Matsumoto 0e721efe9c Merge pull request #3028 from sgnr/fix-mrb-disable-stdio-typo
Fix typo on MRB_DISABLE_STDIO.
2015-11-20 10:58:33 +09:00
Simon Génier 40f237e938 Fix typo on MRB_DISABLE_STDIO. 2015-11-19 17:03:34 -05:00
Yukihiro "Matz" Matsumoto 2aca5ab479 Merge pull request #3027 from pbosetti/master
Fix check for VisualStudio Version in mruby-math gem
2015-11-19 22:51:03 +09:00
Yukihiro "Matz" Matsumoto abc724840e formatting buffer should be bigger for negative dots; ref #3025 2015-11-19 22:49:50 +09:00
Yukihiro "Matz" Matsumoto f974880563 binary format no longer need to preserve org_v 2015-11-19 22:49:50 +09:00
Yukihiro "Matz" Matsumoto 996417cabf integer range check was moved to mrb_flo_to_fixnum(); ref #3025 2015-11-19 22:49:50 +09:00
Yukihiro "Matz" Matsumoto 09abdcb5e8 negative binary format should not be masked by 10bits; ref #3025 2015-11-19 22:49:50 +09:00
Yukihiro "Matz" Matsumoto 1a9b607a4d binary sprintf should not be restricted by mrb_int size; fix #3025 2015-11-19 22:49:50 +09:00
Yukihiro "Matz" Matsumoto 8229f34098 Merge pull request #3026 from murasesyuka/bugfix/check_minus_signedint_bitshift_overflow
Bugfix nagative-number lshift() bit overflow
2015-11-19 22:49:27 +09:00
Paolo Bosetti 470fce5c90 Fix check for VisualStudio Version in mruby-math gem 2015-11-19 12:01:23 +01:00
murase_syuka ef95dcd390 Bugfix nagative-number lshift() bit overflow 2015-11-18 21:37:17 +09:00
Yukihiro "Matz" Matsumoto 557ab3472a Merge pull request #3024 from yoshiori/fix_readme_link
Update README.md
2015-11-18 01:27:55 +09:00
Yoshiori SHOJI 6c181fa123 Update README.md
Fix mrbgems doc link.
2015-11-17 10:20:39 -06:00
murase_syuka a4d5588101 Bugfix lshift() bit overflow; close #3023 2015-11-18 01:00:46 +09:00
Tomoyuki Sahara 828551f86c off_t can be larger than mrb_int. 2015-10-20 16:03:02 +09:00
Tomoyuki Sahara db7d829679 raise a SystemCallError when lseek(2) fails. 2015-10-20 15:40:25 +09:00
Tomoyuki Sahara 21963f8fa1 UT for IO#sysseek. 2015-10-20 15:37:05 +09:00
Tomoyuki Sahara cac0035348 fix typo. 2015-10-20 15:16:46 +09:00
Tomoyuki Sahara 78fe65aec4 Merge branch 'master' of github.com:iij/mruby-io 2015-10-20 15:13:28 +09:00
Tomoyuki Sahara 71197d2737 Merge pull request #47 from matsumoto-r/patch-1
Fix buffer overflow of `pos` when file-size is too big
2015-10-19 19:33:09 +09:00
MATSUMOTO, Ryosuke 238704592a Fix buffer overflow of pos when file-size is too big 2015-10-19 19:24:39 +09:00
Tomoyuki Sahara e724c5af98 Merge pull request #45 from takahashim/enable-test
enable test
2015-09-28 12:25:33 +09:00
Tomoyuki Sahara 1f217ea82e Merge pull request #46 from takahashim/add-rewind
support IO#rewind
2015-09-28 12:24:51 +09:00
takahashim 9bbfc38bb4 add IO#rewind 2015-09-27 21:25:06 +09:00
Tomoyuki Sahara 1d6b7f9bba Merge pull request #44 from takahashim/io-addstr
support IO#<<
2015-09-27 21:15:54 +09:00
takahashim f5560e8f17 enable test 2015-09-27 01:39:11 +09:00
takahashim c26f998ed5 support IO#<< 2015-09-27 00:29:17 +09:00
Yasuhiro Matsumoto e20c2d78d1 mirb should take filename and arguments. 2015-09-12 13:23:22 +09:00
Tomoyuki Sahara 625995424c To run test, we need "conf.enable_test" in build_config.rb. 2015-09-08 13:25:05 +09:00
Tomoyuki Sahara f3016752bd build in container-based environment. 2015-09-08 13:23:46 +09:00
Tomoyuki Sahara ecd7ef5924 Revert "try to fix failure on travis."
This reverts commit 02daa2509d.
2015-09-08 11:57:08 +09:00
Tomoyuki Sahara 02daa2509d try to fix failure on travis. 2015-09-08 10:44:08 +09:00
Tomoyuki Sahara 5fa3c39145 variables are not used on the platforms lack FD_CLOEXEC. 2015-08-27 09:56:17 +09:00
Tomoyuki Sahara 6c4d39412f Merge pull request #30 from ksss/cloexec
Opened fd should be set FD_CLOEXEC by default
2015-08-26 17:37:21 +09:00
Tomoyuki Sahara 042e4a4313 Merge pull request #43 from jkutner/master
Made FILE_SEPERATOR platform dependent
2015-08-21 09:20:32 +09:00
Joe Kutner 2467332c93 Made FILE_SEPERATOR platform dependent 2015-08-20 07:22:48 -05:00
Tomoyuki Sahara efaf74672e Merge pull request #42 from hone/path_separator
define PATH_SEPARATOR
2015-08-12 09:06:34 +09:00
Tomoyuki Sahara 5323498033 Merge pull request #23 from expeditiousRubyist/master
Changed Windows IO overrides to use sysread and syswrite instead
2015-08-10 10:36:14 +09:00
Tomoyuki Sahara e8efd10bd9 make pack_l simpler. 2015-08-07 11:51:01 +09:00
Tomoyuki Sahara 4603047eb1 update installation procedure. 2015-08-07 11:49:56 +09:00
Tomoyuki Sahara 359d2ae6fd support "q" and "Q". closes #7. 2015-08-07 11:48:45 +09:00
Tomoyuki Sahara d34db58797 implicit type conversion caused unexpected result. fixes #8. 2015-08-06 15:38:35 +09:00
unknown c43a08314e Changed IO overrides to use sysread and syswrite instead of read and write 2015-08-03 04:12:10 -07:00
Terence Lee ec4982b2d3 define PATH_SEPARATOR 2015-08-02 17:35:07 +02:00
Tomoyuki Sahara 8527c78fb5 Merge pull request #22 from Asmod4n/master
added SO_NOSIGPIPE
2015-07-28 09:00:31 +09:00
Asmod4n 2929c629d4 added SO_NOSIGPIPE 2015-07-27 18:42:22 +02:00
Tomoyuki Sahara de60400c64 Merge pull request #21 from expeditiousRubyist/master
Added functioning read for Win32
2015-07-25 20:09:20 +09:00
Rubyist f80a4fd0e8 Added functioning read for Win32 2015-07-25 00:24:31 -07:00
Tomoyuki Sahara 2d1134e9ea Merge pull request #41 from hone/cross_compile_windows
support for crossbuild for windows (32 bit and 64 bit) using mingw
2015-07-24 09:19:56 +09:00
Terence Lee fe7784efb0 support for crossbuild for windows (32 bit and 64 bit) using mingw 2015-07-23 12:39:05 -05:00
Tomoyuki Sahara bfb9cf7922 Merge pull request #20 from expeditiousRubyist/master
Win32 Port
2015-07-22 09:35:39 +09:00
Rubyist 4ab922044d Removed unnecessary/incorrect use of sizeof(int) and corrected more
improper usages of mrb_sys_fail
2015-07-21 15:56:27 -07:00
Rubyist 7ee9ab89f9 Changed some uses of mrb_sys_fail to instead use mrb_raise where
appropriate
2015-07-21 03:37:28 -07:00
Rubyist a426f0e2b5 Overrided close and write to work on Win32 platforms 2015-07-18 23:22:57 -07:00
Rubyist 752f7c1526 Minimal semi-working compile on Windows platforms. 2015-07-17 23:45:02 -07:00
Rubyist 7d8cbf1a9c Added Winsock 2 to list of libraries to use when building for Windows
targets
2015-07-17 23:03:34 -07:00
Tomoyuki Sahara 1b5c68567e Merge pull request #40 from archSeer/patch-1
Remove mrb_io_s_select typo.
2015-07-03 09:36:49 +09:00
Blaž Hrastnik 8da787be72 Remove mrb_io_s_select typo.
Uncovered with a Coverity scan of our project using mruby-io. https://scan8.coverity.com/reports.htm#v26153/p11375/fileInstanceId=6844382&defectInstanceId=2515905&mergedDefectId=121921
2015-07-02 21:02:56 +02:00
Tomoyuki Sahara b913e7eefd test suite for pack/unpack. 2015-05-22 11:38:56 +09:00
Tomoyuki Sahara 2ba4933158 refactor "AaZ". fixes #6. 2015-05-22 11:38:39 +09:00
Tomoyuki Sahara 15de80a7cd style. 2015-05-22 09:41:39 +09:00
Tomoyuki Sahara dacb8b626b failed to remove temporary files! 2015-05-20 11:38:03 +09:00
Tomoyuki Sahara ae4fc77675 Merge pull request #39 from jbreeden/master
Correct File::NULL for Windows
2015-04-18 06:50:32 +09:00
Jared Breeden 6d6be18d4e Removing redundant platform check 2015-04-17 15:45:14 -04:00
Jared Breeden 7f8324a2ed Merge branch 'master' of https://github.com/iij/mruby-io 2015-04-17 15:40:35 -04:00
Jared Breeden 36343cf098 Correct File::NULL for Windows 2015-04-17 15:39:11 -04:00
Jared Breeden c0738a74c6 Excluding wait call for windows 2015-04-05 17:21:02 -04:00
Tomoyuki Sahara cfbc8a8995 Merge pull request #38 from jbreeden/master
Excluding wait call for windows
2015-04-05 09:23:29 +09:00
Tomoyuki Sahara e92fd76248 wait for child processes when we close pipes. fixes #37. 2015-04-03 10:05:09 +09:00
Tomoyuki Sahara 1629e86063 add IPv6 constants defined in RFC3493. 2015-02-13 11:35:36 +09:00
Tomoyuki Sahara e4006cb53a Socket::Option requires iij/mruby-pack. 2014-12-26 16:12:41 +09:00
Tomoyuki Sahara 0d05a22602 don't call undefined method. fixes #15. 2014-12-26 16:00:50 +09:00
Tomoyuki Sahara 7b17158f88 remove unused variables. 2014-12-26 13:36:11 +09:00
Tomoyuki Sahara a09858af61 syscalls may return sockaddr shorter than sizeof(struct sockaddr) on Linux. 2014-12-26 13:27:39 +09:00
Tomoyuki Sahara a960a6f931 failed to add... 2014-12-26 11:19:53 +09:00
Tomoyuki Sahara 3a22166c67 debug UNIXSocket and UNIXServer. 2014-12-26 11:16:03 +09:00
Tomoyuki Sahara 3a97a453c4 rewrite IO.for_fd.
IO.for_fd should call IO#initialize to initialize the created object
properly.  It cannot be implemented in Ruby.
2014-12-26 11:09:07 +09:00
Tomoyuki Sahara c455544ee2 better error message. 2014-12-26 11:08:18 +09:00
Tomoyuki Sahara 1d1f273ca9 Merge pull request #35 from tmtm/fix-read-create-many-objects
FIX: IO#read create a large number of objects.
2014-12-18 11:33:06 +09:00
TOMITA Masahiro 42752bffce FIX: IO#read create a large number of objects. 2014-12-18 00:41:59 +09:00
Tomoyuki Sahara e7dbe6e87a Merge pull request #33 from iij/revert-32-fix-read-create-many-objects
Revert "FIX: IO#read create a large number of objects."
2014-12-17 13:39:59 +09:00
Tomoyuki Sahara e82c1d3f38 Revert "FIX: IO#read create a large number of objects." 2014-12-17 13:37:15 +09:00
Tomoyuki Sahara 50721e9bf8 Merge pull request #32 from tmtm/fix-read-create-many-objects
FIX: IO#read create a large number of objects.
2014-12-17 13:35:34 +09:00
TOMITA Masahiro 9b13a59a55 FIX: IO#read create a large number of objects. 2014-12-17 01:46:23 +09:00
Tomoyuki Sahara ee347f3417 Merge pull request #31 from tmtm/fix-sysread-segv
FIX: IO#sysread occurs SEGV
2014-12-16 09:07:45 +09:00
TOMITA Masahiro be9e203563 FIX: IO#sysread occurs SEGV 2014-12-15 20:24:01 +09:00
Tomoyuki Sahara 723db886e1 add Socket::Option#inspect
without this, mirb dies.
https://github.com/mruby/mruby/pull/2666
2014-12-12 12:38:43 +09:00
Tomoyuki Sahara 121475638d add "I" and "i". 2014-12-12 12:12:41 +09:00
Tomoyuki Sahara 2103bc99ba style 2014-12-12 12:12:19 +09:00
Tomoyuki Sahara 669fe705cc "i" and "I". 2014-12-12 12:01:58 +09:00
ksss e61c469724 IO.popen fd set close_on_exec flag by default 2014-12-04 10:25:03 +09:00
ksss 9439b981d8 Opened fd should be set FD_CLOEXEC by default 2014-12-04 10:25:03 +09:00
Tomoyuki Sahara d1fee5892a IO.sysopen does retry. closes #26. 2014-11-25 16:26:34 +09:00
Tomoyuki Sahara e7cd024498 Merge pull request #29 from sdottaka/fix-for-msvc
Fix broken build for Visual C++
2014-11-25 10:29:07 +09:00
sdottaka 24007b80b4 Fix broken build for Visual C++ 2014-11-22 17:48:59 +09:00
Tomoyuki Sahara a2f45bf8d1 Merge pull request #28 from ksss/file-size
Implement FileTest.size
2014-11-18 10:35:12 +09:00
ksss a44ada616e Implement FileTest.size
- File.size delegate to FileTest.size
- File.size more faster by reading i-node value
2014-11-16 14:55:45 +09:00
Tomoyuki Sahara 379c5a6d88 Merge pull request #25 from matz/gc_on_enfile
garbage collect when open(2) fails with ENFILE or EMFILE
2014-11-13 09:27:11 +09:00
Yukihiro "Matz" Matsumoto b50093ad28 garbage collect when open(2) fails with ENFILE or EMFILE 2014-11-13 01:50:46 +09:00
Tomoyuki Sahara 190264b3c8 Merge pull request #23 from jbreeden/master
Correcting E_NOTIMP_ERROR reference
2014-08-08 21:34:15 +09:00
Akito Mochizuki 0761b17245 update implemented methods table 2014-08-05 11:51:05 +09:00
jbreeden 9a2cbc4122 Correcting E_NOTIMP_ERROR reference 2014-08-03 16:45:46 -04:00
Tomoyuki Sahara e60951a305 add IO#sync and IO#sync= 2014-07-29 10:55:02 +09:00
Tomoyuki Sahara 1768ee02e5 remove extra ';'. 2014-07-22 23:55:25 +09:00
Tomoyuki Sahara 8c34a8d561 Merge pull request #22 from take-cheeze/fix_arg
Fix type of argument passed to mrb_get_args.
2014-07-22 15:30:57 +09:00
take_cheeze 689541d0fb Fix type of argument passed to mrb_get_args. 2014-07-19 21:37:13 +09:00
Tomoyuki Sahara 093f4e2cff mrb_voidp (and other macros) has gone. 2014-07-09 12:24:50 +09:00
Tomoyuki Sahara fa39825b1b refactor. 2014-07-09 10:01:33 +09:00
Tomoyuki Sahara 66a92240de Merge pull request #21 from dreamedge/add_close_on_exec
Add close on exec
2014-07-09 09:34:12 +09:00
dreamedge 78f5f98710 delete debug messages 2014-07-09 05:29:20 +09:00
dreamedge 7e689e8680 Add IO#close_on_exec=
and a test on test/io.rb
2014-07-08 15:56:56 +09:00
dreamedge 59b7c4eaf0 add IO.close_on_exec? 2014-07-07 12:47:53 +09:00
Tomoyuki Sahara 91c285fcfe regen. 2014-07-02 09:12:27 +09:00
Tomoyuki Sahara 04097348e8 more TCP options (for NetBSD). 2014-07-02 09:12:04 +09:00
Tomoyuki Sahara baa40ef2b1 sort. 2014-07-02 09:09:58 +09:00
Tomoyuki Sahara 9c3c267bef Merge pull request #14 from dreamedge/add_tcp_constants
Add TCP_* constants included in "netinet/tcp.h".
2014-07-02 09:08:47 +09:00
dreamedge f3c71cf5da Add TCP_* constants included in "netinet/tcp.h".
ex: TCP_NODELAY, TCP_CORK, ...
2014-07-02 00:30:10 +09:00
take_cheeze e6a263a162 Raise NameError as defined in specification when Struct member isn't found. 2014-06-19 22:06:07 +09:00
take_cheeze a2f5840b60 Add tests to Struct#[] and Struct#[]=. 2014-06-19 22:06:07 +09:00
take_cheeze 3d94022b54 Replace return value result passing with assert_* in Struct test. 2014-06-19 22:06:07 +09:00
Tomoyuki Sahara ddfc4eb5ef IO#read(0) should return "" immediately. fixes iij/mruby-socket#13. 2014-06-19 09:57:08 +09:00
Tomoyuki Sahara 376af5bac3 re-implement TCPServer.accept. fixes #12. 2014-06-17 15:41:42 +09:00
Tomoyuki Sahara 5b65ca3ebb Merge pull request #5 from take-cheeze/float
Add full support of float templates.
2014-06-15 19:54:08 +09:00
take_cheeze 7b2611ea28 Update supported template list. 2014-06-14 13:25:00 +09:00
take_cheeze 8f4b7ac15c Support float/double unpacking. 2014-06-14 13:25:00 +09:00
take_cheeze 514450e891 Use PACK_FLAG_LITTLEENDIAN. 2014-06-14 13:25:00 +09:00
take_cheeze 7dc2b4f59f Implement g/f/F/G/d/D packing. 2014-06-14 13:24:59 +09:00
take_cheeze f4f968241b Add support of little endian float. 2014-06-14 13:24:49 +09:00
Tomoyuki Sahara a0c4ca2406 Merge pull request #4 from take-cheeze/raise_fix
Fix invalid raise format found with mruby-clang-plugin.
2014-06-14 07:51:42 +09:00
take_cheeze 1997420a7f Fix raise format found with mruby-clang-plugin. 2014-06-13 17:42:43 +09:00
Tomoyuki Sahara d894de86f4 fd2 is valid if fd2 >= 0. fixes #18. 2014-06-10 10:22:50 +09:00
Tomoyuki Sahara cb84ce30e7 no longer used. 2014-06-10 09:54:23 +09:00
Tomoyuki Sahara 9ee9c271d1 Merge pull request #20 from windwiny/patch-1
compatible 32 bit windows
2014-05-09 02:33:00 +09:00
windwiny dc61ef1c65 compatible 32 bit windows 2014-05-07 20:33:12 +08:00
Tomoyuki Sahara 077f39bd38 Merge pull request #19 from schmurfy/solaris_flock
raise an error for flock on solaris
2014-04-29 00:45:08 +09:00
Julien Ammous 9a1b25bdd8 raise an error for flock on solaris 2014-04-28 15:40:04 +02:00
Tomoyuki Sahara 5aeb99ad49 fix mrb_raisef usage. 2014-04-21 11:14:40 +09:00
Tomoyuki Sahara 9c00de59ce IO.for_fd can be written in Ruby. 2014-04-21 10:24:59 +09:00
Tomoyuki Sahara c46cb1b5eb more tests. 2014-04-21 10:02:25 +09:00
Tomoyuki Sahara e5f30f83ce IO#flush should raise an exception if it is closed. 2014-04-21 10:01:49 +09:00
Tomoyuki Sahara 99c67749ff remove return statements after mrb_raise(). 2014-04-21 09:06:46 +09:00
Tomoyuki Sahara 7d7a549a4f remove io_open(). 2014-04-18 11:32:38 +09:00
Tomoyuki Sahara 36045ea96f IO#syswrite should raise an error if it's not opened for writing. 2014-04-18 11:20:55 +09:00
Tomoyuki Sahara 1c4f46f324 remove standard header files from io.h. 2014-04-17 16:29:27 +09:00
Tomoyuki Sahara a11780f4f1 file.c depends on mruby/ext/io.h now. 2014-04-17 16:18:26 +09:00
Tomoyuki Sahara a3e1e535dc function declarations should be in a header file. 2014-04-17 16:13:18 +09:00
Tomoyuki Sahara 9f5ff9ddec remove unused constants. 2014-04-17 16:12:51 +09:00
Tomoyuki Sahara ba9cb1f757 "struct mrb_io_type" is not used at all. 2014-04-17 16:07:12 +09:00
Tomoyuki Sahara 10be4cbb2c file.c does not depend on mruby/ext/io.h. 2014-04-17 15:56:11 +09:00
Tomoyuki Sahara 87ce12dfe3 io.write("") -> 0 2014-04-17 15:53:51 +09:00
Tomoyuki Sahara 810e37b1c3 return value of syswrite may be less than length of given string. 2014-04-17 15:45:31 +09:00
Tomoyuki Sahara d5cf1de1ae Merge pull request #16 from schmurfy/solaris
solaris does not have flock
2014-04-11 06:53:34 +09:00
Tomoyuki Sahara 1d987d2fcd Merge pull request #9 from schmurfy/solaris
OpenSolaris/Illumos defines a "sun" constant...
2014-04-11 05:50:18 +09:00
Julien Ammous 9850e6a9d0 OpenSolaris/Illumos defines a "sun" constant... 2014-04-10 19:32:05 +02:00
Julien Ammous cd168c6f32 solaris does not have flock 2014-04-10 19:26:55 +02:00
Tomoyuki Sahara 28e00d82fb suppress compiler warnings. 2014-04-07 13:15:54 +09:00
Tomoyuki Sahara a6ab2c54f3 Merge pull request #15 from monami-ya-mrb/pr-add-error-check-in-test
Don't ignore the return value of symlink().
2014-04-05 11:55:51 +09:00
Masaki Muranaka 706ef1337a Don't ignore the return value of symlink(). 2014-04-05 10:44:47 +09:00
Akira Yumiyama 572b404935 Update .travis.yml 2014-04-04 11:32:42 +09:00
Akira Yumiyama 2bf49c9232 Update .travis.yml 2014-04-04 11:31:45 +09:00
Akira Yumiyama 083cd9ca8c Update .travis.yml 2014-04-04 11:31:33 +09:00
Akira Yumiyama 355723ebca Create .travis.yml 2014-04-04 11:27:56 +09:00
Akira Yumiyama 80e01e3659 Create .travis.yml 2014-04-04 11:27:14 +09:00
Akira Yumiyama 1094bbfff8 Create .travis.yml 2014-04-04 11:25:04 +09:00
Akira Yumiyama eda9d1a8fc nonexistent test fixes (for travis-ci) 2014-03-26 22:09:10 +09:00
Tomoyuki Sahara ab9dcc766e IO.close should be IO._sysclose. closes #13. 2014-03-26 17:22:57 +09:00
Tomoyuki Sahara 719452b8d2 remove unsed. 2014-03-14 10:47:54 +09:00
Tomoyuki Sahara 14031bdf44 Merge pull request #11 from pbosetti/master
Can build on VisualStudio, revised.
2014-03-14 10:41:56 +09:00
Tomoyuki Sahara 279587c138 split. 2014-03-12 09:44:34 +09:00
Tomoyuki Sahara a8558512ec mruby-mtest is not required to build (but to test). 2014-03-12 09:41:23 +09:00
Tomoyuki Sahara e345d4c68f Merge pull request #7 from monami-ya-mrb/pr-fix-connect-failed
Call Socket._connect() in Socket.connect() .
2014-03-11 23:25:29 +09:00
Masaki Muranaka 11b47459e7 Call Socket._connect() in Socket.connect() . 2014-03-11 21:18:05 +09:00
Paolo Bosetti 39bd240116 Fixed bug in File.expand_path() on Windows (forever recursive loop) 2014-03-07 16:47:18 +01:00
Paolo Bosetti 7ff049457f Added File.foreach method.
Improved error management in File.new (Errno can be undefined)
2014-03-04 10:43:46 +01:00
Paolo Bosetti d9f3fd868a Merge branch 'master' of https://github.com/iij/mruby-io into test
Conflicts:
	src/io.c
2014-03-03 13:15:57 +01:00
Tomoyuki Sahara f7c054bd39 quiet compiler. 2014-02-25 12:28:34 +09:00
Tomoyuki Sahara e8706d4ee7 remove unused. 2014-02-25 12:23:15 +09:00
Tomoyuki Sahara b9dff44582 Merge branch 'master' of github.com:iij/mruby-io 2014-02-25 12:20:52 +09:00
Tomoyuki Sahara 56a8c592dd add IO.read 2014-02-25 12:19:52 +09:00
Tomoyuki Sahara a90d8b8a73 add Socket.getaddrinfo. 2014-02-24 11:21:49 +09:00
Akira Yumiyama d28f042118 compatibility support (mruby/mruby, iij/mruby and 1.0.0)
- refs https://github.com/mruby/mruby/commit/36e234aa377d50d8ee425c7868e0651cf78e85cf
2014-02-22 20:45:07 +09:00
Tomoyuki Sahara 7fd585bae1 support older version. 2014-02-14 10:36:37 +09:00
Tomoyuki Sahara daa65c15de add dummy IO#flush for better compatibility with CRuby. 2014-02-12 16:33:34 +09:00
Tomoyuki Sahara 40c52f58d0 Merge pull request #9 from matsumoto-r/support_mrb_get_module
Support mrb_module_get
2014-02-12 10:57:58 +09:00
Paolo Bosetti ee2859de6e Updated mrb_include_module call after mruby 1.0.0 2014-02-11 14:54:30 +01:00
Tomoyuki Sahara b3c6075dc5 IO._bless has gone.
https://github.com/iij/mruby-io/commit/b74458a486042f4863fa6362057e25f0997694f5
2014-02-10 09:51:24 +09:00
Tomoyuki Sahara b74458a486 remove _bless trick. closes #8. 2014-02-10 09:49:37 +09:00
MATSUMOTO Ryosuke 526608c8a2 Support mrb_module_ge 2014-02-08 17:38:41 +09:00
Tomoyuki Sahara f10b73efa7 move license terms to the bottom. 2014-02-03 12:35:02 +09:00
Paolo Bosetti a2af349959 Now the drive letter is returned as leading path element by File#dirname on Windows 2014-01-13 17:29:57 +01:00
Tomoyuki Sahara b744097511 Merge pull request #6 from schmurfy/testless
removed mtest dependency
2014-01-09 16:09:50 -08:00
Paolo Bosetti a613bce3f2 Merge branch 'master' of https://github.com/iij/mruby-io 2014-01-07 13:51:38 +01:00
Tomoyuki Sahara 8cee36b1b5 Catch Errno::ENFILE too.
When system file descriptor table is full, errno is set to
ENFILE instead of EMFILE.  They are similar but different.
2013-12-13 15:49:32 +09:00
Paolo Bosetti 23afaf02dc Made compatible with VisualStudio 2013-12-10 14:34:26 +01:00
Julien Ammous a26ce35c64 removed mtest dependency 2013-12-04 20:51:27 +01:00
Tomoyuki Sahara d12f436bdb mrb_intern API change. 2013-12-03 10:07:29 +09:00
Paolo Bosetti 5a59fd3a5c Fix for compilation under Win/MinGW 2013-12-02 12:14:04 +01:00
Tomoyuki Sahara e641e9a380 suppress a compiler warning. 2013-11-20 12:14:54 +09:00
Tomoyuki Sahara 2245818f91 make it more portable. 2013-11-20 12:13:34 +09:00
Tomoyuki Sahara 78d2d909cf style 2013-11-20 10:26:13 +09:00
Tomoyuki Sahara 87d878292d Try GC when Too many open files (revert a part of 1e8097a). 2013-11-16 16:04:31 +09:00
Tomoyuki Sahara e44da8a6cc test for #6. 2013-11-16 05:44:04 +09:00
Tomoyuki Sahara 1e8097a4b8 IO.sysopen raises an exception when open(2) fails. closes #6. 2013-11-16 05:14:07 +09:00
Tomoyuki Sahara e96cdeb2af Merge pull request #3 from h2so5/patch-1
avoid declaration error on VC++
2013-11-05 18:31:15 -08:00
h2so5 db14b8e7d4 avoid declaration error on VC++ 2013-11-06 11:25:33 +09:00
Tomoyuki Sahara d8e5e7df3f Merge pull request #3 from murasesyuka/feature/add_dependencies_gem
add mruby-socket dependency gems
2013-11-03 00:41:21 -07:00
murase_syuka 78ebe1b427 add mruby-socket dependency gems 2013-11-02 14:30:42 +09:00
Tomoyuki Sahara 823df14ff4 remove unused code and irrelevant comment. 2013-10-15 10:43:48 +09:00
Tomoyuki Sahara ec443d45db more IPPROTO_* related to IPv6. 2013-10-10 10:24:02 +09:00
Tomoyuki Sahara 93edd26b3e fix typo... 2013-10-09 00:35:22 +09:00
Tomoyuki Sahara 005f01f2fc fix RSTRING_PTR usage. 2013-10-03 12:18:39 +09:00
Tomoyuki Sahara bf4c226232 Merge pull request #4 from pbosetti/master
Truncate the file to zero length on opening when "w" mode is set
2013-10-02 17:08:24 -07:00
Paolo Bosetti c608c26ab4 Merge branch 'master' of https://github.com/iij/mruby-io 2013-10-02 13:05:12 +02:00
Paolo Bosetti 49494a7367 Truncate file on File.open(file, "w") 2013-10-02 13:01:56 +02:00
Tomoyuki Sahara 8b48e2b4a4 syswrite must write to fd2 if it is properly set.
closes #3.
2013-09-30 11:56:15 +09:00
Tomoyuki Sahara 97899a6922 style 2013-09-30 11:18:22 +09:00
Tomoyuki Sahara adb3bd6698 don't retry when we cannot fork(2).
EAGAIN indicates the system is under heavy load.
Retrying make things worse.
2013-09-30 10:55:09 +09:00
Tomoyuki Sahara d75d23294d fix descriptor leakage. 2013-09-30 10:36:29 +09:00
Tomoyuki Sahara b4f0a68fba add File#flock. 2013-09-30 10:17:21 +09:00
Tomoyuki Sahara 140da1c6ca remove duplicated white spaces. 2013-09-26 18:31:02 +09:00
Tomoyuki Sahara e27fb544df suppress a warning and fix a possible segv. 2013-09-26 10:59:40 +09:00
Tomoyuki Sahara e2b0606752 Merge pull request #2 from pbosetti/master
Catch up with API changes on mrb_intern() -> mrb_intern_cstr()
2013-09-25 18:21:27 -07:00
Paolo Bosetti c4e3c46e86 Catch up with API changes on mrb_intern() -> mrb_intern_cstr() 2013-09-25 13:26:49 +02:00
Tomoyuki Sahara 47a610e688 use array parameter on IO.open. 2013-08-30 19:09:36 +09:00
Tomoyuki Sahara 713aa48cf9 STDERR's file descriptor is 2.
closes #1
2013-08-30 17:04:40 +09:00
Tomoyuki Sahara 9dc875f246 add cmd (command output expression). 2013-08-23 16:00:08 +09:00
Tomoyuki Sahara 40adffc676 ARGS_XXX -> MRB_ARGS_XXX 2013-08-21 09:29:38 +09:00
Tomoyuki Sahara 0345215465 fix a possible address family mismatch. 2013-08-14 11:51:53 +09:00
Tomoyuki Sahara a9593e1f57 v4/v6 fallback for TCP. 2013-08-14 09:34:22 +09:00
Tomoyuki Sahara 5e8021bedb tests for File.socket? and File.symlink? 2013-08-08 14:00:02 +09:00
Tomoyuki Sahara c49541058c use lstat(2) to check if it's a symlink 2013-08-08 13:58:47 +09:00
Tomoyuki Sahara 76e1017f48 hints.ai_socktype must be set if servname is not NULL on NetBSD3.
Closes #1
2013-07-25 15:04:59 +09:00
Tomoyuki Sahara a341b8e0ff more socket options (for multicast). 2013-07-25 11:58:05 +09:00
Tomoyuki Sahara cf827ab0e7 fix Addrinfo.getaddrinfo("127.0.0.1", nil).
Closes #2
2013-07-25 11:54:53 +09:00
Takashi Sogabe 4f3a749da1 Fix incorrect condition for pendig-IO 2013-06-26 15:24:23 +09:00
Tomoyuki Sahara 216e32751e Socket.gethostname always fails. 2013-06-21 09:14:53 +09:00
Akira Yumiyama 5625e44371 add method: IO#select 2013-06-02 15:25:14 +09:00
Akira Yumiyama 1272df7cb6 fix IO#eof? method (consider the read buffer) 2013-06-02 13:24:34 +09:00
Akito Mochizuki 35defaf1c9 fix mrb_voidp_value function call 2013-05-28 10:15:25 +09:00
Tomoyuki Sahara f4aa3e7ae7 getaddrinfo("localhost") returns "fe80::1%lo0" on MacOS! 2013-05-21 14:48:42 +09:00
Tomoyuki Sahara 1411d5b974 using mruby-mtest on test/socket.rb. 2013-05-21 14:23:35 +09:00
Tomoyuki Sahara 12144b9ad2 getaddrinfo("localhost") may return 2 or more. 2013-05-21 14:23:07 +09:00
Tomoyuki Sahara 0f2d7e8a99 fix reading wrong variable. 2013-05-21 14:15:15 +09:00
Tomoyuki Sahara b8912c3508 Linux does not have getpeereid(2). 2013-05-21 14:13:15 +09:00
Tomoyuki Sahara 4bebd4d70f mrb_sys_fail() is declared in src/error.h 2013-05-21 14:03:10 +09:00
Tomoyuki Sahara cfe18142cb test runner. 2013-05-21 13:53:27 +09:00
Tomoyuki Sahara 89147066f8 mruby-socket depends on mruby-io. 2013-05-21 13:48:33 +09:00
Tomoyuki Sahara bc5feb39a1 short description, example, requirement, todo, license. 2013-05-21 13:40:14 +09:00
Tomoyuki Sahara e459ecc934 Merge branch 'master' of github.com:iij/mruby-socket 2013-05-21 13:19:32 +09:00
Tomoyuki Sahara 49e53bca5d Socket library for mruby. 2013-05-21 13:17:34 +09:00
Tomoyuki Sahara 06f1c82f64 Initial commit 2013-05-20 21:15:50 -07:00
Akira Yumiyama 0a21d9ec92 bufix of mrb_file__gethome() 2013-05-12 14:58:12 +09:00
Akira Yumiyama e277079616 update run_test.rb 2013-05-12 14:50:31 +09:00
Akira Yumiyama 55b6ef43c5 add return value check of fseek 2013-05-12 14:23:48 +09:00
Akira Yumiyama 14e1992ed0 add null check 2013-05-12 14:15:00 +09:00
Akira Yumiyama d39a05e68e remove unused variable. 2013-05-12 14:14:48 +09:00
Akira Yumiyama 49cc9c7cfa Use strncpy instead of strcpy. 2013-05-12 14:01:53 +09:00
Akira Yumiyama c25d386c41 Use mkstemp instead of mktemp. 2013-05-12 13:15:11 +09:00
Akira Yumiyama acc8995060 update run_test.rb 2013-05-12 12:54:35 +09:00
Akira Yumiyama df529a83d6 add $stdin $stdout $stderr STDIN STDOUT STDERR 2013-05-08 20:22:29 +09:00
Akira Yumiyama 7a94d02e8d add IO#print 2013-05-08 20:22:14 +09:00
Tomoyuki Sahara 38f4086a52 Merge pull request #2 from schmurfy/double
added support for E in pack
2013-05-08 01:53:56 -07:00
Julien Ammous dce09fb7fd removed unused variables 2013-05-08 10:26:15 +02:00
Julien Ammous c869bdedc0 added support for E in pack (double) 2013-05-08 10:26:15 +02:00
Tomoyuki Sahara 8c5cb5e782 cannot pack objects other than the first one. closes #1. 2013-05-08 09:40:24 +09:00
Akira Yumiyama f89ee88a6c rename mrb_class_obj_get -> mrb_class_get 2013-05-02 23:52:57 +09:00
Akira Yumiyama 7618ca6bb3 remove unused Makefile 2013-05-02 23:45:47 +09:00
Akira Yumiyama 8bfbca234f update run_test.rb 2013-05-02 23:44:40 +09:00
Akira Yumiyama 62e1823187 update run_test.rb 2013-05-02 23:36:20 +09:00
Akira Yumiyama 814f3305ca put MRB_ prefix before ARGS_XXX macros 2013-04-27 10:09:05 +09:00
Akira Yumiyama d5982b43c5 put MRB_ prefix before ARGS_XXX macros 2013-04-27 09:47:05 +09:00
Akira Yumiyama da557fbc82 add File.expand_path 2013-04-07 01:55:18 +09:00
Akira Yumiyama cc40f93ac8 Kernel#open block support 2013-04-02 15:51:36 +09:00
Akira Yumiyama 911003987b add Kernel#open 2013-04-02 15:32:01 +09:00
Akira Yumiyama 5a425f598b Update README.md 2013-04-01 10:17:18 +09:00
Akira Yumiyama b8a23e6be8 update README.md 2013-04-01 09:21:12 +09:00
Akira Yumiyama e8ca5e5169 initial commit 2013-04-01 09:12:01 +09:00
Tomoyuki Sahara 858d67c154 add "v" and "V". 2013-02-15 10:54:36 +09:00
Tomoyuki Sahara fc43022c95 support "V" and "v". 2013-02-15 10:52:37 +09:00
Tomoyuki Sahara abe9ccfe4b Merge branch 'master' of https://github.com/iij/mruby-pack 2013-02-15 10:46:21 +09:00
Tomoyuki Sahara 88fa5851f4 fix an issue large/negative integer may not be packed/unpacked correctly. 2013-02-15 10:45:30 +09:00
Tomoyuki Sahara a0c62dd4b8 fix an issue negative integer may not be packed/unpacked correctly. 2013-02-15 10:39:04 +09:00
Akira Yumiyama 53ff8bab17 update README.md 2013-01-30 17:03:42 +09:00
Akira Yumiyama aadcbb1690 add mrbgem test runner 2013-01-30 15:20:41 +09:00
Akira Yumiyama 0786e37ed6 update mrbgem.rake 2013-01-30 15:20:10 +09:00
Akira Yumiyama a0161d69a8 typo fix on mrbgem.rake 2013-01-24 10:12:02 +09:00
Akira Yumiyama f70a45ad3a update mrbgem.rake 2013-01-24 10:09:15 +09:00
Akira Yumiyama 558f6fc090 update mrbgem.rake 2013-01-24 09:00:55 +09:00
Akira Yumiyama e734ab3f95 add mrb_mruby_pack_gem_final 2013-01-24 09:00:40 +09:00
Akira Yumiyama 209ad3171d add mrbgem.rake 2013-01-04 00:04:02 +09:00
Akira Yumiyama fb79282a5b add README.md 2012-12-31 13:15:30 +09:00
Akira Yumiyama e205905d02 mruby-pack 2012-12-31 11:38:22 +09:00
295 changed files with 26621 additions and 5763 deletions
+2
View File
@@ -16,7 +16,9 @@
.ccmalloc
.svn
/.git
cscope.files
cscope.out
tags
/src/y.tab.c
/bin
/build
+3214
View File
File diff suppressed because it is too large Load Diff
+3 -9
View File
@@ -7,20 +7,14 @@ matrix:
- os: linux
sudo: 9000
- os: osx
osx_image: xcod6.4
osx_image: xcode7.1
addons:
apt:
packages:
- gperf
env:
MRUBY_CONFIG=travis_config.rb
env: MRUBY_CONFIG=travis_config.rb
script: "./minirake all test"
notifications:
# Update mruby-head installed on Travis CI so other projects can test against it.
webhooks:
urls:
- "https://rubies.travis-ci.org/rebuild/mruby-head"
on_success: always
on_failure: never
+4
View File
@@ -34,3 +34,7 @@ Original Authors "mruby developers" are:
Yuichi Osawa
Terence Lee
Zachary Scott
Tomasz Dąbrowski
Christopher Aue
Masahiro Wakame
YAMAMOTO Masaya
-15
View File
@@ -1,15 +0,0 @@
Thu Apl 19 17:25:18 2012 Yukihiro Matsumoto <matz@ruby-lang.org>
* first release version 1.0.0 released.
Local variables:
add-log-time-format: (lambda ()
(let* ((time (current-time))
(system-time-locale "C")
(diff (+ (cadr time) 32400))
(lo (% diff 65536))
(hi (+ (car time) (/ diff 65536))))
(format-time-string "%a %b %e %H:%M:%S %Y" (list hi lo) t)))
indent-tabs-mode: t
tab-width: 8
end:
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2015 mruby developers
Copyright (c) 2018 mruby developers
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
+5 -3
View File
@@ -17,7 +17,7 @@ of the Ministry of Economy, Trade and Industry of Japan.
## How to get mruby
The stable version 1.2.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/1.2.0.zip](https://github.com/mruby/mruby/archive/1.2.0.zip)
The stable version 1.4.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/1.4.0.zip](https://github.com/mruby/mruby/archive/1.4.0.zip)
The latest development version of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/zipball/master](https://github.com/mruby/mruby/zipball/master)
@@ -26,13 +26,15 @@ following command:
$ git clone https://github.com/mruby/mruby.git
You can also install and compile mruby using [ruby-install](https://github.com/postmodern/ruby-install), [ruby-build](https://github.com/rbenv/ruby-build) or [rvm](https://github.com/rvm/rvm).
## mruby home-page
The URL of the mruby home-page is: [http://www.mruby.org](http://www.mruby.org).
## Mailing list
We don't have mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby).
We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby).
## How to compile and install (mruby and gems)
@@ -52,7 +54,7 @@ Or
mruby contains a package manager called *mrbgems*. To create extensions
in C and/or Ruby you should create a *GEM*. For a documentation of how to
use mrbgems consult the file [doc/mrbgems/README.md](doc/mrbgems/README.md). For example code of
use mrbgems consult the file [doc/guides/mrbgems.md](doc/guides/mrbgems.md). For example code of
how to use mrbgems look into the folder *examples/mrbgems/*.
## License
+7 -3
View File
@@ -5,10 +5,12 @@ MRUBY_ROOT = File.dirname(File.expand_path(__FILE__))
MRUBY_BUILD_HOST_IS_CYGWIN = RUBY_PLATFORM.include?('cygwin')
MRUBY_BUILD_HOST_IS_OPENBSD = RUBY_PLATFORM.include?('openbsd')
$LOAD_PATH << File.join(MRUBY_ROOT, "lib")
# load build systems
load "#{MRUBY_ROOT}/tasks/ruby_ext.rake"
load "#{MRUBY_ROOT}/tasks/mruby_build.rake"
load "#{MRUBY_ROOT}/tasks/mrbgem_spec.rake"
require "mruby-core-ext"
require "mruby/build"
require "mruby/gem"
# load configuration file
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
@@ -28,6 +30,8 @@ load "#{MRUBY_ROOT}/tasks/libmruby.rake"
load "#{MRUBY_ROOT}/tasks/benchmark.rake"
load "#{MRUBY_ROOT}/tasks/gitlab.rake"
##############################
# generic build targets, rules
task :default => :all
+38
View File
@@ -0,0 +1,38 @@
version: "{build}"
os: Visual Studio 2015
clone_depth: 50
cache:
- win_flex_bison-2.5.10.zip
environment:
matrix:
# Visual Studio 2015 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
machine: amd64
# Visual Studio 2013 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat
machine: amd64
init:
- call "%visualcpp%" %machine%
# For using Rubyinstaller's Ruby 2.4 64bit
- set PATH=C:\Ruby24-x64\bin;%PATH%
- ruby --version
install:
- if not exist win_flex_bison-2.5.10.zip appveyor DownloadFile "https://github.com/lexxmark/winflexbison/releases/download/v.2.5.10/win_flex_bison-2.5.10.zip"
- 7z x -y -owin_flex_bison win_flex_bison-2.5.10.zip > nul
build_script:
- set YACC=.\win_flex_bison\win_bison.exe
- set MRUBY_CONFIG=appveyor_config.rb
- ruby .\minirake test all
+50
View File
@@ -0,0 +1,50 @@
MRuby::Build.new('debug') do |conf|
toolchain :visualcpp
enable_debug
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_STRESS MRB_GC_FIXED_ARENA MRB_METHOD_CACHE)
end
build_mrbc_exec
end
MRuby::Build.new('full-debug') do |conf|
toolchain :visualcpp
enable_debug
# include all core GEMs
conf.gembox 'full-core'
conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)
conf.enable_test
end
MRuby::Build.new do |conf|
toolchain :visualcpp
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
conf.enable_bintest
conf.enable_test
end
MRuby::Build.new('cxx_abi') do |conf|
toolchain :visualcpp
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
conf.enable_bintest
conf.enable_test
enable_cxx_abi
build_mrbc_exec
end
+15 -15
View File
@@ -68,7 +68,7 @@ class Vec
def vnormalize
len = vlength
v = Vec.new(@x, @y, @z)
if len > 1.0e-17 then
if len > 1.0e-17
v.x = v.x / len
v.y = v.y / len
v.z = v.z / len
@@ -92,10 +92,10 @@ class Sphere
b = rs.vdot(ray.dir)
c = rs.vdot(rs) - (@radius * @radius)
d = b * b - c
if d > 0.0 then
if d > 0.0
t = - b - Math.sqrt(d)
if t > 0.0 and t < isect.t then
if t > 0.0 and t < isect.t
isect.t = t
isect.hit = true
isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
@@ -118,16 +118,16 @@ class Plane
d = -@p.vdot(@n)
v = ray.dir.vdot(@n)
v0 = v
if v < 0.0 then
if v < 0.0
v0 = -v
end
if v0 < 1.0e-17 then
if v0 < 1.0e-17
return
end
t = -(ray.org.vdot(@n) + d) / v
if t > 0.0 and t < isect.t then
if t > 0.0 and t < isect.t
isect.hit = true
isect.t = t
isect.n = @n
@@ -170,10 +170,10 @@ end
def clamp(f)
i = f * 255.5
if i > 255.0 then
if i > 255.0
i = 255.0
end
if i < 0.0 then
if i < 0.0
i = 0.0
end
i.to_i
@@ -183,11 +183,11 @@ def otherBasis(basis, n)
basis[2] = Vec.new(n.x, n.y, n.z)
basis[1] = Vec.new(0.0, 0.0, 0.0)
if n.x < 0.6 and n.x > -0.6 then
if n.x < 0.6 and n.x > -0.6
basis[1].x = 1.0
elsif n.y < 0.6 and n.y > -0.6 then
elsif n.y < 0.6 and n.y > -0.6
basis[1].y = 1.0
elsif n.z < 0.6 and n.z > -0.6 then
elsif n.z < 0.6 and n.z > -0.6
basis[1].z = 1.0
else
basis[1].x = 1.0
@@ -221,8 +221,8 @@ class Scene
p0 = Vec.new(isect.pl.x + eps * isect.n.x,
isect.pl.y + eps * isect.n.y,
isect.pl.z + eps * isect.n.z)
nphi.times do |j|
ntheta.times do |i|
nphi.times do
ntheta.times do
r = Rand::rand
phi = 2.0 * 3.14159265 * Rand::rand
x = Math.cos(phi) * Math.sqrt(1.0 - r)
@@ -241,7 +241,7 @@ class Scene
@spheres[1].intersect(ray, occisect)
@spheres[2].intersect(ray, occisect)
@plane.intersect(ray, occisect)
if occisect.hit then
if occisect.hit
occlusion = occlusion + 1.0
else
0.0
@@ -283,7 +283,7 @@ class Scene
@spheres[1].intersect(ray, isect)
@spheres[2].intersect(ray, isect)
@plane.intersect(ray, isect)
if isect.hit then
if isect.hit
col = ambient_occlusion(isect)
rad.x = rad.x + col.x
rad.y = rad.y + col.y
+3 -3
View File
@@ -17,19 +17,19 @@ def test_lists()
# li2 must now be empty
# remove each individual item from right side of li3 and
# append to right side of li2 (reversing list)
while (not li3.empty?)
until li3.empty?
li2.push(li3.pop)
end
# li3 must now be empty
# reverse li1 in place
li1.reverse!
# check that first item is now SIZE
if li1[0] != SIZE then
if li1[0] != SIZE
p "not SIZE"
0
else
# compare li1 and li2 for equality
if li1 != li2 then
if li1 != li2
return(0)
else
# return the length of the list
+16 -3
View File
@@ -16,8 +16,10 @@ MRuby::Build.new do |conf|
# g.cc.flags << '-g' # append cflags in this gem
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# conf.gem :github => 'masuidrive/mrbgems-example', :checksum_hash => '76518e8aecd131d047378448ac8055fa29d974a9'
# conf.gem :git => 'git@github.com:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v'
# conf.gem :core => 'mruby-eval'
# conf.gem :mgem => 'mruby-io'
# conf.gem :github => 'iij/mruby-io'
# conf.gem :git => 'git@github.com:iij/mruby-io.git', :branch => 'master', :options => '-v'
# include the default GEMs
conf.gembox 'default'
@@ -122,6 +124,18 @@ MRuby::Build.new('test') do |conf|
conf.gembox 'default'
end
#MRuby::Build.new('bench') do |conf|
# # Gets set by the VS command prompts.
# if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
# toolchain :visualcpp
# else
# toolchain :gcc
# conf.cc.flags << '-O3'
# end
#
# conf.gembox 'default'
#end
# Define cross build settings
# MRuby::CrossBuild.new('32bit') do |conf|
# toolchain :gcc
@@ -134,5 +148,4 @@ end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
#
# conf.test_runner.command = 'env'
#
# end
+19 -12
View File
@@ -67,7 +67,7 @@ toolchain :clang
Toolchain configuration for Visual Studio on Windows. If you use the
[Visual Studio Command Prompt](http://msdn.microsoft.com/en-us/library/ms229859\(v=vs.110\).aspx),
you normally do not have to specify this manually, since it gets automatically detected by our build process.
```
```ruby
toolchain :visualcpp
```
@@ -241,25 +241,32 @@ conf.enable_bintest
### C++ ABI
mruby can use C++ exception to raise exception internally.
It is called C++ ABI mode.
By using C++ exception it can release C++ stack object correctly.
Whenever you mix C++ code C++ ABI mode would be enabled automatically.
If you need to enable C++ ABI mode explicitly add the following:
By default, mruby uses setjmp/longjmp to implement its
exceptions. But it doesn't release C++ stack object
correctly. To support mrbgems written in C++, mruby can be
configured to use C++ exception.
There are two levels of C++ exception handling. The one is
```enable_cxx_exception``` that enables C++ exception, but
uses C ABI. The other is ```enable_cxx_abi``` where all
files are compiled by C++ compiler.
When you mix C++ code, C++ exception would be enabled automatically.
If you need to enable C++ exception explicitly add the following:
```ruby
conf.enable_cxx_abi
conf.enable_cxx_exception
```
#### C++ exception disabling.
If you need to force C++ exception disable
(For example using a compiler option to disable C++ exception)
add following:
If your compiler does not support C++ and you want to ensure
you don't use mrbgem written in C++, you can explicitly disable
C++ exception, add following:
```ruby
conf.disable_cxx_exception
```
Note that it must be called before ```enable_cxx_abi``` or ```gem``` method.
and you will get an error when you try to use C++ gem.
Note that it must be called before ```enable_cxx_exception``` or ```gem``` method.
### Debugging mode
+1 -1
View File
@@ -38,7 +38,7 @@ To confirm mrdb was installed properly, run mrdb with the `--version` option:
```bash
$ mrdb --version
mruby 1.2.0 (2014-11-17)
mruby 1.4.0 (2018-1-16)
```
## 2.2 Basic Operation
+54 -48
View File
@@ -1,7 +1,9 @@
# How to use `mrb_gc_arena_save()`/`mrb_gc_arena_restore()`
# How to use `mrb_gc_arena_save()`/`mrb_gc_arena_restore()`/`mrb_gc_protect()`
This is basically English translation of [Matz's blog post](http://www.rubyist.net/~matz/20130731.html) written in Japanese.
Some parts are updated to reflect recent changes.
_This is an English translation of [Matz's blog post][matz blog post]
written in Japanese._
_Some parts are updated to reflect recent changes._
[matz blog post]: http://www.rubyist.net/~matz/20130731.html
When you are extending mruby using C language, you may encounter
mysterious "arena overflow error" or memory leak or very slow
@@ -10,7 +12,7 @@ implementing "conservative GC".
GC (garbage collector) must ensure that object is "alive", in other
words, that it is referenced by somewhere from program. This can be
determined by checking that that object can be directly or indirectly
determined by checking if the object can be directly or indirectly
referenced by root. The local variables, global variables and
constants etc are root.
@@ -22,7 +24,7 @@ by C variable is also "alive", but mruby GC cannot aware of this, so
it might mistakenly recognize the objects referenced by only C
variables as dead.
It is a fatal bug for GC to collect live objects.
This can be a fatal bug if the GC tries to collect a live object.
In CRuby, we scan C stack area, and use C variable as root to check
whether object is alive or not. Of course, because we are accessing C
@@ -32,60 +34,64 @@ pointer, then assume it as a pointer. We call it "conservative".
By the way, CRuby's "conservative GC" has some problems.
Its biggest problem is we have no way to access to the stack area in
The biggest problem is we have no way to access to the stack area in
portable way. Therefore, we cannot use this method if we'd like to
implement highly portable runtime, like mruby.
So we came up an another plan to implement "conservative GC" in mruby.
So we came up with an another plan to implement "conservative GC" in mruby.
Again, the problem is that there is an object which was created in C
function, and is not referenced by Ruby world, and cannot be treated
as garbage.
Again, the problem is when an object which was created in C function, becomes
no longer referenced in the Ruby world, and cannot be treated as garbage.
In mruby, we recognize all objects created in C function are alive.
Then we have no problem such as recognizing live object as dead.
Then we have no problem such as confusing a live object as dead.
This means that because we cannot collect truly dead object, we may
get a little bit less efficiency, but GC itself is highly portable.
lose efficiency, but as a trade-off the GC itself is highly portable.
We can say goodbye to the problem that GC deletes live objects due to
optimization which sometimes occurs in CRuby.
According to this idea, we have a table, called "GC arena", which
remembers objects created in C function. The arena is stack
structure, when C function execution is returned to mruby VM, all
objects registered in the arena are popped.
remembers objects created in C function.
This works very well, but GC arena causes another problem. "arena
overflow error" or memory leak.
The arena is stack structure, when C function execution is returned to mruby
VM, all objects registered in the arena are popped.
This works very well, but can cause another problem: "arena overflow error" or
memory leak.
As of this writing, mruby automatically extend arena to remember
objects (See `MRB_GC_FIXED_ARENA` and `MRB_GC_ARENA_SIZE` in
doc/mrbconf/README.md). If you keep creating objects in C functions,
it increases memory usage, since GC never kick in. This memory usage
may look like memory leak, and also makes execution slower.
doc/guides/mrbconf.md).
If you create many objects in C functions, memory usage will increase, since
GC never kick in. This memory usage may look like memory leak, but will also
make execution slower as more memory will need to be allocated.
With the build time configuration, you can limit the maximum size of
arena (e.g., 100). Then if you create many objects, arena overflows,
thus you will get "arena overflow error".
thus you will get an "arena overflow error".
To workaround these problems, we have `mrb_gc_arena_save()` and
`mrb_gc_arena_restore()` functions.
`int mrb_gc_arena_save(mrb)` returns the current position of the stack
top of GC arena, and `void mrb_gc_arena_restore(mrb, idx)` sets the
stack top position to back to given idx. We uses them like so:
stack top position to back to given `idx`.
We can use them like this:
```c
int arena_idx = mrb_gc_arena_save(mrb);
...create objects...
// ...create objects...
mrb_gc_arena_restore(mrb, arena_idx);
```
In mruby, C function call are surrounded by this save/restore, but we
In mruby, C function calls are surrounded by this save/restore, but we
can further optimize memory usage by surrounding save/restore, and can
avoid arena overflow.
avoid creating arena overflow bugs.
Let's take a real example. Here is the source code of `Array#inspect`:
@@ -108,14 +114,14 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
mrb_ary_push(mrb, list, ary);
arystr = mrb_str_buf_new(mrb, 64);
mrb_str_buf_cat(mrb, arystr, head, sizeof(head));
arystr = mrb_str_new_capa(mrb, 64);
mrb_str_cat(mrb, arystr, head, sizeof(head));
for(i=0; i<RARRAY_LEN(ary); i++) {
int ai = mrb_gc_arena_save(mrb);
if (i > 0) {
mrb_str_buf_cat(mrb, arystr, sep, sizeof(sep));
mrb_str_cat(mrb, arystr, sep, sizeof(sep));
}
if (mrb_array_p(RARRAY_PTR(ary)[i])) {
s = inspect_ary(mrb, RARRAY_PTR(ary)[i], list);
@@ -123,49 +129,49 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
else {
s = mrb_inspect(mrb, RARRAY_PTR(ary)[i]);
}
mrb_str_buf_cat(mrb, arystr, RSTRING_PTR(s), RSTRING_LEN(s));
mrb_str_cat(mrb, arystr, RSTRING_PTR(s), RSTRING_LEN(s));
mrb_gc_arena_restore(mrb, ai);
}
mrb_str_buf_cat(mrb, arystr, tail, sizeof(tail));
mrb_str_cat(mrb, arystr, tail, sizeof(tail));
mrb_ary_pop(mrb, list);
return arystr;
}
```
This is a real example, so a little bit complicated, so bear with me.
This is a real example, so a little bit complicated, but bear with me.
The essence of `Array#inspect` is that after stringifying each element
of array using `inspect` method, we join them together so that we can
get `inspect` representation of entire array.
get `inspect` representation of the entire array.
After the `inspect` representation of entire array is created, we no
longer require the individual string representation. That means that
we don't have to register these temporal objects into GC arena.
After the `inspect` representation is created, we no longer require the
individual string representation. This means that we don't have to register
these temporal objects into GC arena.
Therefore, in `ary_inspect()` function, we do:
Therefore, in order to keep the arena size small; the `ary_inspect()` function
will do the following:
* save the position of the stack top using `mrb_gc_arena_save()`.
* get `inspect` representation of each element.
* append it to the constructing entire `inspect` representation of array.
* restore stack top position using `mrb_gc_arena_restore()`.
to keep the arena size small.
Please note that the final `inspect` representation of entire array
was created before the call of `mrb_gc_arena_restore()`. Otherwise,
required temporal object may be deleted by GC.
We may have a usecase that after creating many temporal objects, we'd
We may have a usecase where after creating many temporal objects, we'd
like to keep some of them. In this case, we cannot use the same idea
in `ary_inspect()` like appending objects to existing one. Instead,
after `mrb_gc_arena_restore()`, we register back the objects we'd like
to keep to the arena using `mrb_gc_protect(mrb, obj)`. Use
`mrb_gc_protect()` with caution because its usage could lead to arena
overflow error.
in `ary_inspect()` like appending objects to existing one.
Instead, after `mrb_gc_arena_restore()`, we must re-register the objects we
want to keep in the arena using `mrb_gc_protect(mrb, obj)`.
Use `mrb_gc_protect()` with caution because it could also lead to an "arena
overflow error".
We also have to mention that when `mrb_funcall` is called in top
level, its return value is also registered to GC arena, so calling
them repeatedly eventually lead to arena overflow error. Use
`mrb_gc_arena_save()` and `mrb_gc_arena_restore()` or possible use of
We must also mention that when `mrb_funcall` is called in top level, the return
value is also registered to GC arena, so repeated use of `mrb_funcall` may
eventually lead to an "arena overflow error".
Use `mrb_gc_arena_save()` and `mrb_gc_arena_restore()` or possible use of
`mrb_gc_protect()` to workaround this.
+1 -12
View File
@@ -122,20 +122,9 @@ largest value of required alignment.
* If defined `Float` will be a mruby object with `RBasic`.
## Instance variable configuration.
`MRB_USE_IV_SEGLIST`
* If defined enable segmented list in instance variable table instead of khash.
* Segmented list is a linked list of key and value segments.
* It will linear search instead of hash search.
`MRB_SEGMENT_SIZE`
`MRB_IV_SEGMENT_SIZE`
* Default value is `4`.
* Specifies size of each segment in segment list.
* Ignored when `MRB_USE_IV_SEGLIST` isn't defined.
`MRB_IVHASH_INIT_SIZE`
* Default value is `8`.
* Specifies initial size for instance variable table.
* Ignored when `MRB_USE_IV_SEGLIST` is defined.
## Other configuration.
`MRB_UTF8_STRING`
+3
View File
@@ -153,6 +153,9 @@ MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
# Use latest mruby-onig-regexp from github. (version requirements can be omitted)
spec.add_dependency('mruby-onig-regexp', :github => 'mattn/mruby-onig-regexp')
# You can add extra mgems active only on test
spec.add_test_dependency('mruby-process', :github => 'iij/mruby-process')
end
```
+187
View File
@@ -0,0 +1,187 @@
# Limitations and Differences
The philosophy of mruby is to be a lightweight implementation of
the Ruby ISO standard. These two objectives are partially contradicting.
Ruby is an expressive language with complex implementation details which
are difficult to implement in a lightweight manner. To cope with this,
limitations to the "Ruby Compatibility" are defined.
This document is collecting these limitations.
## Integrity
This document does not contain a complete list of limitations.
Please help to improve it by submitting your findings.
## ```1/2``` gives ```0.5```
Since mruby does not have ```Bignum```, bigger integers are represented
by ```Float``` numbers. To enhance interoperability between ```Fixnum```
and ```Float```, mruby provides ```Float#upto``` and other iterating
methods for the ```Float``` class. As a side effect, ```1/2``` gives ```0.5```
not ```0```.
## ```Array``` passed to ```puts```
Passing an Array to ```puts``` results in different output.
```ruby
puts [1,2,3]
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```
1
2
3
```
#### mruby [1.4.0 (2018-1-16)]
```
[1, 2, 3]
```
## ```Kernel.raise``` in rescue clause
```Kernel.raise``` without arguments does not raise the current exception within
a rescue clause.
```ruby
begin
1 / 0
rescue
raise
end
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```ZeroDivisionError``` is raised.
#### mruby [1.4.0 (2018-1-16)]
No exception is raised.
## Fiber execution can't cross C function boundary
mruby's ```Fiber``` is implemented in a similar way to Lua's co-routine. This
results in the consequence that you can't switch context within C functions.
Only exception is ```mrb_fiber_yield``` at return.
## ```Array``` does not support instance variables
To reduce memory consumption ```Array``` does not support instance variables.
```ruby
class Liste < Array
def initialize(str = nil)
@feld = str
end
end
p Liste.new "foobar"
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
``` [] ```
#### mruby [1.4.0 (2018-1-16)]
```ArgumentError``` is raised.
## Method visibility
For simplicity reasons no method visibility (public/private/protected) is
supported.
```ruby
class VisibleTest
def public_method; end
private
def private_method; end
end
p VisibleTest.new.respond_to?(:private_method, false)
p VisibleTest.new.respond_to?(:private_method, true)
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```
false
true
```
#### mruby [1.4.0 (2018-1-16)]
```
true
true
```
## defined?
The ```defined?``` keyword is considered too complex to be fully
implemented. It is recommended to use ```const_defined?``` and
other reflection methods instead.
```ruby
defined?(Foo)
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```
nil
```
#### mruby [1.4.0 (2018-1-16)]
```NameError``` is raised.
## ```alias``` on global variables
Aliasing a global variable works in CRuby but is not part
of the ISO standard.
```ruby
alias $a $__a__
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
``` nil ```
#### mruby [1.4.0 (2018-1-16)]
Syntax error
## Operator modification
An operator can't be overwritten by the user.
```ruby
class String
def +
end
end
'a' + 'b'
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```ArgumentError``` is raised.
The re-defined ```+``` operator does not accept any arguments.
#### mruby [1.4.0 (2018-1-16)]
``` 'ab' ```
Behavior of the operator wasn't changed.
@@ -11,6 +11,8 @@ MRuby::Gem::Specification.new('ruby_extension_example') do |spec|
# Add libraries
# spec.linker.libraries << 'external_lib'
spec.add_dependency('mruby-print', :core => 'mruby-print')
# Default build files
# spec.rbfiles = Dir.glob("#{dir}/mrblib/*.rb")
# spec.objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
@@ -46,7 +46,6 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(MRB_USE_IV_SEGLIST)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
@@ -0,0 +1,69 @@
# Cross-compiling setup for Intel Edison (poky linux) platform
# Get SDK from here: https://software.intel.com/en-us/iot/hardware/edison/downloads
# REMEMBER to check and update the SDK root in the constant POKY_EDISON_PATH
MRuby::Build.new do |conf|
toolchain :gcc
conf.gembox 'default'
conf.cc.defines = %w(ENABLE_READLINE)
conf.gembox 'default'
#lightweight regular expression
conf.gem :github => "pbosetti/mruby-hs-regexp", :branch => "master"
end
# Define cross build settings
MRuby::CrossBuild.new('core2-32-poky-linux') do |conf|
toolchain :gcc
# Mac OS X
#
POKY_EDISON_PATH = '/opt/poky-edison/1.7.2'
POKY_EDISON_SYSROOT = "#{POKY_EDISON_PATH}/sysroots/core2-32-poky-linux"
POKY_EDISON_X86_PATH = "#{POKY_EDISON_PATH}/sysroots/i386-pokysdk-darwin"
POKY_EDISON_BIN_PATH = "#{POKY_EDISON_X86_PATH}/usr/bin/i586-poky-linux"
conf.cc do |cc|
cc.command = "#{POKY_EDISON_BIN_PATH}/i586-poky-linux-gcc"
cc.include_paths << ["#{POKY_EDISON_SYSROOT}/usr/include", "#{POKY_EDISON_X86_PATH}/usr/include"]
cc.flags = %w(-m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mstackrealign -fno-omit-frame-pointer)
cc.flags << %w(-O2 -pipe -g -feliminate-unused-debug-types)
cc.flags << "--sysroot=#{POKY_EDISON_SYSROOT}"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.defines = %w(ENABLE_READLINE)
end
conf.cxx do |cxx|
cxx.command = "#{POKY_EDISON_BIN_PATH}/i586-poky-linux-g++"
cxx.include_paths = conf.cc.include_paths.dup
cxx.include_paths << ["#{POKY_EDISON_SYSROOT}/usr/include/c++/4.9.1"]
cxx.flags = conf.cc.flags.dup
cxx.defines = conf.cc.defines.dup
cxx.compile_options = conf.cc.compile_options.dup
end
conf.archiver do |archiver|
archiver.command = "#{POKY_EDISON_BIN_PATH}/i586-poky-linux-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
end
conf.linker do |linker|
linker.command = "#{POKY_EDISON_BIN_PATH}/i586-poky-linux-g++"
linker.flags = %w(-m32 -march=i586)
linker.flags << "--sysroot=#{POKY_EDISON_SYSROOT}"
linker.flags << %w(-O1)
linker.libraries = %w(m pthread)
end
#do not build executable test
conf.build_mrbtest_lib_only
conf.gembox 'default'
#lightweight regular expression
conf.gem :github => "pbosetti/mruby-hs-regexp", :branch => "master"
end
+81
View File
@@ -0,0 +1,81 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for RX630
# http://gadget.renesas.com/
#
# Requires gnurx_v14.03
MRuby::CrossBuild.new("RX630") do |conf|
toolchain :gcc
# Linux
BIN_PATH = "/usr/share/gnurx_v14.03_elf-1/bin"
conf.cc do |cc|
cc.command = "#{BIN_PATH}/rx-elf-gcc"
cc.flags = "-Wall -g -O2 -flto -mcpu=rx600 -m64bit-doubles"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
#configuration for low memory environment
cc.defines << %w(MRB_USE_FLOAT)
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
conf.cxx do |cxx|
cxx.command = conf.cc.command.dup
cxx.include_paths = conf.cc.include_paths.dup
cxx.flags = conf.cc.flags.dup
cxx.defines = conf.cc.defines.dup
cxx.compile_options = conf.cc.compile_options.dup
end
conf.linker do |linker|
linker.command="#{BIN_PATH}/rx-elf-ld"
end
conf.archiver do |archiver|
archiver.command = "#{BIN_PATH}/rx-elf-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
end
#no executables
conf.bins = []
#do not build executable test
conf.build_mrbtest_lib_only
#disable C++ exception
conf.disable_cxx_exception
#gems from core
conf.gem :core => "mruby-sprintf"
conf.gem :core => "mruby-print"
conf.gem :core => "mruby-math"
conf.gem :core => "mruby-enum-ext"
conf.gem :core => "mruby-numeric-ext"
#light-weight regular expression
#conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
#Arduino API
#conf.gem :github =>"kyab/mruby-arduino", :branch => "master"
end
@@ -0,0 +1,26 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-arm64-v8a') do |conf|
params = {
:arch => 'arm64-v8a',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
@@ -0,0 +1,26 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi') do |conf|
params = {
:arch => 'armeabi',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
@@ -0,0 +1,28 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi-v7a-neon-hard') do |conf|
params = {
:arch => 'armeabi-v7a',
:mfpu => 'neon',
:mfloat_abi => 'hard',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
@@ -43,7 +43,6 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(MRB_USE_IV_SEGLIST)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
+46 -9
View File
@@ -7,17 +7,60 @@
#ifndef MRUBYCONF_H
#define MRUBYCONF_H
#include <limits.h>
#include <stdint.h>
/* architecture selection: */
/* specify -DMRB_32BIT or -DMRB_64BIT to override */
#if !defined(MRB_32BIT) && !defined(MRB_64BIT)
#if UINT64_MAX == SIZE_MAX
#define MRB_64BIT
#else
#define MRB_32BIT
#endif
#endif
#if defined(MRB_32BIT) && defined(MRB_64BIT)
#error Cannot build for 32 and 64 bit architecture at the same time
#endif
/* configuration options: */
/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
//#define MRB_USE_FLOAT
/* exclude floating point numbers */
//#define MRB_WITHOUT_FLOAT
/* add -DMRB_METHOD_CACHE to use method cache to improve performance */
//#define MRB_METHOD_CACHE
/* size of the method cache (need to be the power of 2) */
//#define MRB_METHOD_CACHE_SIZE (1<<7)
/* add -DMRB_METHOD_TABLE_INLINE unless platform uses MSB of pointers */
//#define MRB_METHOD_TABLE_INLINE
/* turn MRB_METHOD_TABLE_INLINE on for linux by default */
#if !defined(MRB_METHOD_TABLE_INLINE) && defined(__linux__)
# define MRB_METHOD_TABLE_INLINE
#endif
/* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */
//#define MRB_INT16
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT16 */
//#define MRB_INT64
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT */
/* if no specific integer type is chosen */
#if !defined(MRB_INT16) && !defined(MRB_INT32) && !defined(MRB_INT64)
# if defined(MRB_64BIT) && !defined(MRB_NAN_BOXING)
/* Use 64bit integers on 64bit architecture (without MRB_NAN_BOXING) */
# define MRB_INT64
# else
/* Otherwise use 32bit integers */
# define MRB_INT32
# endif
#endif
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT and MRB_WITHOUT_FLOAT */
//#define MRB_NAN_BOXING
/* define on big endian machines; used by MRB_NAN_BOXING */
@@ -35,12 +78,6 @@
/* number of object per heap page */
//#define MRB_HEAP_PAGE_SIZE 1024
/* use segmented list for IV table */
//#define MRB_USE_IV_SEGLIST
/* initial size for IV khash; ignored when MRB_USE_IV_SEGLIST is set */
//#define MRB_IVHASH_INIT_SIZE 8
/* if _etext and _edata available, mruby can reduce memory used by symbols */
//#define MRB_USE_ETEXT_EDATA
@@ -76,10 +113,10 @@
//#define MRB_FIXED_STATE_ATEXIT_STACK
/* -DMRB_DISABLE_XXXX to drop following features */
//#define MRB_DISABLE_STDIO /* use of stdio */
//#define MRB_DISABLE_STDIO /* use of stdio */
/* -DMRB_ENABLE_XXXX to enable following features */
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
/* end of configuration */
+482 -273
View File
File diff suppressed because it is too large Load Diff
+167 -27
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_ARRAY_H
#define MRUBY_ARRAY_H
#include "mruby/common.h"
#include "common.h"
/*
* Array class
@@ -21,22 +21,46 @@ typedef struct mrb_shared_array {
mrb_value *ptr;
} mrb_shared_array;
#define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
struct RArray {
MRB_OBJECT_HEADER;
mrb_int len;
union {
mrb_int capa;
mrb_shared_array *shared;
} aux;
mrb_value *ptr;
struct {
mrb_int len;
union {
mrb_int capa;
mrb_shared_array *shared;
} aux;
mrb_value *ptr;
} heap;
mrb_value embed[MRB_ARY_EMBED_LEN_MAX];
} as;
};
#define mrb_ary_ptr(v) ((struct RArray*)(mrb_ptr(v)))
#define mrb_ary_value(p) mrb_obj_value((void*)(p))
#define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
#define RARRAY_LEN(a) (RARRAY(a)->len)
#define RARRAY_PTR(a) ((const mrb_value*)RARRAY(a)->ptr)
#define MRB_ARY_EMBED_MASK 7
#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
#define ARY_EMBED_PTR(a) (&((a)->as.embed[0]))
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
#define RARRAY_LEN(a) ARY_LEN(RARRAY(a))
#define RARRAY_PTR(a) ARY_PTR(RARRAY(a))
#define ARY_SET_LEN(a,n) do {\
if (ARY_EMBED_P(a)) {\
mrb_assert((n) <= MRB_ARY_EMBED_LEN_MAX); \
ARY_SET_EMBED_LEN(a,n);\
}\
else\
(a)->as.heap.len = (n);\
} while (0)
#define ARY_CAPA(a) (ARY_EMBED_P(a)?MRB_ARY_EMBED_LEN_MAX:(a)->as.heap.aux.capa)
#define MRB_ARY_SHARED 256
#define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED)
#define ARY_SET_SHARED_FLAG(a) ((a)->flags |= MRB_ARY_SHARED)
@@ -54,14 +78,60 @@ MRB_API mrb_value mrb_ary_new_capa(mrb_state*, mrb_int);
* Array.new
*
* @param mrb The mruby state reference.
* @return The initialized array
* @return The initialized array.
*/
MRB_API mrb_value mrb_ary_new(mrb_state *mrb);
/*
* Initializes a new array with initial values
*
* Equivalent to:
*
* Array[value1, value2, ...]
*
* @param mrb The mruby state reference.
* @param size The numer of values.
* @param vals The actual values.
* @return The initialized array.
*/
MRB_API mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals);
/*
* Initializes a new array with two initial values
*
* Equivalent to:
*
* Array[car, cdr]
*
* @param mrb The mruby state reference.
* @param car The first value.
* @param cdr The second value.
* @return The initialized array.
*/
MRB_API mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr);
MRB_API void mrb_ary_concat(mrb_state*, mrb_value, mrb_value);
MRB_API mrb_value mrb_ary_splat(mrb_state*, mrb_value);
/*
* Concatenate two arrays. The target array will be modified
*
* Equivalent to:
* ary.concat(other)
*
* @param mrb The mruby state reference.
* @param self The target array.
* @param other The array that will be concatenated to self.
*/
MRB_API void mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other);
/*
* Create an array from the input. It tries calling to_a on the
* value. If value does not respond to that, it creates a new
* array with just this value.
*
* @param mrb The mruby state reference.
* @param value The value to change into an array.
* @return An array representation of value.
*/
MRB_API mrb_value mrb_ary_splat(mrb_state *mrb, mrb_value value);
/*
* Pushes value into array.
@@ -84,8 +154,8 @@ MRB_API void mrb_ary_push(mrb_state *mrb, mrb_value array, mrb_value value);
* ary.pop
*
* @param mrb The mruby state reference.
* @param ary The array from which the value will be poped.
* @return The poped value.
* @param ary The array from which the value will be popped.
* @return The popped value.
*/
MRB_API mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary);
@@ -117,22 +187,92 @@ MRB_API mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n);
*/
MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val);
MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value a, mrb_value b);
/*
* Replace the array with another array
*
* Equivalent to:
*
* ary.replace(other)
*
* @param mrb The mruby state reference
* @param self The target array.
* @param other The array to replace it with.
*/
MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other);
MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self);
MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int len);
static inline mrb_int
mrb_ary_len(mrb_state *mrb, mrb_value ary)
{
(void)mrb;
mrb_assert(mrb_array_p(ary));
return RARRAY_LEN(ary);
}
/*
* Unshift an element into the array
*
* Equivalent to:
*
* ary.unshift(item)
*
* @param mrb The mruby state reference.
* @param self The target array.
* @param item The item to unshift.
*/
MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
/*
* Get nth element in the array
*
* Equivalent to:
*
* ary[offset]
*
* @param ary The target array.
* @param offset The element position (negative counts from the tail).
*/
MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
/*
* Shifts the first element from the array.
*
* Equivalent to:
*
* ary.shift
*
* @param mrb The mruby state reference.
* @param self The array from which the value will be shifted.
* @return The shifted value.
*/
MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self);
/*
* Removes all elements from the array
*
* Equivalent to:
*
* ary.clear
*
* @param mrb The mruby state reference.
* @param self The target array.
* @return self
*/
MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
/*
* Join the array elements together in a string
*
* Equivalent to:
*
* ary.join(sep="")
*
* @param mrb The mruby state reference.
* @param ary The target array
* @param sep The separater, can be NULL
*/
MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
/*
* Update the capacity of the array
*
* @param mrb The mruby state reference.
* @param ary The target array.
* @param new_len The new capacity of the array
*/
MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
MRB_END_DECL
+22 -13
View File
@@ -11,6 +11,10 @@
# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT conflict <<----
#endif
#ifdef MRB_WITHOUT_FLOAT
# error ---->> MRB_NAN_BOXING and MRB_WITHOUT_FLOAT conflict <<----
#endif
#ifdef MRB_INT64
# error ---->> MRB_NAN_BOXING and MRB_INT64 conflict <<----
#endif
@@ -53,30 +57,35 @@ typedef struct mrb_value {
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
#define mrb_tt(o) ((enum mrb_vtype)(((o).value.ttt & 0xfc000)>>14)-1)
#define mrb_type(o) ((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2))
#define mrb_float(o) (o).f
#define mrb_cptr(o) mrb_ptr(o)
#define mrb_fixnum(o) (o).value.i
#define mrb_symbol(o) (o).value.sym
#ifdef MRB_64BIT
#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
#else
#define BOXNAN_SHIFT_LONG_POINTER(v) 0
#endif
#define BOXNAN_SET_VALUE(o, tt, attr, v) do {\
switch (tt) {\
case MRB_TT_FALSE:\
case MRB_TT_TRUE:\
case MRB_TT_UNDEF:\
case MRB_TT_FIXNUM:\
case MRB_TT_SYMBOL: (o).attr = (v); break;\
default: (o).value.i = 0; (o).value.p = (void*)((uintptr_t)(o).value.p | (((uintptr_t)(v))>>2)); break;\
}\
(o).value.ttt = (0xfff00000|(((tt)+1)<<14));\
(o).attr = (v);\
(o).value.ttt = 0xfff00000 | (((tt)+1)<<14);\
} while (0)
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
(o).value.p = (void*)((uintptr_t)(v)>>2);\
(o).value.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
} while (0)
#define SET_FLOAT_VALUE(mrb,r,v) do { \
if (v != v) { \
(r).value.ttt = 0x7ff80000; \
(r).value.i = 0; \
} else { \
} \
else { \
(r).f = v; \
}} while(0)
@@ -86,8 +95,8 @@ typedef struct mrb_value {
#define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_OBJ_VALUE(r,v) BOXNAN_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_VALUE(r, MRB_TT_CPTR, value.p, v)
#define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_OBJ_VALUE(r, MRB_TT_CPTR, v)
#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
#endif /* MRUBY_BOXING_NAN_H */
+8
View File
@@ -12,7 +12,9 @@
typedef struct mrb_value {
union {
#ifndef MRB_WITHOUT_FLOAT
mrb_float f;
#endif
void *p;
mrb_int i;
mrb_sym sym;
@@ -20,11 +22,15 @@ typedef struct mrb_value {
enum mrb_vtype tt;
} mrb_value;
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
#endif
#define mrb_ptr(o) (o).value.p
#define mrb_cptr(o) mrb_ptr(o)
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float(o) (o).value.f
#endif
#define mrb_fixnum(o) (o).value.i
#define mrb_symbol(o) (o).value.sym
#define mrb_type(o) (o).tt
@@ -39,7 +45,9 @@ typedef struct mrb_value {
#define SET_TRUE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXNIX_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#ifndef MRB_WITHOUT_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v))
#endif
#define SET_SYM_VALUE(r,v) BOXNIX_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_OBJ_VALUE(r,v) BOXNIX_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
#define SET_CPTR_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_CPTR, value.p, v)
+24 -4
View File
@@ -11,10 +11,16 @@
# error MRB_INT16 is too small for MRB_WORD_BOXING.
#endif
#if defined(MRB_INT64) && !defined(MRB_64BIT)
#error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode.
#endif
#ifndef MRB_WITHOUT_FLOAT
struct RFloat {
MRB_OBJECT_HEADER;
mrb_float f;
};
#endif
struct RCptr {
MRB_OBJECT_HEADER;
@@ -22,7 +28,11 @@ struct RCptr {
};
#define MRB_FIXNUM_SHIFT 1
#ifdef MRB_WITHOUT_FLOAT
#define MRB_TT_HAS_BASIC MRB_TT_CPTR
#else
#define MRB_TT_HAS_BASIC MRB_TT_FLOAT
#endif
enum mrb_special_consts {
MRB_Qnil = 0,
@@ -47,22 +57,30 @@ typedef union mrb_value {
mrb_sym sym : (sizeof(mrb_sym) * CHAR_BIT);
};
struct RBasic *bp;
#ifndef MRB_WITHOUT_FLOAT
struct RFloat *fp;
#endif
struct RCptr *vp;
} value;
unsigned long w;
} mrb_value;
MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*);
#ifndef MRB_WITHOUT_FLOAT
MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
#endif
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_pool(mrb,f) mrb_word_boxing_float_pool(mrb,f)
#endif
#define mrb_ptr(o) (o).value.p
#define mrb_cptr(o) (o).value.vp->p
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float(o) (o).value.fp->f
#define mrb_fixnum(o) (o).value.i
#endif
#define mrb_fixnum(o) ((mrb_int)(o).value.i)
#define mrb_symbol(o) (o).value.sym
static inline enum mrb_vtype
@@ -91,18 +109,20 @@ mrb_type(mrb_value o)
#define mrb_undef_p(o) ((o).w == MRB_Qundef)
#define mrb_nil_p(o) ((o).w == MRB_Qnil)
#define BOXWORD_SET_VALUE(o, ttt, attr, v) do {\
#define BOXWORD_SET_VALUE(o, ttt, attr, v) do { \
switch (ttt) {\
case MRB_TT_FALSE: (o).w = (v) ? MRB_Qfalse : MRB_Qnil; break;\
case MRB_TT_TRUE: (o).w = MRB_Qtrue; break;\
case MRB_TT_UNDEF: (o).w = MRB_Qundef; break;\
case MRB_TT_FIXNUM: (o).value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\
case MRB_TT_SYMBOL: (o).value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\
case MRB_TT_FIXNUM: (o).w = 0;(o).value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\
case MRB_TT_SYMBOL: (o).w = 0;(o).value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\
default: (o).w = 0; (o).attr = (v); if ((o).value.bp) (o).value.bp->tt = ttt; break;\
}\
} while (0)
#ifndef MRB_WITHOUT_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) r = mrb_word_boxing_float_value(mrb, v)
#endif
#define SET_CPTR_VALUE(mrb,r,v) r = mrb_word_boxing_cptr_value(mrb, v)
#define SET_NIL_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
#define SET_FALSE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
+11 -6
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_CLASS_H
#define MRUBY_CLASS_H
#include "mruby/common.h"
#include "common.h"
/**
* Class class
@@ -40,8 +40,10 @@ mrb_class(mrb_state *mrb, mrb_value v)
return mrb->symbol_class;
case MRB_TT_FIXNUM:
return mrb->fixnum_class;
#ifndef MRB_WITHOUT_FLOAT
case MRB_TT_FLOAT:
return mrb->float_class;
#endif
case MRB_TT_CPTR:
return mrb->object_class;
case MRB_TT_ENV:
@@ -51,7 +53,8 @@ mrb_class(mrb_state *mrb, mrb_value v)
}
}
// TODO: figure out where to put user flags
/* TODO: figure out where to put user flags */
/* flags bits >= 18 is reserved */
#define MRB_FLAG_IS_PREPENDED (1 << 19)
#define MRB_FLAG_IS_ORIGIN (1 << 20)
#define MRB_CLASS_ORIGIN(c) do {\
@@ -62,6 +65,7 @@ mrb_class(mrb_state *mrb, mrb_value v)
}\
}\
} while (0)
#define MRB_FLAG_IS_INHERITED (1 << 21)
#define MRB_INSTANCE_TT_MASK (0xFF)
#define MRB_SET_INSTANCE_TT(c, tt) c->flags = ((c->flags & ~MRB_INSTANCE_TT_MASK) | (char)tt)
#define MRB_INSTANCE_TT(c) (enum mrb_vtype)(c->flags & MRB_INSTANCE_TT_MASK)
@@ -70,16 +74,17 @@ MRB_API struct RClass* mrb_define_class_id(mrb_state*, mrb_sym, struct RClass*);
MRB_API struct RClass* mrb_define_module_id(mrb_state*, mrb_sym);
MRB_API struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym);
MRB_API struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym);
MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, struct RProc *);
MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t);
MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec);
MRB_API void mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b);
MRB_API struct RClass *mrb_class_outer_module(mrb_state*, struct RClass *);
MRB_API struct RProc *mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
MRB_API struct RProc *mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
MRB_API mrb_method_t mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
MRB_API mrb_method_t mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
MRB_API struct RClass* mrb_class_real(struct RClass* cl);
void mrb_class_name_class(mrb_state*, struct RClass*, struct RClass*, mrb_sym);
mrb_value mrb_class_find_path(mrb_state*, struct RClass*);
void mrb_gc_mark_mt(mrb_state*, struct RClass*);
size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*);
void mrb_gc_free_mt(mrb_state*, struct RClass*);
+7 -2
View File
@@ -1,5 +1,5 @@
/*
** mruby/common.h - mruby common platform definitions
**"common.h - mruby common platform definition"
**
** See Copyright Notice in mruby.h
*/
@@ -9,8 +9,13 @@
#ifdef __cplusplus
#ifdef MRB_ENABLE_CXX_ABI
#define MRB_BEGIN_DECL
#define MRB_END_DECL
#else
# define MRB_BEGIN_DECL extern "C" {
# define MRB_END_DECL }
# define MRB_END_DECL }
#endif
#else
/** Start declarations in C mode */
# define MRB_BEGIN_DECL
+15 -11
View File
@@ -7,14 +7,14 @@
#ifndef MRUBY_COMPILE_H
#define MRUBY_COMPILE_H
#include "mruby/common.h"
#include "common.h"
/**
* MRuby Compiler
*/
MRB_BEGIN_DECL
#include "mruby.h"
#include <mruby.h>
struct mrb_jmpbuf;
@@ -33,6 +33,8 @@ typedef struct mrbc_context {
mrb_bool no_exec:1;
mrb_bool keep_lv:1;
mrb_bool no_optimize:1;
size_t parser_nerr;
} mrbc_context;
MRB_API mrbc_context* mrbc_context_new(mrb_state *mrb);
@@ -40,8 +42,6 @@ MRB_API void mrbc_context_free(mrb_state *mrb, mrbc_context *cxt);
MRB_API const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
MRB_API void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data);
MRB_API mrb_value mrb_toplevel_run_keep(mrb_state*, struct RProc*, unsigned int);
/* AST node structure */
typedef struct mrb_ast_node {
struct mrb_ast_node *car, *cdr;
@@ -104,7 +104,8 @@ struct mrb_parser_heredoc_info {
mrb_ast_node *doc;
};
#define MRB_PARSER_BUF_SIZE 1024
#define MRB_PARSER_TOKBUF_MAX 65536
#define MRB_PARSER_TOKBUF_SIZE 256
/* parser structure */
struct mrb_parser_state {
@@ -132,10 +133,12 @@ struct mrb_parser_state {
mrb_ast_node *locals;
mrb_ast_node *pb;
char buf[MRB_PARSER_BUF_SIZE];
int bidx;
char *tokbuf;
char buf[MRB_PARSER_TOKBUF_SIZE];
int tidx;
int tsiz;
mrb_ast_node *all_heredocs; /* list of mrb_parser_heredoc_info* */
mrb_ast_node *all_heredocs; /* list of mrb_parser_heredoc_info* */
mrb_ast_node *heredocs_from_nextline;
mrb_ast_node *parsing_heredoc;
mrb_ast_node *lex_strterm_before_heredoc;
@@ -171,8 +174,9 @@ MRB_API char const* mrb_parser_get_filename(struct mrb_parser_state*, uint16_t i
MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*);
#endif
MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mrbc_context*);
MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t,mrbc_context*);
MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c);
/* program load functions */
#ifndef MRB_DISABLE_STDIO
@@ -180,9 +184,9 @@ MRB_API mrb_value mrb_load_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
#endif
MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s);
MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, int len);
MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, size_t len);
MRB_API mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *cxt);
MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *cxt);
MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrbc_context *cxt);
/** @} */
MRB_END_DECL
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_DATA_H
#define MRUBY_DATA_H
#include "mruby/common.h"
#include "common.h"
/**
* Custom C wrapped data.
+3 -3
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_DEBUG_H
#define MRUBY_DEBUG_H
#include "mruby/common.h"
#include "common.h"
/**
* MRuby Debugging.
@@ -47,13 +47,13 @@ typedef struct mrb_irep_debug_info {
* get line from irep's debug info and program counter
* @return returns NULL if not found
*/
MRB_API const char *mrb_debug_get_filename(mrb_irep *irep, uint32_t pc);
MRB_API const char *mrb_debug_get_filename(mrb_irep *irep, ptrdiff_t pc);
/*
* get line from irep's debug info and program counter
* @return returns -1 if not found
*/
MRB_API int32_t mrb_debug_get_line(mrb_irep *irep, uint32_t pc);
MRB_API int32_t mrb_debug_get_line(mrb_irep *irep, ptrdiff_t pc);
MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file(
mrb_state *mrb, mrb_irep *irep,
+4 -4
View File
@@ -7,9 +7,9 @@
#ifndef MRUBY_DUMP_H
#define MRUBY_DUMP_H
#include "mruby.h"
#include "mruby/irep.h"
#include "mruby/common.h"
#include <mruby.h>
#include <mruby/irep.h>
#include "common.h"
/**
* Dumping compiled mruby script.
@@ -52,7 +52,7 @@ MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
/* Rite Binary File header */
#define RITE_BINARY_IDENT "RITE"
#define RITE_BINARY_IDENT_LIL "ETIR"
#define RITE_BINARY_FORMAT_VER "0003"
#define RITE_BINARY_FORMAT_VER "0004"
#define RITE_COMPILER_NAME "MATZ"
#define RITE_COMPILER_VERSION "0000"
+8 -2
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_ERROR_H
#define MRUBY_ERROR_H
#include "mruby/common.h"
#include "common.h"
/**
* MRuby error handling.
@@ -24,7 +24,7 @@ struct RException {
MRB_API void mrb_sys_fail(mrb_state *mrb, const char *mesg);
MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
MRB_API mrb_value mrb_make_exception(mrb_state *mrb, int argc, const mrb_value *argv);
MRB_API mrb_value mrb_make_exception(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
MRB_API mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
MRB_API mrb_value mrb_get_backtrace(mrb_state *mrb);
MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...);
@@ -32,6 +32,12 @@ MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_va
/* declaration for fail method */
MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value);
struct RBreak {
MRB_OBJECT_HEADER;
struct RProc *proc;
mrb_value val;
};
/**
* Protect
*
+16 -2
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_GC_H
#define MRUBY_GC_H
#include "mruby/common.h"
#include "common.h"
/**
* Uncommon memory management stuffs.
@@ -17,7 +17,9 @@ MRB_BEGIN_DECL
struct mrb_state;
typedef void (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data);
#define MRB_EACH_OBJ_OK 0
#define MRB_EACH_OBJ_BREAK 1
typedef int (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data);
void mrb_objspace_each_objects(struct mrb_state *mrb, mrb_each_object_callback *callback, void *data);
MRB_API void mrb_free_context(struct mrb_state *mrb, struct mrb_context *c);
@@ -31,6 +33,13 @@ typedef enum {
MRB_GC_STATE_SWEEP
} mrb_gc_state;
/* Disable MSVC warning "C4200: nonstandard extension used: zero-sized array
* in struct/union" when in C++ mode */
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4200)
#endif
typedef struct mrb_heap_page {
struct RBasic *freelist;
struct mrb_heap_page *prev;
@@ -41,6 +50,10 @@ typedef struct mrb_heap_page {
void *objects[];
} mrb_heap_page;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
typedef struct mrb_gc {
mrb_heap_page *heaps; /* heaps for GC */
mrb_heap_page *sweeps;
@@ -62,6 +75,7 @@ typedef struct mrb_gc {
size_t threshold;
int interval_ratio;
int step_ratio;
mrb_bool iterating :1;
mrb_bool disabled :1;
mrb_bool full :1;
mrb_bool generational :1;
+107 -4
View File
@@ -7,7 +7,8 @@
#ifndef MRUBY_HASH_H
#define MRUBY_HASH_H
#include "mruby/common.h"
#include "common.h"
#include <mruby/khash.h>
/**
* Hash class
@@ -23,42 +24,142 @@ struct RHash {
#define mrb_hash_ptr(v) ((struct RHash*)(mrb_ptr(v)))
#define mrb_hash_value(p) mrb_obj_value((void*)(p))
MRB_API mrb_value mrb_hash_new_capa(mrb_state*, int);
MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int);
/*
* Initializes a new hash.
*
* Equivalent to:
*
* Hash.new
*
* @param mrb The mruby state reference.
* @return The initialized hash.
*/
MRB_API mrb_value mrb_hash_new(mrb_state *mrb);
/*
* Sets a keys and values to hashes.
*
* Equivalent to:
*
* hash[key] = val
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @param key The key to set.
* @param val The value to set.
* @return The value.
*/
MRB_API void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val);
/*
* Gets a value from a key.
* Gets a value from a key. If the key is not found, the default of the
* hash is used.
*
* Equivalent to:
*
* hash[key]
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @param key The key to get.
* @return The found value.
*/
MRB_API mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
/*
* Gets a value from a key. If the key is not found, the default parameter is
* used.
*
* Equivalent to:
*
* hash.hash_key?(key) ? hash[key] : def
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @param key The key to get.
* @param def The default value.
* @return The found value.
*/
MRB_API mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def);
/*
* Deletes hash key and value pair.
*
* Equivalent to:
*
* hash.delete(key)
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @param key The key to delete.
* @return The deleted value.
*/
MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key);
/*
* Gets an array of keys.
*
* Equivalent to:
*
* hash.keys
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @return An array with the keys of the hash.
*/
MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash);
MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
/*
* Check if the hash is empty
*
* Equivalent to:
*
* hash.empty?
*
* @param mrb The mruby state reference.
* @param self The target hash.
* @return True if the hash is empty, false otherwise.
*/
MRB_API mrb_value mrb_hash_empty_p(mrb_state *mrb, mrb_value self);
/*
* Gets an array of values.
*
* Equivalent to:
*
* hash.values
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @return An array with the values of the hash.
*/
MRB_API mrb_value mrb_hash_values(mrb_state *mrb, mrb_value hash);
/*
* Clears the hash.
*
* Equivalent to:
*
* hash.clear
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @return The hash
*/
MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
/* declaration of struct kh_ht */
/* be careful when you touch the internal */
typedef struct {
mrb_value v;
mrb_int n;
} mrb_hash_value;
KHASH_DECLARE(ht, mrb_value, mrb_hash_value, TRUE)
/* RHASH_TBL allocates st_table if not available. */
#define RHASH(obj) ((struct RHash*)(mrb_ptr(obj)))
#define RHASH_TBL(h) (RHASH(h)->ht)
@@ -66,7 +167,9 @@ MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
#define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h)
MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);
#define MRB_HASH_PROC_DEFAULT 256
#define MRB_HASH_DEFAULT 1
#define MRB_HASH_PROC_DEFAULT 2
#define MRB_RHASH_DEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_DEFAULT)
#define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT)
/* GC functions */
+5 -3
View File
@@ -7,8 +7,8 @@
#ifndef MRUBY_IREP_H
#define MRUBY_IREP_H
#include "mruby/common.h"
#include "mruby/compile.h"
#include "common.h"
#include <mruby/compile.h>
/**
* Compiled mruby scripts.
@@ -39,11 +39,12 @@ typedef struct mrb_irep {
struct mrb_locals *lv;
/* debug info */
mrb_bool own_filename;
const char *filename;
uint16_t *lines;
struct mrb_irep_debug_info* debug_info;
size_t ilen, plen, slen, rlen, refcnt;
int ilen, plen, slen, rlen, refcnt;
} mrb_irep;
#define MRB_ISEQ_NO_FREE 1
@@ -54,6 +55,7 @@ MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrbc_context*);
void mrb_irep_free(mrb_state*, struct mrb_irep*);
void mrb_irep_incref(mrb_state*, struct mrb_irep*);
void mrb_irep_decref(mrb_state*, struct mrb_irep*);
void mrb_irep_cutref(mrb_state*, struct mrb_irep*);
MRB_END_DECL
+47
View File
@@ -0,0 +1,47 @@
/*
** mruby/istruct.h - Inline structures
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_ISTRUCT_H
#define MRUBY_ISTRUCT_H
#include "common.h"
#include <string.h>
/**
* Inline structures that fit in RVALUE
*
* They cannot have finalizer, and cannot have instance variables.
*/
MRB_BEGIN_DECL
#define ISTRUCT_DATA_SIZE (sizeof(void*) * 3)
struct RIstruct {
MRB_OBJECT_HEADER;
char inline_data[ISTRUCT_DATA_SIZE];
};
#define RISTRUCT(obj) ((struct RIstruct*)(mrb_ptr(obj)))
#define ISTRUCT_PTR(obj) (RISTRUCT(obj)->inline_data)
MRB_INLINE mrb_int mrb_istruct_size()
{
return ISTRUCT_DATA_SIZE;
}
MRB_INLINE void* mrb_istruct_ptr(mrb_value object)
{
return ISTRUCT_PTR(object);
}
MRB_INLINE void mrb_istruct_copy(mrb_value dest, mrb_value src)
{
memcpy(ISTRUCT_PTR(dest), ISTRUCT_PTR(src), ISTRUCT_DATA_SIZE);
}
MRB_END_DECL
#endif /* MRUBY_ISTRUCT_H */
+2 -2
View File
@@ -9,8 +9,8 @@
#include <string.h>
#include "mruby.h"
#include "mruby/common.h"
#include <mruby.h>
#include "common.h"
/**
* khash definitions used in mruby's hash table.
+89 -38
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_NUMERIC_H
#define MRUBY_NUMERIC_H
#include "mruby/common.h"
#include "common.h"
/**
* Numeric class and it's sub-classes.
@@ -16,68 +16,90 @@
*/
MRB_BEGIN_DECL
#define POSFIXABLE(f) ((f) <= MRB_INT_MAX)
#define NEGFIXABLE(f) ((f) >= MRB_INT_MIN)
#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
#define TYPED_POSFIXABLE(f,t) ((f) <= (t)MRB_INT_MAX)
#define TYPED_NEGFIXABLE(f,t) ((f) >= (t)MRB_INT_MIN)
#define TYPED_FIXABLE(f,t) (TYPED_POSFIXABLE(f,t) && TYPED_NEGFIXABLE(f,t))
#define POSFIXABLE(f) TYPED_POSFIXABLE(f,mrb_int)
#define NEGFIXABLE(f) TYPED_NEGFIXABLE(f,mrb_int)
#define FIXABLE(f) TYPED_FIXABLE(f,mrb_int)
#ifndef MRB_WITHOUT_FLOAT
#define FIXABLE_FLOAT(f) TYPED_FIXABLE(f,double)
#endif
#ifndef MRB_WITHOUT_FLOAT
MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val);
MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, int base);
#endif
MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base);
/* ArgumentError if format string doesn't match /%(\.[0-9]+)?[aAeEfFgG]/ */
#ifndef MRB_WITHOUT_FLOAT
MRB_API mrb_value mrb_float_to_str(mrb_state *mrb, mrb_value x, const char *fmt);
MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x);
#endif
mrb_value mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y);
#define MRB_UINT_MAKE2(n) uint ## n ## _t
#define MRB_UINT_MAKE(n) MRB_UINT_MAKE2(n)
#define mrb_uint MRB_UINT_MAKE(MRB_INT_BIT)
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#define MRB_INT_OVERFLOW_MASK ((mrb_uint)1 << (MRB_INT_BIT - 1 - MRB_FIXNUM_SHIFT))
#if (defined(__GNUC__) && __GNUC__ >= 5) || \
(__has_builtin(__builtin_add_overflow) && \
__has_builtin(__builtin_sub_overflow) && \
__has_builtin(__builtin_mul_overflow))
# define MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
#endif
/* Idea from Potion: https://github.com/perl11/potion (MIT) */
#if (defined(__clang__) && ((__clang_major__ > 3) || (__clang_major__ == 3 && __clang_minor__ >= 4))) \
|| (defined(__GNUC__) && __GNUC__ >= 5)
/*
// Clang 3.8 and 3.9 have problem compiling mruby in 32-bit mode, when MRB_INT64 is set
// because of missing __mulodi4 and similar functions in its runtime. We need to use custom
// implementation for them.
*/
#ifdef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
#if defined(__clang__) && (__clang_major__ == 3) && (__clang_minor__ >= 8) && \
defined(MRB_32BIT) && defined(MRB_INT64)
#undef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
#endif
#endif
#ifdef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
#ifndef MRB_WORD_BOXING
# define WBCHK(x) 0
#else
# define WBCHK(x) !FIXABLE(x)
#endif
static inline mrb_bool
mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum)
{
mrb_bool of;
#ifdef MRB_INT64
long long val;
of = __builtin_saddll_overflow(augend, addend, &val) ||
#else
int val;
of = __builtin_sadd_overflow(augend, addend, &val) ||
#endif
(val > MRB_INT_MAX) || (val < MRB_INT_MIN);
*sum = (mrb_int) val;
return of;
return __builtin_add_overflow(augend, addend, sum) || WBCHK(*sum);
}
static inline mrb_bool
mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference)
{
mrb_bool of;
#ifdef MRB_INT64
long long val;
of = __builtin_ssubll_overflow(minuend, subtrahend, &val) ||
#else
int val;
of = __builtin_ssub_overflow(minuend, subtrahend, &val) ||
#endif
(val > MRB_INT_MAX) || (val < MRB_INT_MIN);
*difference = (mrb_int) val;
return of;
return __builtin_sub_overflow(minuend, subtrahend, difference) || WBCHK(*difference);
}
static inline mrb_bool
mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
{
return __builtin_mul_overflow(multiplier, multiplicand, product) || WBCHK(*product);
}
#undef WBCHK
#else
#define MRB_UINT_MAKE2(n) uint ## n ## _t
#define MRB_UINT_MAKE(n) MRB_UINT_MAKE2(n)
#define mrb_uint MRB_UINT_MAKE(MRB_INT_BIT)
#define MRB_INT_OVERFLOW_MASK ((mrb_uint)1 << (MRB_INT_BIT - 1 - MRB_FIXNUM_SHIFT))
static inline mrb_bool
mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum)
{
@@ -98,13 +120,42 @@ mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference)
return !!(((x ^ z) & (~y ^ z)) & MRB_INT_OVERFLOW_MASK);
}
static inline mrb_bool
mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
{
#if MRB_INT_BIT == 32
int64_t n = (int64_t)multiplier * multiplicand;
*product = (mrb_int)n;
return !FIXABLE(n);
#else
if (multiplier > 0) {
if (multiplicand > 0) {
if (multiplier > MRB_INT_MAX / multiplicand) return TRUE;
}
else {
if (multiplicand < MRB_INT_MAX / multiplier) return TRUE;
}
}
else {
if (multiplicand > 0) {
if (multiplier < MRB_INT_MAX / multiplicand) return TRUE;
}
else {
if (multiplier != 0 && multiplicand < MRB_INT_MAX / multiplier) return TRUE;
}
}
*product = multiplier * multiplicand;
return FALSE;
#endif
}
#undef MRB_INT_OVERFLOW_MASK
#undef mrb_uint
#undef MRB_UINT_MAKE
#undef MRB_UINT_MAKE2
#endif
MRB_END_DECL
#endif /* MRUBY_NUMERIC_H */
+6
View File
@@ -22,6 +22,12 @@ struct RBasic {
};
#define mrb_basic_ptr(v) ((struct RBasic*)(mrb_ptr(v)))
/* flags bits >= 18 is reserved */
#define MRB_FLAG_IS_FROZEN (1 << 18)
#define MRB_FROZEN_P(o) ((o)->flags & MRB_FLAG_IS_FROZEN)
#define MRB_SET_FROZEN_FLAG(o) ((o)->flags |= MRB_FLAG_IS_FROZEN)
#define MRB_UNSET_FROZEN_FLAG(o) ((o)->flags &= ~MRB_FLAG_IS_FROZEN)
struct RObject {
MRB_OBJECT_HEADER;
struct iv_tbl *iv;
+2 -1
View File
@@ -82,7 +82,8 @@ enum {
OP_JMPIF,/* A sBx if R(A) pc+=sBx */
OP_JMPNOT,/* A sBx if !R(A) pc+=sBx */
OP_ONERR,/* sBx rescue_push(pc+sBx) */
OP_RESCUE,/* A clear(exc); R(A) := exception (ignore when A=0) */
OP_RESCUE,/* A B C if A (if C exc=R(A) else R(A) := exc);
if B R(B) := exc.isa?(R(B)); clear(exc) */
OP_POPERR,/* A A.times{rescue_pop()} */
OP_RAISE,/* A raise(R(A)) */
OP_EPUSH,/* Bx ensure_push(SEQ[Bx]) */
+68 -13
View File
@@ -7,8 +7,8 @@
#ifndef MRUBY_PROC_H
#define MRUBY_PROC_H
#include "mruby/common.h"
#include "mruby/irep.h"
#include "common.h"
#include <mruby/irep.h>
/**
* Proc class
@@ -18,14 +18,20 @@ MRB_BEGIN_DECL
struct REnv {
MRB_OBJECT_HEADER;
mrb_value *stack;
struct mrb_context *cxt;
mrb_sym mid;
ptrdiff_t cioff;
};
#define MRB_SET_ENV_STACK_LEN(e,len) (e)->flags = (unsigned int)(len)
#define MRB_ENV_STACK_LEN(e) ((mrb_int)(e)->flags)
#define MRB_ENV_UNSHARE_STACK(e) ((e)->cioff = -1)
#define MRB_ENV_STACK_SHARED_P(e) ((e)->cioff >= 0)
/* flags (21bits): 1(shared flag):10(cioff/bidx):10(stack_len) */
#define MRB_ENV_SET_STACK_LEN(e,len) (e)->flags = (((e)->flags & ~0x3ff)|((unsigned int)(len) & 0x3ff))
#define MRB_ENV_STACK_LEN(e) ((mrb_int)((e)->flags & 0x3ff))
#define MRB_ENV_STACK_UNSHARED (1<<20)
#define MRB_ENV_UNSHARE_STACK(e) (e)->flags |= MRB_ENV_STACK_UNSHARED
#define MRB_ENV_STACK_SHARED_P(e) (((e)->flags & MRB_ENV_STACK_UNSHARED) == 0)
#define MRB_ENV_BIDX(e) (((e)->flags >> 10) & 0x3ff)
#define MRB_ENV_SET_BIDX(e,idx) (e)->flags = (((e)->flags & ~(0x3ff<<10))|((unsigned int)(idx) & 0x3ff)<<10)
void mrb_env_unshare(mrb_state*, struct REnv*);
struct RProc {
MRB_OBJECT_HEADER;
@@ -33,8 +39,11 @@ struct RProc {
mrb_irep *irep;
mrb_func_t func;
} body;
struct RClass *target_class;
struct REnv *env;
struct RProc *upper;
union {
struct RClass *target_class;
struct REnv *env;
} e;
};
/* aspec access */
@@ -46,10 +55,29 @@ struct RProc {
#define MRB_ASPEC_KDICT(a) ((a) & (1<<1))
#define MRB_ASPEC_BLOCK(a) ((a) & 1)
#define MRB_PROC_CFUNC 128
#define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC) != 0)
#define MRB_PROC_CFUNC_FL 128
#define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC_FL) != 0)
#define MRB_PROC_CFUNC(p) (p)->body.func
#define MRB_PROC_STRICT 256
#define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0)
#define MRB_PROC_ORPHAN 512
#define MRB_PROC_ORPHAN_P(p) (((p)->flags & MRB_PROC_ORPHAN) != 0)
#define MRB_PROC_ENVSET 1024
#define MRB_PROC_ENV_P(p) (((p)->flags & MRB_PROC_ENVSET) != 0)
#define MRB_PROC_ENV(p) (MRB_PROC_ENV_P(p) ? (p)->e.env : NULL)
#define MRB_PROC_TARGET_CLASS(p) (MRB_PROC_ENV_P(p) ? (p)->e.env->c : (p)->e.target_class)
#define MRB_PROC_SET_TARGET_CLASS(p,tc) do {\
if (MRB_PROC_ENV_P(p)) {\
(p)->e.env->c = (tc);\
mrb_field_write_barrier(mrb, (struct RBasic*)(p)->e.env, (struct RBasic*)tc);\
}\
else {\
(p)->e.target_class = (tc);\
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)tc);\
}\
} while (0)
#define MRB_PROC_SCOPE 2048
#define MRB_PROC_SCOPE_P(p) (((p)->flags & MRB_PROC_SCOPE) != 0)
#define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v)))
@@ -68,8 +96,35 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state*, mrb_int);
/* old name */
#define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx)
#include "mruby/khash.h"
KHASH_DECLARE(mt, mrb_sym, struct RProc*, TRUE)
#ifdef MRB_METHOD_TABLE_INLINE
#define MRB_METHOD_FUNC_FL ((uintptr_t)1U<<(sizeof(uintptr_t)*8-1))
#define MRB_METHOD_FUNC_P(m) ((uintptr_t)(m)&MRB_METHOD_FUNC_FL)
#define MRB_METHOD_FUNC(m) ((mrb_func_t)((uintptr_t)(m)&(~MRB_METHOD_FUNC_FL)))
#define MRB_METHOD_FROM_FUNC(m,fn) m=(mrb_method_t)((struct RProc*)((uintptr_t)(fn)|MRB_METHOD_FUNC_FL))
#define MRB_METHOD_FROM_PROC(m,pr) m=(mrb_method_t)(struct RProc*)(pr)
#define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
#define MRB_METHOD_PROC(m) ((struct RProc*)(m))
#define MRB_METHOD_UNDEF_P(m) ((m)==0)
#else
#define MRB_METHOD_FUNC_P(m) ((m).func_p)
#define MRB_METHOD_FUNC(m) ((m).func)
#define MRB_METHOD_FROM_FUNC(m,fn) do{(m).func_p=TRUE;(m).func=(fn);}while(0)
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).func_p=FALSE;(m).proc=(pr);}while(0)
#define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
#define MRB_METHOD_PROC(m) ((m).proc)
#define MRB_METHOD_UNDEF_P(m) ((m).proc==NULL)
#endif /* MRB_METHOD_TABLE_INLINE */
#define MRB_METHOD_CFUNC_P(m) (MRB_METHOD_FUNC_P(m)?TRUE:(MRB_METHOD_PROC(m)?(MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m))):FALSE))
#define MRB_METHOD_CFUNC(m) (MRB_METHOD_FUNC_P(m)?MRB_METHOD_FUNC(m):((MRB_METHOD_PROC(m)&&MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m)))?MRB_PROC_CFUNC(MRB_METHOD_PROC(m)):NULL))
#include <mruby/khash.h>
KHASH_DECLARE(mt, mrb_sym, mrb_method_t, TRUE)
MRB_END_DECL
+4 -3
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_RANGE_H
#define MRUBY_RANGE_H
#include "mruby/common.h"
#include "common.h"
/**
* Range class
@@ -25,7 +25,8 @@ struct RRange {
mrb_bool excl : 1;
};
#define mrb_range_ptr(v) ((struct RRange*)(mrb_ptr(v)))
MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value v);
#define mrb_range_raw_ptr(v) ((struct RRange*)mrb_ptr(v))
#define mrb_range_value(p) mrb_obj_value((void*)(p))
/*
@@ -40,7 +41,7 @@ struct RRange {
*/
MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end, mrb_bool exclude);
MRB_API mrb_bool mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len);
MRB_API mrb_int mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len, mrb_bool trunc);
mrb_value mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, const mrb_value *argv, mrb_value (*func)(mrb_state*, mrb_value, mrb_int));
MRB_END_DECL
+2 -6
View File
@@ -7,14 +7,10 @@
#ifndef MRUBY_RE_H
#define MRUBY_RE_H
#ifdef __cplusplus
extern "C" {
#endif
MRB_BEGIN_DECL
#define REGEXP_CLASS "Regexp"
#ifdef __cplusplus
}
#endif
MRB_END_DECL
#endif /* RE_H */
+256 -17
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_STRING_H
#define MRUBY_STRING_H
#include "mruby/common.h"
#include "common.h"
/**
* String class
@@ -26,6 +26,7 @@ struct RString {
union {
mrb_int capa;
struct mrb_shared_string *shared;
struct RString *fshared;
} aux;
char *ptr;
} heap;
@@ -44,7 +45,8 @@ struct RString {
#define RSTR_SET_LEN(s, n) do {\
if (RSTR_EMBED_P(s)) {\
RSTR_SET_EMBED_LEN((s),(n));\
} else {\
}\
else {\
s->as.heap.len = (mrb_int)(n);\
}\
} while (0)
@@ -58,13 +60,16 @@ struct RString {
#define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED)
#define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED)
#define RSTR_FSHARED_P(s) ((s)->flags & MRB_STR_FSHARED)
#define RSTR_SET_FSHARED_FLAG(s) ((s)->flags |= MRB_STR_FSHARED)
#define RSTR_UNSET_FSHARED_FLAG(s) ((s)->flags &= ~MRB_STR_FSHARED)
#define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE)
#define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE)
#define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE)
#define RSTR_FROZEN_P(s) ((s)->flags & MRB_STR_FROZEN)
#define RSTR_SET_FROZEN_FLAG(s) ((s)->flags |= MRB_STR_FROZEN)
#define RSTR_UNSET_FROZEN_FLAG(s) ((s)->flags &= ~MRB_STR_FROZEN)
#define RSTR_POOL_P(s) ((s)->flags & MRB_STR_POOL)
#define RSTR_SET_POOL_FLAG(s) ((s)->flags |= MRB_STR_POOL)
/*
* Returns a pointer from a Ruby string
@@ -72,66 +77,274 @@ struct RString {
#define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s)))
#define RSTRING(s) mrb_str_ptr(s)
#define RSTRING_PTR(s) RSTR_PTR(RSTRING(s))
#define RSTRING_EMBED_LEN(s) RSTR_ENBED_LEN(RSTRING(s))
#define RSTRING_EMBED_LEN(s) RSTR_EMBED_LEN(RSTRING(s))
#define RSTRING_LEN(s) RSTR_LEN(RSTRING(s))
#define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s))
#define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s))
mrb_int mrb_str_strlen(mrb_state*, struct RString*);
MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*);
#define MRB_STR_SHARED 1
#define MRB_STR_NOFREE 2
#define MRB_STR_FROZEN 4
#define MRB_STR_EMBED 8
#define MRB_STR_EMBED_LEN_MASK 0x1f0
#define MRB_STR_EMBED_LEN_SHIFT 4
#define MRB_STR_FSHARED 2
#define MRB_STR_NOFREE 4
#define MRB_STR_POOL 8
#define MRB_STR_NO_UTF 16
#define MRB_STR_EMBED 32
#define MRB_STR_EMBED_LEN_MASK 0x7c0
#define MRB_STR_EMBED_LEN_SHIFT 6
void mrb_gc_free_str(mrb_state*, struct RString*);
MRB_API void mrb_str_modify(mrb_state*, struct RString*);
/*
* Finds the index of a substring in a string
*/
MRB_API mrb_int mrb_str_index(mrb_state*, mrb_value, const char*, mrb_int, mrb_int);
#define mrb_str_index_lit(mrb, str, lit, off) mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off);
/*
* Appends self to other. Returns self as a concatnated string.
*
*
* Example:
*
* !!!c
* int
* main(int argc,
* char **argv)
* {
* // Variable declarations.
* mrb_value str1;
* mrb_value str2;
*
* mrb_state *mrb = mrb_open();
* if (!mrb)
* {
* // handle error
* }
*
* // Creates new Ruby strings.
* str1 = mrb_str_new_lit(mrb, "abc");
* str2 = mrb_str_new_lit(mrb, "def");
*
* // Concatnates str2 to str1.
* mrb_str_concat(mrb, str1, str2);
*
* // Prints new Concatnated Ruby string.
* mrb_p(mrb, str1);
*
* mrb_close(mrb);
* return 0;
* }
*
*
* Result:
*
* => "abcdef"
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] self String to concatenate.
* @param [mrb_value] other String to append to self.
* @return [mrb_value] Returns a new String appending other to self.
*/
MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
/*
* Adds two strings together.
*
*
* Example:
*
* !!!c
* int
* main(int argc,
* char **argv)
* {
* // Variable declarations.
* mrb_value a;
* mrb_value b;
* mrb_value c;
*
* mrb_state *mrb = mrb_open();
* if (!mrb)
* {
* // handle error
* }
*
* // Creates two Ruby strings from the passed in C strings.
* a = mrb_str_new_lit(mrb, "abc");
* b = mrb_str_new_lit(mrb, "def");
*
* // Prints both C strings.
* mrb_p(mrb, a);
* mrb_p(mrb, b);
*
* // Concatnates both Ruby strings.
* c = mrb_str_plus(mrb, a, b);
*
* // Prints new Concatnated Ruby string.
* mrb_p(mrb, c);
*
* mrb_close(mrb);
* return 0;
* }
*
*
* Result:
*
* => "abc" # First string
* => "def" # Second string
* => "abcdef" # First & Second concatnated.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] a First string to concatenate.
* @param [mrb_value] b Second string to concatenate.
* @return [mrb_value] Returns a new String containing a concatenated to b.
*/
MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value);
/*
* Converts pointer into a Ruby string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [void*] p The pointer to convert to Ruby string.
* @return [mrb_value] Returns a new Ruby String.
*/
MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*);
/*
* Returns an object as a Ruby string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] obj An object to return as a Ruby string.
* @return [mrb_value] An object as a Ruby string.
*/
MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj);
/*
* Resizes the string's length.
* Resizes the string's length. Returns the amount of characters
* in the specified by len.
*
* Example:
*
* !!!c
* int
* main(int argc,
* char **argv)
* {
* // Variable declaration.
* mrb_value str;
*
* mrb_state *mrb = mrb_open();
* if (!mrb)
* {
* // handle error
* }
* // Creates a new string.
* str = mrb_str_new_lit(mrb, "Hello, world!");
* // Returns 5 characters of
* mrb_str_resize(mrb, str, 5);
* mrb_p(mrb, str);
*
* mrb_close(mrb);
* return 0;
* }
*
* Result:
*
* => "Hello"
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str The Ruby string to resize.
* @param [mrb_value] len The length.
* @return [mrb_value] An object as a Ruby string.
*/
MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len);
/*
* Returns a sub string.
*
* Example:
*
* !!!c
* int
* main(int argc,
* char const **argv)
* {
* // Variable declarations.
* mrb_value str1;
* mrb_value str2;
*
* mrb_state *mrb = mrb_open();
* if (!mrb)
* {
* // handle error
* }
* // Creates new string.
* str1 = mrb_str_new_lit(mrb, "Hello, world!");
* // Returns a sub-string within the range of 0..2
* str2 = mrb_str_substr(mrb, str1, 0, 2);
*
* // Prints sub-string.
* mrb_p(mrb, str2);
*
* mrb_close(mrb);
* return 0;
* }
*
* Result:
*
* => "He"
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @param [mrb_int] beg The beginning point of the sub-string.
* @param [mrb_int] len The end point of the sub-string.
* @return [mrb_value] An object as a Ruby sub-string.
*/
MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len);
/*
* Returns a Ruby string type.
*
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @return [mrb_value] A Ruby string.
*/
MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str);
MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str);
MRB_API mrb_value mrb_str_new_capa(mrb_state *mrb, size_t capa);
MRB_API mrb_value mrb_str_buf_new(mrb_state *mrb, size_t capa);
MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr);
MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr);
MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value str);
/*
* Returns the length of the Ruby string.
*
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @return [mrb_int] The length of the passed in Ruby string.
*/
MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str);
/*
* Duplicates a string object.
*
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @return [mrb_value] Duplicated Ruby string.
*/
MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str);
/*
* Returns a symbol from a passed in string.
* Returns a symbol from a passed in Ruby string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] self Ruby string.
* @return [mrb_value] A symbol.
*/
MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
@@ -145,12 +358,22 @@ MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);
/*
* Returns true if the strings match and false if the strings don't match.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str1 Ruby string to compare.
* @param [mrb_value] str2 Ruby string to compare.
* @return [mrb_value] boolean value.
*/
MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2);
/*
* Returns a concated string comprised of a Ruby string and a C string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @param [const char *] ptr A C string.
* @param [size_t] len length of C string.
* @return [mrb_value] A Ruby string.
* @see mrb_str_cat_cstr
*/
MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len);
@@ -158,6 +381,10 @@ MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, si
/*
* Returns a concated string comprised of a Ruby string and a C string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @param [const char *] ptr A C string.
* @return [mrb_value] A Ruby string.
* @see mrb_str_cat
*/
MRB_API mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr);
@@ -175,12 +402,24 @@ MRB_API mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2);
MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
/*
* Returns a C string from a Ruby string.
* Returns a newly allocated C string from a Ruby string.
* This is an utility function to pass a Ruby string to C library functions.
*
* - Returned string does not contain any NUL characters (but terminator).
* - It raises an ArgumentError exception if Ruby string contains
* NUL characters.
* - Retured string will be freed automatically on next GC.
* - Caller can modify returned string without affecting Ruby string
* (e.g. it can be used for mkstemp(3)).
*
* @param [mrb_state *] mrb The current mruby state.
* @param [mrb_value] str Ruby string. Must be an instance of String.
* @return [char *] A newly allocated C string.
*/
MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_pool(mrb_state *mrb, mrb_value str);
mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str);
uint32_t mrb_str_hash(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str);
/*
+18 -4
View File
@@ -7,7 +7,13 @@
#ifndef MRB_THROW_H
#define MRB_THROW_H
#ifdef MRB_ENABLE_CXX_EXCEPTION
#if defined(MRB_ENABLE_CXX_ABI)
# if !defined(__cplusplus)
# error Trying to use C++ exception handling in C code
# endif
#endif
#if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
#define MRB_TRY(buf) do { try {
#define MRB_CATCH(buf) } catch(mrb_jmpbuf_impl e) { if (e != (buf)->impl) { throw e; }
@@ -20,11 +26,19 @@ typedef mrb_int mrb_jmpbuf_impl;
#include <setjmp.h>
#define MRB_TRY(buf) do { if (setjmp((buf)->impl) == 0) {
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define MRB_SETJMP _setjmp
#define MRB_LONGJMP _longjmp
#else
#define MRB_SETJMP setjmp
#define MRB_LONGJMP longjmp
#endif
#define MRB_TRY(buf) do { if (MRB_SETJMP((buf)->impl) == 0) {
#define MRB_CATCH(buf) } else {
#define MRB_END_EXC(buf) } } while(0)
#define MRB_THROW(buf) longjmp((buf)->impl, 1);
#define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1);
#define mrb_jmpbuf_impl jmp_buf
#endif
@@ -32,7 +46,7 @@ typedef mrb_int mrb_jmpbuf_impl;
struct mrb_jmpbuf {
mrb_jmpbuf_impl impl;
#ifdef MRB_ENABLE_CXX_EXCEPTION
#if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
static mrb_int jmpbuf_id;
mrb_jmpbuf() : impl(jmpbuf_id++) {}
#endif
+48 -7
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_VALUE_H
#define MRUBY_VALUE_H
#include "mruby/common.h"
#include "common.h"
/**
* MRuby Value definition functions and macros.
@@ -22,29 +22,54 @@ struct mrb_state;
# error "You can't define MRB_INT16 and MRB_INT64 at the same time."
#endif
#if defined _MSC_VER && _MSC_VER < 1800
# define PRIo64 "llo"
# define PRId64 "lld"
# define PRIx64 "llx"
# define PRIo16 "ho"
# define PRId16 "hd"
# define PRIx16 "hx"
# define PRIo32 "o"
# define PRId32 "d"
# define PRIx32 "x"
#else
# include <inttypes.h>
#endif
#if defined(MRB_INT64)
typedef int64_t mrb_int;
# define MRB_INT_BIT 64
# define MRB_INT_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
# define MRB_PRIo PRIo64
# define MRB_PRId PRId64
# define MRB_PRIx PRIx64
#elif defined(MRB_INT16)
typedef int16_t mrb_int;
# define MRB_INT_BIT 16
# define MRB_INT_MIN (INT16_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MAX (INT16_MAX>>MRB_FIXNUM_SHIFT)
# define MRB_PRIo PRIo16
# define MRB_PRId PRId16
# define MRB_PRIx PRIx16
#else
typedef int32_t mrb_int;
# define MRB_INT_BIT 32
# define MRB_INT_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
# define MRB_PRIo PRIo32
# define MRB_PRId PRId32
# define MRB_PRIx PRIx32
#endif
#ifndef MRB_WITHOUT_FLOAT
MRB_API double mrb_float_read(const char*, char**);
#ifdef MRB_USE_FLOAT
typedef float mrb_float;
# define str_to_mrb_float(buf) strtof(buf, NULL)
#else
typedef double mrb_float;
# define str_to_mrb_float(buf) strtod(buf, NULL)
#endif
#endif
#if defined _MSC_VER && _MSC_VER < 1900
@@ -56,13 +81,12 @@ MRB_API int mrb_msvc_vsnprintf(char *s, size_t n, const char *format, va_list ar
MRB_API int mrb_msvc_snprintf(char *s, size_t n, const char *format, ...);
# define vsnprintf(s, n, format, arg) mrb_msvc_vsnprintf(s, n, format, arg)
# define snprintf(s, n, format, ...) mrb_msvc_snprintf(s, n, format, __VA_ARGS__)
# if _MSC_VER < 1800
# if _MSC_VER < 1800 && !defined MRB_WITHOUT_FLOAT
# include <float.h>
# define isfinite(n) _finite(n)
# define isnan _isnan
# define isinf(n) (!_finite(n) && !_isnan(n))
# define signbit(n) (_copysign(1.0, (n)) < 0.0)
# define strtof (float)strtod
static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000;
# define INFINITY (*(float *)&IEEE754_INFINITY_BITS_SINGLE)
# define NAN ((float)(INFINITY - INFINITY))
@@ -93,10 +117,12 @@ enum mrb_vtype {
MRB_TT_ENV, /* 20 */
MRB_TT_DATA, /* 21 */
MRB_TT_FIBER, /* 22 */
MRB_TT_MAXDEFINE /* 23 */
MRB_TT_ISTRUCT, /* 23 */
MRB_TT_BREAK, /* 24 */
MRB_TT_MAXDEFINE /* 25 */
};
#include "mruby/object.h"
#include <mruby/object.h>
#ifdef MRB_DOCUMENTATION_BLOCK
@@ -134,7 +160,9 @@ typedef void mrb_value;
#ifndef mrb_bool
#define mrb_bool(o) (mrb_type(o) != MRB_TT_FALSE)
#endif
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT)
#endif
#define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL)
#define mrb_array_p(o) (mrb_type(o) == MRB_TT_ARRAY)
#define mrb_string_p(o) (mrb_type(o) == MRB_TT_STRING)
@@ -147,6 +175,7 @@ MRB_API mrb_bool mrb_regexp_p(struct mrb_state*, mrb_value);
/*
* Returns a float in Ruby.
*/
#ifndef MRB_WITHOUT_FLOAT
MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
{
mrb_value v;
@@ -154,6 +183,7 @@ MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
SET_FLOAT_VALUE(mrb, v, f);
return v;
}
#endif
static inline mrb_value
mrb_cptr_value(struct mrb_state *mrb, void *p)
@@ -187,6 +217,8 @@ mrb_obj_value(void *p)
{
mrb_value v;
SET_OBJ_VALUE(v, (struct RBasic*)p);
mrb_assert(p == mrb_ptr(v));
mrb_assert(((struct RBasic*)p)->tt == mrb_type(v));
return v;
}
@@ -241,6 +273,14 @@ mrb_undef_value(void)
}
#ifdef MRB_USE_ETEXT_EDATA
#if (defined(__APPLE__) && defined(__MACH__))
#include <mach-o/getsect.h>
static inline mrb_bool
mrb_ro_data_p(const char *p)
{
return (const char*)get_etext() < p && p < (const char*)get_edata();
}
#else
extern char _etext[];
#ifdef MRB_NO_INIT_ARRAY_START
extern char _edata[];
@@ -259,6 +299,7 @@ mrb_ro_data_p(const char *p)
return _etext < p && p < (char*)&__init_array_start;
}
#endif
#endif
#else
# define mrb_ro_data_p(p) FALSE
#endif
+59 -3
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_VARIABLE_H
#define MRUBY_VARIABLE_H
#include "mruby/common.h"
#include "common.h"
/**
* Functions to access mruby variables.
@@ -47,16 +47,73 @@ MRB_API void mrb_iv_check(mrb_state *mrb, mrb_sym sym);
MRB_API mrb_value mrb_obj_iv_get(mrb_state *mrb, struct RObject *obj, mrb_sym sym);
MRB_API void mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v);
MRB_API mrb_bool mrb_obj_iv_defined(mrb_state *mrb, struct RObject *obj, mrb_sym sym);
MRB_API void mrb_obj_iv_ifnone(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v);
MRB_API mrb_value mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym);
MRB_API void mrb_iv_set(mrb_state *mrb, mrb_value obj, mrb_sym sym, mrb_value v);
MRB_API mrb_bool mrb_iv_defined(mrb_state*, mrb_value, mrb_sym);
MRB_API mrb_value mrb_iv_remove(mrb_state *mrb, mrb_value obj, mrb_sym sym);
MRB_API void mrb_iv_copy(mrb_state *mrb, mrb_value dst, mrb_value src);
MRB_API mrb_bool mrb_const_defined_at(mrb_state *mrb, mrb_value mod, mrb_sym id);
/**
* Get a global variable. Will return nil if the var does not exist
*
* Example:
*
* !!!ruby
* # Ruby style
* var = $value
*
* !!!c
* // C style
* mrb_sym sym = mrb_intern_lit(mrb, "$value");
* mrb_value var = mrb_gv_get(mrb, sym);
*
* @param mrb The mruby state reference
* @param sym The name of the global variable
* @return The value of that global variable. May be nil
*/
MRB_API mrb_value mrb_gv_get(mrb_state *mrb, mrb_sym sym);
/**
* Set a global variable
*
* Example:
*
* !!!ruby
* # Ruby style
* $value = "foo"
*
* !!!c
* // C style
* mrb_sym sym = mrb_intern_lit(mrb, "$value");
* mrb_gv_set(mrb, sym, mrb_str_new_lit("foo"));
*
* @param mrb The mruby state reference
* @param sym The name of the global variable
* @param val The value of the global variable
*/
MRB_API void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value val);
/**
* Remove a global variable.
*
* Example:
*
* !!!ruby
* # Ruby style
* $value = nil
*
* !!!c
* // C style
* mrb_sym sym = mrb_intern_lit(mrb, "$value");
* mrb_gv_remove(mrb, sym);
*
* @param mrb The mruby state reference
* @param sym The name of the global variable
* @param val The value of the global variable
*/
MRB_API void mrb_gv_remove(mrb_state *mrb, mrb_sym sym);
MRB_API mrb_value mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym);
MRB_API void mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v);
MRB_API void mrb_cv_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v);
@@ -68,7 +125,6 @@ mrb_value mrb_obj_instance_variables(mrb_state*, mrb_value);
mrb_value mrb_mod_class_variables(mrb_state*, mrb_value);
mrb_value mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym);
mrb_bool mrb_mod_cv_defined(mrb_state *mrb, struct RClass * c, mrb_sym sym);
mrb_sym mrb_class_sym(mrb_state *mrb, struct RClass *c, struct RClass *outer);
/* GC functions */
void mrb_gc_mark_gv(mrb_state*);
+5 -5
View File
@@ -7,7 +7,7 @@
#ifndef MRUBY_VERSION_H
#define MRUBY_VERSION_H
#include "mruby/common.h"
#include "common.h"
/**
* mruby version definition macros
@@ -42,7 +42,7 @@ MRB_BEGIN_DECL
/*
* Minor release version number.
*/
#define MRUBY_RELEASE_MINOR 2
#define MRUBY_RELEASE_MINOR 4
/*
* Tiny release version number.
@@ -62,17 +62,17 @@ MRB_BEGIN_DECL
/*
* Release year.
*/
#define MRUBY_RELEASE_YEAR 2015
#define MRUBY_RELEASE_YEAR 2018
/*
* Release month.
*/
#define MRUBY_RELEASE_MONTH 11
#define MRUBY_RELEASE_MONTH 1
/*
* Release day.
*/
#define MRUBY_RELEASE_DAY 17
#define MRUBY_RELEASE_DAY 16
/*
* Release date as a string.
+39 -8
View File
@@ -1,5 +1,5 @@
load "#{MRUBY_ROOT}/tasks/mruby_build_gem.rake"
load "#{MRUBY_ROOT}/tasks/mruby_build_commands.rake"
require "mruby/build/load_gems"
require "mruby/build/command"
module MRuby
class << self
@@ -83,8 +83,9 @@ module MRuby
@bins = []
@gems, @libmruby = MRuby::Gem::List.new, []
@build_mrbtest_lib_only = false
@cxx_abi_enabled = false
@cxx_exception_enabled = false
@cxx_exception_disabled = false
@cxx_abi_enabled = false
@enable_bintest = false
@enable_test = false
@toolchains = []
@@ -110,16 +111,44 @@ module MRuby
end
def disable_cxx_exception
if @cxx_exception_enabled or @cxx_abi_enabled
raise "cxx_exception already enabled"
end
@cxx_exception_disabled = true
end
def enable_cxx_exception
return if @cxx_exception_enabled
return if @cxx_abi_enabled
if @cxx_exception_disabled
raise "cxx_exception disabled"
end
@cxx_exception_enabled = true
compilers.each { |c|
c.defines += %w(MRB_ENABLE_CXX_EXCEPTION)
c.flags << c.cxx_exception_flag
}
linker.command = cxx.command if toolchains.find { |v| v == 'gcc' }
end
def cxx_exception_enabled?
@cxx_exception_enabled
end
def cxx_abi_enabled?
@cxx_abi_enabled
end
def enable_cxx_abi
return if @cxx_exception_disabled or @cxx_abi_enabled
compilers.each { |c| c.defines += %w(MRB_ENABLE_CXX_EXCEPTION) }
return if @cxx_abi_enabled
if @cxx_exception_enabled
raise "cxx_exception already enabled"
end
compilers.each { |c|
c.defines += %w(MRB_ENABLE_CXX_EXCEPTION MRB_ENABLE_CXX_ABI)
c.flags << c.cxx_compile_flag
}
compilers.each { |c| c.flags << c.cxx_compile_flag }
linker.command = cxx.command if toolchains.find { |v| v == 'gcc' }
@cxx_abi_enabled = true
end
@@ -135,11 +164,13 @@ module MRuby
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
#ifndef MRB_ENABLE_CXX_ABI
extern "C" {
#endif
#include "#{src}"
#ifndef MRB_ENABLE_CXX_ABI
}
#{src == "#{MRUBY_ROOT}/src/error.c"? 'mrb_int mrb_jmpbuf::jmpbuf_id = 0;' : ''}
#endif
EOS
end
@@ -210,7 +241,7 @@ EOS
else
compiler.defines += %w(DISABLE_GEMS)
end
compiler.define_rules build_dir, File.expand_path(File.join(File.dirname(__FILE__), '..'))
compiler.define_rules build_dir, File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
end
end
@@ -41,6 +41,7 @@ module MRuby
class Command::Compiler < Command
attr_accessor :flags, :include_paths, :defines, :source_exts
attr_accessor :compile_options, :option_define, :option_include_path, :out_ext
attr_accessor :cxx_compile_flag, :cxx_exception_flag
def initialize(build, source_exts=[])
super(build)
@@ -38,7 +38,7 @@ module MRuby
cxx_srcs = ['src', 'test', 'tools'].map do |subdir|
Dir.glob("#{Gem.current.dir}/#{subdir}/*.{cpp,cxx,cc}")
end.flatten
enable_cxx_abi unless cxx_srcs.empty?
enable_cxx_exception unless cxx_srcs.empty?
Gem.current
end
+37 -11
View File
@@ -1,6 +1,7 @@
require 'pathname'
require 'forwardable'
require 'tsort'
require 'shellwords'
module MRuby
module Gem
@@ -17,6 +18,7 @@ module MRuby
attr_accessor :name, :dir, :build
alias mruby build
attr_accessor :build_config_initializer
attr_accessor :mrblib_dir, :objs_dir
attr_accessor :version
attr_accessor :description, :summary
@@ -44,6 +46,8 @@ module MRuby
@name = name
@initializer = block
@version = "0.0.0"
@mrblib_dir = "mrblib"
@objs_dir = "src"
MRuby::Gem.current = self
end
@@ -54,14 +58,11 @@ module MRuby
end
@linker = LinkerConfig.new([], [], [], [], [])
@rbfiles = Dir.glob("#{dir}/mrblib/**/*.rb").sort
@objs = Dir.glob("#{dir}/src/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f|
@rbfiles = Dir.glob("#{@dir}/#{@mrblib_dir}/**/*.rb").sort
@objs = Dir.glob("#{@dir}/#{@objs_dir}/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f|
objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X"))
end
@generate_functions = !(@rbfiles.empty? && @objs.empty?)
@objs << objfile("#{build_dir}/gem_init") if @generate_functions
@test_rbfiles = Dir.glob("#{dir}/test/**/*.rb")
@test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f|
objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X"))
@@ -79,6 +80,9 @@ module MRuby
instance_eval(&@initializer)
@generate_functions = !(@rbfiles.empty? && @objs.empty?)
@objs << objfile("#{build_dir}/gem_init") if @generate_functions
if !name || !licenses || !authors
fail "#{name || dir} required to set name, license(s) and author(s)"
end
@@ -86,7 +90,9 @@ module MRuby
build.libmruby << @objs
instance_eval(&@build_config_initializer) if @build_config_initializer
end
def setup_compilers
compilers.each do |compiler|
compiler.define_rules build_dir, "#{dir}"
compiler.defines << %Q[MRBGEM_#{funcname.upcase}_VERSION=#{version}]
@@ -123,6 +129,21 @@ module MRuby
"#{build_dir}/gem_test.c"
end
def search_package(name, version_query=nil)
package_query = name
package_query += " #{version_query}" if version_query
_pp "PKG-CONFIG", package_query
escaped_package_query = Shellwords.escape(package_query)
if system("pkg-config --exists #{escaped_package_query}")
cc.flags += [`pkg-config --cflags #{escaped_package_query}`.strip]
cxx.flags += [`pkg-config --cflags #{escaped_package_query}`.strip]
linker.flags_before_libraries += [`pkg-config --libs #{escaped_package_query}`.strip]
true
else
false
end
end
def funcname
@funcname ||= @name.gsub('-', '_')
end
@@ -181,18 +202,18 @@ module MRuby
def print_gem_init_header(f)
print_gem_comment(f)
f.puts %Q[#include <stdlib.h>] unless rbfiles.empty?
f.puts %Q[#include "mruby.h"]
f.puts %Q[#include "mruby/irep.h"] unless rbfiles.empty?
f.puts %Q[#include <mruby.h>]
f.puts %Q[#include <mruby/irep.h>] unless rbfiles.empty?
end
def print_gem_test_header(f)
print_gem_comment(f)
f.puts %Q[#include <stdio.h>]
f.puts %Q[#include <stdlib.h>]
f.puts %Q[#include "mruby.h"]
f.puts %Q[#include "mruby/irep.h"]
f.puts %Q[#include "mruby/variable.h"]
f.puts %Q[#include "mruby/hash.h"] unless test_args.empty?
f.puts %Q[#include <mruby.h>]
f.puts %Q[#include <mruby/irep.h>]
f.puts %Q[#include <mruby/variable.h>]
f.puts %Q[#include <mruby/hash.h>] unless test_args.empty?
end
def test_dependencies
@@ -400,6 +421,8 @@ module MRuby
@ary = tsort_dependencies gem_table.keys, gem_table, true
each(&:setup_compilers)
each do |g|
import_include_paths(g)
end
@@ -413,9 +436,12 @@ module MRuby
# as circular dependency has already detected in the caller.
import_include_paths(dep_g)
dep_g.export_include_paths.uniq!
g.compilers.each do |compiler|
compiler.include_paths += dep_g.export_include_paths
g.export_include_paths += dep_g.export_include_paths
compiler.include_paths.uniq!
g.export_include_paths.uniq!
end
end
end
+2 -2
View File
@@ -113,8 +113,7 @@ module MiniRake
# Timestamp for this task. Basic tasks return the current time for
# their time stamp. Other tasks can be more sophisticated.
def timestamp
prerequisites = @prerequisites.collect{ |n| n.is_a?(Proc) ? n.call(name) : n }.flatten
prerequisites.collect { |n| Task[n].timestamp }.max || Time.now
Time.now
end
# Class Methods ----------------------------------------------------
@@ -237,6 +236,7 @@ module MiniRake
# Time stamp for file task.
def timestamp
return Time.at(0) unless File.exist?(name)
stat = File::stat(name.to_s)
stat.directory? ? Time.at(0) : stat.mtime
end
+7 -1
View File
@@ -14,6 +14,9 @@ MRuby::GemBox.new do |conf|
# Use standard Struct class
conf.gem :core => "mruby-struct"
# Use Comparable module extension
conf.gem :core => "mruby-compar-ext"
# Use Enumerable module extension
conf.gem :core => "mruby-enum-ext"
@@ -53,7 +56,7 @@ MRuby::GemBox.new do |conf|
# Use Enumerator class (require mruby-fiber)
conf.gem :core => "mruby-enumerator"
# Use Enumerable::Lazy class (require mruby-enumerator)
# Use Enumerator::Lazy class (require mruby-enumerator)
conf.gem :core => "mruby-enum-lazy"
# Use toplevel object (main) methods extension
@@ -71,6 +74,9 @@ MRuby::GemBox.new do |conf|
# Use Kernel module extension
conf.gem :core => "mruby-kernel-ext"
# Use class/module extension
conf.gem :core => "mruby-class-ext"
# Use mruby-compiler to build other mrbgems
conf.gem :core => "mruby-compiler"
end
+1
View File
@@ -2,4 +2,5 @@ MRuby::Gem::Specification.new('mruby-array-ext') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Array class extension'
spec.add_test_dependency 'mruby-enumerator', core: 'mruby-enumerator'
end
+271 -48
View File
@@ -1,4 +1,29 @@
class Array
##
# call-seq:
# Array.try_convert(obj) -> array or nil
#
# Tries to convert +obj+ into an array, using +to_ary+ method.
# converted array or +nil+ if +obj+ cannot be converted for any reason.
# This method can be used to check if an argument is an array.
#
# Array.try_convert([1]) #=> [1]
# Array.try_convert("1") #=> nil
#
# if tmp = Array.try_convert(arg)
# # the argument is an array
# elsif tmp = String.try_convert(arg)
# # the argument is a string
# end
#
def self.try_convert(obj)
if obj.respond_to?(:to_ary)
obj.to_ary
else
nil
end
end
##
# call-seq:
# ary.uniq! -> ary or nil
@@ -56,11 +81,7 @@ class Array
#
def uniq(&block)
ary = self.dup
if block
ary.uniq!(&block)
else
ary.uniq!
end
ary.uniq!(&block)
ary
end
@@ -80,8 +101,19 @@ class Array
hash = {}
array = []
elem.each { |x| hash[x] = true }
self.each { |x| array << x unless hash[x] }
idx = 0
len = elem.size
while idx < len
hash[elem[idx]] = true
idx += 1
end
idx = 0
len = size
while idx < len
v = self[idx]
array << v unless hash[v]
idx += 1
end
array
end
@@ -116,12 +148,21 @@ class Array
hash = {}
array = []
elem.each{|v| hash[v] = true }
self.each do |v|
idx = 0
len = elem.size
while idx < len
hash[elem[idx]] = true
idx += 1
end
idx = 0
len = size
while idx < len
v = self[idx]
if hash[v]
array << v
hash.delete v
end
idx += 1
end
array
end
@@ -144,15 +185,9 @@ class Array
# a.flatten(1) #=> [1, 2, 3, [4, 5]]
#
def flatten(depth=nil)
ar = []
self.each do |e|
if e.is_a?(Array) && (depth.nil? || depth > 0)
ar += e.flatten(depth.nil? ? nil : depth - 1)
else
ar << e
end
end
ar
res = dup
res.flatten! depth
res
end
##
@@ -175,13 +210,17 @@ class Array
def flatten!(depth=nil)
modified = false
ar = []
self.each do |e|
idx = 0
len = size
while idx < len
e = self[idx]
if e.is_a?(Array) && (depth.nil? || depth > 0)
ar += e.flatten(depth.nil? ? nil : depth - 1)
modified = true
else
ar << e
end
idx += 1
end
if modified
self.replace(ar)
@@ -227,7 +266,7 @@ class Array
# for efficiency
def reverse_each(&block)
return to_enum :reverse_each unless block_given?
return to_enum :reverse_each unless block
i = self.size - 1
while i>=0
@@ -250,8 +289,9 @@ class Array
# +default+ value.
#
# Alternatively, if a block is given it will only be executed when an
# invalid +index+ is referenced. Negative values of +index+ count from the
# end of the array.
# invalid +index+ is referenced.
#
# Negative values of +index+ count from the end of the array.
#
# a = [ 11, 22, 33, 44 ]
# a.fetch(1) #=> 22
@@ -448,7 +488,7 @@ class Array
# scores.delete_if {|score| score < 80 } #=> [97]
def delete_if(&block)
return to_enum :delete_if unless block_given?
return to_enum :delete_if unless block
idx = 0
while idx < self.size do
@@ -477,7 +517,7 @@ class Array
# If no block is given, an Enumerator is returned instead.
def reject!(&block)
return to_enum :reject! unless block_given?
return to_enum :reject! unless block
len = self.size
idx = 0
@@ -567,33 +607,60 @@ class Array
# undefined which value is actually picked up at each iteration.
def bsearch(&block)
return to_enum :bsearch unless block_given?
return to_enum :bsearch unless block
if idx = bsearch_index(&block)
self[idx]
else
nil
end
end
##
# call-seq:
# ary.bsearch_index {|x| block } -> int or nil
#
# By using binary search, finds an index of a value from this array which
# meets the given condition in O(log n) where n is the size of the array.
#
# It supports two modes, depending on the nature of the block and they are
# exactly the same as in the case of #bsearch method with the only difference
# being that this method returns the index of the element instead of the
# element itself. For more details consult the documentation for #bsearch.
def bsearch_index(&block)
return to_enum :bsearch_index unless block
low = 0
high = self.size
high = size
satisfied = false
while low < high
mid = low + ((high - low) / 2).truncate
val = self[mid]
v = block.call(val)
if v.is_a?(Integer)
return val if v == 0
smaller = v < 0
elsif v == true
mid = ((low+high)/2).truncate
res = block.call self[mid]
case res
when 0 # find-any mode: Found!
return mid
when Numeric # find-any mode: Continue...
in_lower_half = res < 0
when true # find-min mode
in_lower_half = true
satisfied = true
smaller = true
elsif v == false || v.nil?
smaller = false
when false, nil # find-min mode
in_lower_half = false
else
raise TypeError, 'invalid block result (must be numeric, true, false or nil)'
end
if smaller
if in_lower_half
high = mid
else
low = mid + 1
end
end
return nil if low == self.size
return nil unless satisfied
self[low]
satisfied ? low : nil
end
##
@@ -614,7 +681,7 @@ class Array
# scores.delete_if {|score| score < 80 } #=> [97]
def delete_if(&block)
return to_enum :delete_if unless block_given?
return to_enum :delete_if unless block
idx = 0
while idx < self.size do
@@ -643,7 +710,7 @@ class Array
# a.keep_if { |val| val > 3 } #=> [4, 5]
def keep_if(&block)
return to_enum :keep_if unless block_given?
return to_enum :keep_if unless block
idx = 0
len = self.size
@@ -672,13 +739,17 @@ class Array
# If no block is given, an Enumerator is returned instead.
def select!(&block)
return to_enum :select! unless block_given?
return to_enum :select! unless block
result = []
self.each do |x|
result << x if block.call(x)
idx = 0
len = size
while idx < len
elem = self[idx]
result << elem if block.call(elem)
idx += 1
end
return nil if self.size == result.size
return nil if len == result.size
self.replace(result)
end
@@ -700,8 +771,9 @@ class Array
if block
idx = 0
self.each do |*e|
return idx if block.call(*e)
len = size
while idx < len
return idx if block.call self[idx]
idx += 1
end
else
@@ -709,4 +781,155 @@ class Array
end
nil
end
##
# call-seq:
# ary.to_ary -> ary
#
# Returns +self+.
#
def to_ary
self
end
##
# call-seq:
# ary.dig(idx, ...) -> object
#
# Extracts the nested value specified by the sequence of <i>idx</i>
# objects by calling +dig+ at each step, returning +nil+ if any
# intermediate step is +nil+.
#
def dig(idx,*args)
n = self[idx]
if args.size > 0
n&.dig(*args)
else
n
end
end
##
# call-seq:
# ary.permutation { |p| block } -> ary
# ary.permutation -> Enumerator
# ary.permutation(n) { |p| block } -> ary
# ary.permutation(n) -> Enumerator
#
# When invoked with a block, yield all permutations of length +n+ of the
# elements of the array, then return the array itself.
#
# If +n+ is not specified, yield all permutations of all elements.
#
# The implementation makes no guarantees about the order in which the
# permutations are yielded.
#
# If no block is given, an Enumerator is returned instead.
#
# Examples:
#
# a = [1, 2, 3]
# a.permutation.to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
# a.permutation(1).to_a #=> [[1],[2],[3]]
# a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
# a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
# a.permutation(0).to_a #=> [[]] # one permutation of length 0
# a.permutation(4).to_a #=> [] # no permutations of length 4
def permutation(n=self.size, &block)
size = self.size
return to_enum(:permutation, n) unless block
return if n > size
if n == 0
yield []
else
i = 0
while i<size
result = [self[i]]
if n-1 > 0
ary = self[0...i] + self[i+1..-1]
ary.permutation(n-1) do |c|
yield result + c
end
else
yield result
end
i += 1
end
end
end
##
# call-seq:
# ary.combination(n) { |c| block } -> ary
# ary.combination(n) -> Enumerator
#
# When invoked with a block, yields all combinations of length +n+ of elements
# from the array and then returns the array itself.
#
# The implementation makes no guarantees about the order in which the
# combinations are yielded.
#
# If no block is given, an Enumerator is returned instead.
#
# Examples:
#
# a = [1, 2, 3, 4]
# a.combination(1).to_a #=> [[1],[2],[3],[4]]
# a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
# a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
# a.combination(4).to_a #=> [[1,2,3,4]]
# a.combination(0).to_a #=> [[]] # one combination of length 0
# a.combination(5).to_a #=> [] # no combinations of length 5
def combination(n, &block)
size = self.size
return to_enum(:combination, n) unless block
return if n > size
if n == 0
yield []
elsif n == 1
i = 0
while i<size
yield [self[i]]
i += 1
end
else
i = 0
while i<size
result = [self[i]]
self[i+1..-1].combination(n-1) do |c|
yield result + c
end
i += 1
end
end
end
##
# call-seq:
# ary.transpose -> new_ary
#
# Assumes that self is an array of arrays and transposes the rows and columns.
#
# If the length of the subarrays dont match, an IndexError is raised.
#
# Examples:
#
# a = [[1,2], [3,4], [5,6]]
# a.transpose #=> [[1, 3, 5], [2, 4, 6]]
def transpose
return [] if empty?
column_count = nil
self.each do |row|
raise TypeError unless row.is_a?(Array)
column_count ||= row.count
raise IndexError, 'element size differs' unless column_count == row.count
end
Array.new(column_count) do |column_index|
self.map { |row| row[column_index] }
end
end
end
+89 -10
View File
@@ -1,8 +1,8 @@
#include "mruby.h"
#include "mruby/value.h"
#include "mruby/array.h"
#include "mruby/range.h"
#include "mruby/hash.h"
#include <mruby.h>
#include <mruby/value.h>
#include <mruby/array.h>
#include <mruby/range.h>
#include <mruby/hash.h>
/*
* call-seq:
@@ -127,19 +127,20 @@ mrb_ary_to_h(mrb_state *mrb, mrb_value ary)
hash = mrb_hash_new_capa(mrb, 0);
for (i = 0; i < RARRAY_LEN(ary); ++i) {
v = mrb_check_array_type(mrb, RARRAY_PTR(ary)[i]);
mrb_value elt = RARRAY_PTR(ary)[i];
v = mrb_check_array_type(mrb, elt);
if (mrb_nil_p(v)) {
mrb_raisef(mrb, E_TYPE_ERROR, "wrong element type %S at %S (expected array)",
mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, RARRAY_PTR(ary)[i])),
mrb_fixnum_value(i)
mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, elt)),
mrb_fixnum_value(i)
);
}
if (RARRAY_LEN(v) != 2) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong array length at %S (expected 2, was %S)",
mrb_fixnum_value(i),
mrb_fixnum_value(RARRAY_LEN(v))
mrb_fixnum_value(i),
mrb_fixnum_value(RARRAY_LEN(v))
);
}
@@ -149,6 +150,83 @@ mrb_ary_to_h(mrb_state *mrb, mrb_value ary)
return hash;
}
/*
* call-seq:
* ary.slice!(index) -> obj or nil
* ary.slice!(start, length) -> new_ary or nil
* ary.slice!(range) -> new_ary or nil
*
* Deletes the element(s) given by an +index+ (optionally up to +length+
* elements) or by a +range+.
*
* Returns the deleted object (or objects), or +nil+ if the +index+ is out of
* range.
*
* a = [ "a", "b", "c" ]
* a.slice!(1) #=> "b"
* a #=> ["a", "c"]
* a.slice!(-1) #=> "c"
* a #=> ["a"]
* a.slice!(100) #=> nil
* a #=> ["a"]
*/
static mrb_value
mrb_ary_slice_bang(mrb_state *mrb, mrb_value self)
{
struct RArray *a = mrb_ary_ptr(self);
mrb_int i, j, k, len, alen = ARY_LEN(a);
mrb_value val;
mrb_value *ptr;
mrb_value ary;
mrb_ary_modify(mrb, a);
if (mrb_get_argc(mrb) == 1) {
mrb_value index;
mrb_get_args(mrb, "o|i", &index, &len);
switch (mrb_type(index)) {
case MRB_TT_RANGE:
if (mrb_range_beg_len(mrb, index, &i, &len, alen, TRUE) == 1) {
goto delete_pos_len;
}
else {
return mrb_nil_value();
}
case MRB_TT_FIXNUM:
val = mrb_funcall(mrb, self, "delete_at", 1, index);
return val;
default:
val = mrb_funcall(mrb, self, "delete_at", 1, index);
return val;
}
}
mrb_get_args(mrb, "ii", &i, &len);
delete_pos_len:
if (i < 0) i += alen;
if (i < 0 || alen < i) return mrb_nil_value();
if (len < 0) return mrb_nil_value();
if (alen == i) return mrb_ary_new(mrb);
if (len > alen - i) len = alen - i;
ary = mrb_ary_new_capa(mrb, len);
ptr = ARY_PTR(a);
for (j = i, k = 0; k < len; ++j, ++k) {
mrb_ary_push(mrb, ary, ptr[j]);
}
ptr += i;
for (j = i; j < alen - len; ++j) {
*ptr = *(ptr+len);
++ptr;
}
mrb_ary_resize(mrb, self, alen - len);
return ary;
}
void
mrb_mruby_array_ext_gem_init(mrb_state* mrb)
{
@@ -159,6 +237,7 @@ mrb_mruby_array_ext_gem_init(mrb_state* mrb)
mrb_define_method(mrb, a, "rassoc", mrb_ary_rassoc, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "values_at", mrb_ary_values_at, MRB_ARGS_ANY());
mrb_define_method(mrb, a, "to_h", mrb_ary_to_h, MRB_ARGS_REQ(0));
mrb_define_method(mrb, a, "slice!", mrb_ary_slice_bang, MRB_ARGS_ANY());
}
void
+132 -10
View File
@@ -1,6 +1,13 @@
##
# Array(Ext) Test
assert("Array.try_convert") do
assert_nil Array.try_convert(0)
assert_nil Array.try_convert(nil)
assert_equal [], Array.try_convert([])
assert_equal [1,2,3], Array.try_convert([1,2,3])
end
assert("Array#assoc") do
s1 = [ "colors", "red", "blue", "green" ]
s2 = [ "letters", "a", "b", "c" ]
@@ -221,18 +228,47 @@ end
assert("Array#bsearch") do
# Find minimum mode
a = [0, 4, 7, 10, 12]
assert_include [4, 7], a.bsearch {|x| x >= 4 }
assert_equal 7, a.bsearch {|x| x >= 6 }
assert_equal 0, a.bsearch {|x| x >= -1 }
assert_nil a.bsearch {|x| x >= 100 }
a = [0, 2, 4]
assert_equal 0, a.bsearch{ |x| x >= -1 }
assert_equal 0, a.bsearch{ |x| x >= 0 }
assert_equal 2, a.bsearch{ |x| x >= 1 }
assert_equal 2, a.bsearch{ |x| x >= 2 }
assert_equal 4, a.bsearch{ |x| x >= 3 }
assert_equal 4, a.bsearch{ |x| x >= 4 }
assert_nil a.bsearch{ |x| x >= 5 }
# Find any mode
a = [0, 4, 7, 10, 12]
assert_include [4, 7], a.bsearch {|x| 1 - (x / 4).truncate }
assert_nil a.bsearch {|x| 4 - (x / 2).truncate }
assert_equal(nil, a.bsearch {|x| 1 })
assert_equal(nil, a.bsearch {|x| -1 })
a = [0, 4, 8]
def between(lo, x, hi)
if x < lo
1
elsif x > hi
-1
else
0
end
end
assert_nil a.bsearch{ |x| between(-3, x, -1) }
assert_equal 0, a.bsearch{ |x| between(-1, x, 1) }
assert_nil a.bsearch{ |x| between( 1, x, 3) }
assert_equal 4, a.bsearch{ |x| between( 3, x, 5) }
assert_nil a.bsearch{ |x| between( 5, x, 7) }
assert_equal 8, a.bsearch{ |x| between( 7, x, 9) }
assert_nil a.bsearch{ |x| between( 9, x, 11) }
assert_equal 0, a.bsearch{ |x| between( 0, x, 3) }
assert_equal 4, a.bsearch{ |x| between( 0, x, 4) }
assert_equal 4, a.bsearch{ |x| between( 4, x, 8) }
assert_equal 8, a.bsearch{ |x| between( 5, x, 8) }
# Invalid block result
assert_raise TypeError, 'invalid block result (must be numeric, true, false or nil)' do
a.bsearch{ 'I like to watch the world burn' }
end
end
assert("Array#bsearch_index") do
# tested through Array#bsearch
end
assert("Array#delete_if") do
@@ -294,7 +330,93 @@ assert('Array#to_h') do
assert_raise(ArgumentError) { [[1]].to_h }
end
assert('Array#to_h (Modified)') do
class A
def to_ary
$a.clear
nil
end
end
$a = [A.new]
assert_raise(TypeError) { $a.to_h }
end
assert("Array#index (block)") do
assert_nil (1..10).to_a.index { |i| i % 5 == 0 and i % 7 == 0 }
assert_equal 34, (1..100).to_a.index { |i| i % 5 == 0 and i % 7 == 0 }
end
assert("Array#to_ary") do
assert_equal [], [].to_ary
assert_equal [1,2,3], [1,2,3].to_ary
end
assert("Array#dig") do
h = [[[1]], 0]
assert_equal(1, h.dig(0, 0, 0))
assert_nil(h.dig(2, 0))
assert_raise(TypeError) {h.dig(:a)}
end
assert("Array#slice!") do
a = [1, 2, 3]
b = a.slice!(0)
c = [1, 2, 3, 4, 5]
d = c.slice!(0, 2)
e = [1, 2, 3, 4, 5]
f = e.slice!(1..3)
g = [1, 2, 3]
h = g.slice!(-1)
i = [1, 2, 3]
j = i.slice!(0, -1)
assert_equal(a, [2, 3])
assert_equal(b, 1)
assert_equal(c, [3, 4, 5])
assert_equal(d, [1, 2])
assert_equal(e, [1, 5])
assert_equal(f, [2, 3, 4])
assert_equal(g, [1, 2])
assert_equal(h, 3)
assert_equal(i, [1, 2, 3])
assert_equal(j, nil)
end
assert("Array#permutation") do
a = [1, 2, 3]
assert_equal([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]],
a.permutation.to_a)
assert_equal([[1],[2],[3]],
a.permutation(1).to_a)
assert_equal([[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]],
a.permutation(2).to_a)
assert_equal([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]],
a.permutation(3).to_a)
assert_equal([[]], a.permutation(0).to_a)
assert_equal([], a.permutation(4).to_a)
end
assert("Array#combination") do
a = [1, 2, 3, 4]
assert_equal([[1],[2],[3],[4]],
a.combination(1).to_a)
assert_equal([[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]],
a.combination(2).to_a)
assert_equal([[1,2,3],[1,2,4],[1,3,4],[2,3,4]],
a.combination(3).to_a)
assert_equal([[1,2,3,4]],
a.combination(4).to_a)
assert_equal([[]], a.combination(0).to_a)
assert_equal([], a.combination(5).to_a)
end
assert('Array#transpose') do
assert_equal([].transpose, [])
assert_equal([[]].transpose, [])
assert_equal([[1]].transpose, [[1]])
assert_equal([[1,2,3]].transpose, [[1], [2], [3]])
assert_equal([[1], [2], [3]].transpose, [[1,2,3]])
assert_equal([[1,2], [3,4], [5,6]].transpose, [[1,3,5], [2,4,6]])
assert_raise(TypeError) { [1].transpose }
assert_raise(IndexError) { [[1], [2,3,4]].transpose }
end
+1 -1
View File
@@ -14,7 +14,7 @@ class BinTest_MrubyBinDebugger
# compile
`./bin/mrbc -g -o "#{bin.path}" "#{script.path}"`
# add mrdb quit
testcase << {:cmd=>"quit"}
+3 -3
View File
@@ -13,7 +13,7 @@ class BinTest_MrubyBinDebugger
# compile
`./bin/mrbc -g -o "#{bin.path}" "#{script.path}"`
# add mrdb quit
testcase << {:cmd=>"quit"}
@@ -341,8 +341,8 @@ assert('mruby-bin-debugger(print) Literal:Numeric') do
tc << {:cmd=>"p +0100", :exp=>'$3 = 64'}
tc << {:cmd=>"p 0x100", :exp=>'$4 = 256'}
tc << {:cmd=>"p 1_234", :exp=>'$5 = 1234'}
tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000.to_s}"}
tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000.to_s}"}
tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000}"}
tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000}"}
tc << {:cmd=>"p 3.14", :exp=>'$8 = 3.14'}
tc << {:cmd=>"p -12.3", :exp=>'$9 = -12.3'}
View File
+103 -114
View File
@@ -4,14 +4,14 @@
*/
#include <string.h>
#include "mruby.h"
#include "mruby/irep.h"
#include <mruby.h>
#include <mruby/irep.h>
#include "mrdb.h"
#include "mruby/debug.h"
#include "mruby/opcode.h"
#include "mruby/class.h"
#include "mruby/proc.h"
#include "mruby/variable.h"
#include <mruby/debug.h>
#include <mruby/opcode.h>
#include <mruby/class.h>
#include <mruby/proc.h>
#include <mruby/variable.h>
#include "mrdberror.h"
#include "apibreak.h"
@@ -20,20 +20,21 @@
#define MRB_DEBUG_BP_LINENO_OK (0x0002)
static uint16_t
check_lineno( mrb_irep_debug_info_file *info_file, uint16_t lineno )
check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno)
{
uint32_t count = info_file->line_entry_count;
uint16_t l_idx;
if( info_file->line_type == mrb_debug_line_ary ) {
if (info_file->line_type == mrb_debug_line_ary) {
for (l_idx = 0; l_idx < count; ++l_idx) {
if(lineno == info_file->lines.ary[l_idx]) {
if (lineno == info_file->lines.ary[l_idx]) {
return lineno;
}
}
} else {
}
else {
for (l_idx = 0; l_idx < count; ++l_idx) {
if(lineno == info_file->lines.flat_map[l_idx].line) {
if (lineno == info_file->lines.flat_map[l_idx].line) {
return lineno;
}
}
@@ -43,21 +44,21 @@ check_lineno( mrb_irep_debug_info_file *info_file, uint16_t lineno )
}
static int32_t
get_break_index( mrb_debug_context *dbg, int32_t bpno )
get_break_index(mrb_debug_context *dbg, uint32_t bpno)
{
uint32_t i;
int32_t index;
char hit = FALSE;
for(i = 0 ; i < dbg->bpnum; i++) {
if(dbg->bp[i].bpno == bpno) {
if (dbg->bp[i].bpno == bpno) {
hit = TRUE;
index = i;
break;
}
}
if(hit == FALSE) {
if (hit == FALSE) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
@@ -65,7 +66,7 @@ get_break_index( mrb_debug_context *dbg, int32_t bpno )
}
static void
free_breakpoint( mrb_state *mrb, mrb_debug_breakpoint *bp )
free_breakpoint(mrb_state *mrb, mrb_debug_breakpoint *bp)
{
switch(bp->type) {
case MRB_DEBUG_BPTYPE_LINE:
@@ -73,7 +74,7 @@ free_breakpoint( mrb_state *mrb, mrb_debug_breakpoint *bp )
break;
case MRB_DEBUG_BPTYPE_METHOD:
mrb_free(mrb, (void*)bp->point.methodpoint.method_name);
if(bp->point.methodpoint.class_name != NULL) {
if (bp->point.methodpoint.class_name != NULL) {
mrb_free(mrb, (void*)bp->point.methodpoint.class_name);
}
break;
@@ -83,7 +84,7 @@ free_breakpoint( mrb_state *mrb, mrb_debug_breakpoint *bp )
}
static uint16_t
check_file_lineno( struct mrb_irep *irep, const char *file, uint16_t lineno )
check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
{
mrb_irep_debug_info_file *info_file;
uint16_t result = 0;
@@ -93,17 +94,17 @@ check_file_lineno( struct mrb_irep *irep, const char *file, uint16_t lineno )
for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
info_file = irep->debug_info->files[f_idx];
if(!strcmp(info_file->filename, file)) {
if (!strcmp(info_file->filename, file)) {
result = MRB_DEBUG_BP_FILE_OK;
fix_lineno = check_lineno( info_file, lineno );
if(fix_lineno != 0) {
fix_lineno = check_lineno(info_file, lineno);
if (fix_lineno != 0) {
return result | MRB_DEBUG_BP_LINENO_OK;
}
}
for ( i=0; i < irep->rlen; ++i ) {
for (i=0; i < irep->rlen; ++i) {
result |= check_file_lineno(irep->reps[i], file, lineno);
if(result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {
if (result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {
return result;
}
}
@@ -111,23 +112,12 @@ check_file_lineno( struct mrb_irep *irep, const char *file, uint16_t lineno )
return result;
}
static const char*
get_class_name( mrb_state *mrb, struct RClass *class_obj )
{
struct RClass *outer;
mrb_sym class_sym;
outer = mrb_class_outer_module(mrb, class_obj);
class_sym = mrb_class_sym(mrb, class_obj, outer);
return mrb_sym2name(mrb, class_sym);
}
static int32_t
compare_break_method( mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc )
compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
{
const char* class_name;
const char* method_name;
struct RProc* m;
mrb_method_t m;
struct RClass* sc;
const char* sn;
mrb_sym ssym;
@@ -137,37 +127,37 @@ compare_break_method( mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *c
method_name = mrb_sym2name(mrb, method_sym);
method_p = &bp->point.methodpoint;
if(strcmp(method_p->method_name, method_name) == 0) {
class_name = get_class_name(mrb, class_obj);
if(class_name == NULL) {
if(method_p->class_name == NULL) {
if (strcmp(method_p->method_name, method_name) == 0) {
class_name = mrb_class_name(mrb, class_obj);
if (class_name == NULL) {
if (method_p->class_name == NULL) {
return bp->bpno;
}
}
else if(method_p->class_name != NULL) {
else if (method_p->class_name != NULL) {
m = mrb_method_search_vm(mrb, &class_obj, method_sym);
if(m == NULL) {
if (MRB_METHOD_UNDEF_P(m)) {
return MRB_DEBUG_OK;
}
if(MRB_PROC_CFUNC_P(m)) {
if (MRB_METHOD_CFUNC_P(m)) {
*isCfunc = TRUE;
}
is_defined = mrb_class_defined(mrb, method_p->class_name);
if(is_defined == FALSE) {
if (is_defined == FALSE) {
return MRB_DEBUG_OK;
}
sc = mrb_class_get(mrb, method_p->class_name);
ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name));
m = mrb_method_search_vm(mrb, &sc, ssym);
if(m == NULL) {
if (MRB_METHOD_UNDEF_P(m)) {
return MRB_DEBUG_OK;
}
class_name = get_class_name(mrb, class_obj);
sn = get_class_name(mrb, sc);
if(strcmp(sn, class_name) == 0) {
class_name = mrb_class_name(mrb, class_obj);
sn = mrb_class_name(mrb, sc);
if (strcmp(sn, class_name) == 0) {
return bp->bpno;
}
}
@@ -176,33 +166,34 @@ compare_break_method( mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *c
}
int32_t
mrb_debug_set_break_line( mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t lineno)
mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t lineno)
{
int32_t index;
char* set_file;
uint16_t result;
if((mrb == NULL)||(dbg == NULL)||(file == NULL)) {
if ((mrb == NULL)||(dbg == NULL)||(file == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
if(dbg->bpnum >= MAX_BREAKPOINT) {
if (dbg->bpnum >= MAX_BREAKPOINT) {
return MRB_DEBUG_BREAK_NUM_OVER;
}
if(dbg->next_bpno > MAX_BREAKPOINTNO) {
if (dbg->next_bpno > MAX_BREAKPOINTNO) {
return MRB_DEBUG_BREAK_NO_OVER;
}
/* file and lineno check (line type mrb_debug_line_ary only.) */
result = check_file_lineno( dbg->root_irep, file, lineno );
if(result == 0) {
result = check_file_lineno(dbg->root_irep, file, lineno);
if (result == 0) {
return MRB_DEBUG_BREAK_INVALID_FILE;
}else if(result == MRB_DEBUG_BP_FILE_OK) {
}
else if (result == MRB_DEBUG_BP_FILE_OK) {
return MRB_DEBUG_BREAK_INVALID_LINENO;
}
}
set_file = mrb_malloc(mrb, strlen(file) + 1);
set_file = (char*)mrb_malloc(mrb, strlen(file) + 1);
index = dbg->bpnum;
dbg->bp[index].bpno = dbg->next_bpno;
@@ -220,33 +211,33 @@ mrb_debug_set_break_line( mrb_state *mrb, mrb_debug_context *dbg, const char *fi
}
int32_t
mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char *class_name, const char *method_name )
mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *class_name, const char *method_name)
{
int32_t index;
char* set_class;
char* set_method;
if((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
if ((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
if(dbg->bpnum >= MAX_BREAKPOINT) {
if (dbg->bpnum >= MAX_BREAKPOINT) {
return MRB_DEBUG_BREAK_NUM_OVER;
}
if(dbg->next_bpno > MAX_BREAKPOINTNO) {
if (dbg->next_bpno > MAX_BREAKPOINTNO) {
return MRB_DEBUG_BREAK_NO_OVER;
}
if(class_name != NULL) {
set_class = mrb_malloc(mrb, strlen(class_name) + 1);
if (class_name != NULL) {
set_class = (char*)mrb_malloc(mrb, strlen(class_name) + 1);
strncpy(set_class, class_name, strlen(class_name) + 1);
}
else {
set_class = NULL;
}
set_method = mrb_malloc(mrb, strlen(method_name) + 1);
set_method = (char*)mrb_malloc(mrb, strlen(method_name) + 1);
strncpy(set_method, method_name, strlen(method_name) + 1);
@@ -263,25 +254,25 @@ mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char *
}
int32_t
mrb_debug_get_breaknum( mrb_state *mrb, mrb_debug_context *dbg )
mrb_debug_get_breaknum(mrb_state *mrb, mrb_debug_context *dbg)
{
if((mrb == NULL) || (dbg == NULL)) {
if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
return dbg->bpnum;
}
int32_t
mrb_debug_get_break_all( mrb_state *mrb, mrb_debug_context *dbg, uint32_t size, mrb_debug_breakpoint *bp )
int32_t
mrb_debug_get_break_all(mrb_state *mrb, mrb_debug_context *dbg, uint32_t size, mrb_debug_breakpoint *bp)
{
uint32_t get_size = 0;
if((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
if(dbg->bpnum >= size) {
if (dbg->bpnum >= size) {
get_size = size;
}
else {
@@ -294,16 +285,16 @@ mrb_debug_get_break_all( mrb_state *mrb, mrb_debug_context *dbg, uint32_t size,
}
int32_t
mrb_debug_get_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_debug_breakpoint *bp )
mrb_debug_get_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_debug_breakpoint *bp)
{
uint32_t index;
int32_t index;
if((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
index = get_break_index(dbg, bpno);
if(index == MRB_DEBUG_BREAK_INVALID_NO) {
if (index == MRB_DEBUG_BREAK_INVALID_NO) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
@@ -315,25 +306,25 @@ mrb_debug_get_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_
return 0;
}
int32_t
mrb_debug_delete_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
int32_t
mrb_debug_delete_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
{
uint32_t i;
int32_t index;
if((mrb == NULL) ||(dbg == NULL)) {
if ((mrb == NULL) ||(dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
index = get_break_index(dbg, bpno);
if(index == MRB_DEBUG_BREAK_INVALID_NO) {
if (index == MRB_DEBUG_BREAK_INVALID_NO) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
free_breakpoint(mrb, &dbg->bp[index]);
for(i = index ; i < dbg->bpnum; i++) {
if((i + 1) == dbg->bpnum) {
if ((i + 1) == dbg->bpnum) {
memset(&dbg->bp[i], 0, sizeof(mrb_debug_breakpoint));
}
else {
@@ -346,12 +337,12 @@ mrb_debug_delete_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
return MRB_DEBUG_OK;
}
int32_t
mrb_debug_delete_break_all( mrb_state *mrb, mrb_debug_context *dbg )
int32_t
mrb_debug_delete_break_all(mrb_state *mrb, mrb_debug_context *dbg)
{
uint32_t i;
if((mrb == NULL) || (dbg == NULL)) {
if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
@@ -364,17 +355,17 @@ mrb_debug_delete_break_all( mrb_state *mrb, mrb_debug_context *dbg )
return MRB_DEBUG_OK;
}
int32_t
mrb_debug_enable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
int32_t
mrb_debug_enable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
{
int32_t index = 0;
if((mrb == NULL) || (dbg == NULL)) {
if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
index = get_break_index(dbg, bpno);
if(index == MRB_DEBUG_BREAK_INVALID_NO) {
if (index == MRB_DEBUG_BREAK_INVALID_NO) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
@@ -384,11 +375,11 @@ mrb_debug_enable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
}
int32_t
mrb_debug_enable_break_all( mrb_state *mrb, mrb_debug_context *dbg )
mrb_debug_enable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
{
uint32_t i;
if((mrb == NULL) || (dbg == NULL)) {
if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
@@ -399,17 +390,17 @@ mrb_debug_enable_break_all( mrb_state *mrb, mrb_debug_context *dbg )
return MRB_DEBUG_OK;
}
int32_t
mrb_debug_disable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
int32_t
mrb_debug_disable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
{
int32_t index = 0;
if((mrb == NULL) || (dbg == NULL)) {
if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
index = get_break_index(dbg, bpno);
if(index == MRB_DEBUG_BREAK_INVALID_NO) {
if (index == MRB_DEBUG_BREAK_INVALID_NO) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
@@ -418,12 +409,12 @@ mrb_debug_disable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
return MRB_DEBUG_OK;
}
int32_t
mrb_debug_disable_break_all( mrb_state *mrb, mrb_debug_context *dbg )
int32_t
mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
{
uint32_t i;
if((mrb == NULL) || (dbg == NULL)) {
if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
@@ -435,10 +426,10 @@ mrb_debug_disable_break_all( mrb_state *mrb, mrb_debug_context *dbg )
}
static mrb_bool
check_start_pc_for_line( mrb_irep *irep, mrb_code *pc, uint16_t line )
check_start_pc_for_line(mrb_irep *irep, mrb_code *pc, uint16_t line)
{
if( pc > irep->iseq ) {
if( line == mrb_debug_get_line(irep, (uint32_t)(pc - irep->iseq - 1))) {
if (pc > irep->iseq) {
if (line == mrb_debug_get_line(irep, pc - irep->iseq - 1)) {
return FALSE;
}
}
@@ -446,17 +437,17 @@ check_start_pc_for_line( mrb_irep *irep, mrb_code *pc, uint16_t line )
}
int32_t
mrb_debug_check_breakpoint_line( mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t line )
mrb_debug_check_breakpoint_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t line)
{
mrb_debug_breakpoint *bp;
mrb_debug_linepoint *line_p;
int i;
uint32_t i;
if((mrb == NULL) || (dbg == NULL) || (file == NULL) || (line <= 0)) {
if ((mrb == NULL) || (dbg == NULL) || (file == NULL) || (line <= 0)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
if(!check_start_pc_for_line(dbg->irep, dbg->pc, line)) {
if (!check_start_pc_for_line(dbg->irep, dbg->pc, line)) {
return MRB_DEBUG_OK;
}
@@ -464,9 +455,9 @@ mrb_debug_check_breakpoint_line( mrb_state *mrb, mrb_debug_context *dbg, const c
for(i=0; i<dbg->bpnum; i++) {
switch (bp->type) {
case MRB_DEBUG_BPTYPE_LINE:
if(bp->enable == TRUE) {
if (bp->enable == TRUE) {
line_p = &bp->point.linepoint;
if((strcmp(line_p->file, file) == 0) && (line_p->lineno == line)) {
if ((strcmp(line_p->file, file) == 0) && (line_p->lineno == line)) {
return bp->bpno;
}
}
@@ -483,28 +474,28 @@ mrb_debug_check_breakpoint_line( mrb_state *mrb, mrb_debug_context *dbg, const c
}
int32_t
mrb_debug_check_breakpoint_method( mrb_state *mrb, mrb_debug_context *dbg, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc )
int32_t
mrb_debug_check_breakpoint_method(mrb_state *mrb, mrb_debug_context *dbg, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
{
mrb_debug_breakpoint *bp;
int32_t bpno;
int i;
uint32_t i;
if((mrb == NULL) || (dbg == NULL) || (class_obj == NULL)) {
if ((mrb == NULL) || (dbg == NULL) || (class_obj == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
bp = dbg->bp;
for(i=0; i<dbg->bpnum; i++) {
if(bp->type == MRB_DEBUG_BPTYPE_METHOD) {
if(bp->enable == TRUE) {
if (bp->type == MRB_DEBUG_BPTYPE_METHOD) {
if (bp->enable == TRUE) {
bpno = compare_break_method(mrb, bp, class_obj, method_sym, isCfunc);
if(bpno > 0) {
if (bpno > 0) {
return bpno;
}
}
}
else if(bp->type == MRB_DEBUG_BPTYPE_NONE) {
else if (bp->type == MRB_DEBUG_BPTYPE_NONE) {
break;
}
bp++;
@@ -512,5 +503,3 @@ mrb_debug_check_breakpoint_method( mrb_state *mrb, mrb_debug_context *dbg, struc
return 0;
}
+14 -14
View File
@@ -6,21 +6,21 @@
#ifndef APIBREAK_H_
#define APIBREAK_H_
#include "mruby.h"
#include <mruby.h>
#include "mrdb.h"
int32_t mrb_debug_set_break_line( mrb_state *, mrb_debug_context *, const char *, uint16_t );
int32_t mrb_debug_set_break_method( mrb_state *, mrb_debug_context *, const char *, const char * );
int32_t mrb_debug_get_breaknum( mrb_state *, mrb_debug_context * );
int32_t mrb_debug_get_break_all( mrb_state *, mrb_debug_context *, uint32_t, mrb_debug_breakpoint bp[]);
int32_t mrb_debug_get_break( mrb_state *, mrb_debug_context *, uint32_t, mrb_debug_breakpoint * );
int32_t mrb_debug_delete_break( mrb_state *, mrb_debug_context *, uint32_t );
int32_t mrb_debug_delete_break_all( mrb_state *, mrb_debug_context * );
int32_t mrb_debug_enable_break( mrb_state *, mrb_debug_context *, uint32_t );
int32_t mrb_debug_enable_break_all( mrb_state *, mrb_debug_context * );
int32_t mrb_debug_disable_break( mrb_state *, mrb_debug_context *, uint32_t );
int32_t mrb_debug_disable_break_all( mrb_state *, mrb_debug_context * );
int32_t mrb_debug_check_breakpoint_line( mrb_state *, mrb_debug_context *, const char *, uint16_t );
int32_t mrb_debug_check_breakpoint_method( mrb_state *, mrb_debug_context *, struct RClass *, mrb_sym, mrb_bool* );
int32_t mrb_debug_set_break_line(mrb_state *, mrb_debug_context *, const char *, uint16_t);
int32_t mrb_debug_set_break_method(mrb_state *, mrb_debug_context *, const char *, const char *);
int32_t mrb_debug_get_breaknum(mrb_state *, mrb_debug_context *);
int32_t mrb_debug_get_break_all(mrb_state *, mrb_debug_context *, uint32_t, mrb_debug_breakpoint bp[]);
int32_t mrb_debug_get_break(mrb_state *, mrb_debug_context *, uint32_t, mrb_debug_breakpoint *);
int32_t mrb_debug_delete_break(mrb_state *, mrb_debug_context *, uint32_t);
int32_t mrb_debug_delete_break_all(mrb_state *, mrb_debug_context *);
int32_t mrb_debug_enable_break(mrb_state *, mrb_debug_context *, uint32_t);
int32_t mrb_debug_enable_break_all(mrb_state *, mrb_debug_context *);
int32_t mrb_debug_disable_break(mrb_state *, mrb_debug_context *, uint32_t);
int32_t mrb_debug_disable_break_all(mrb_state *, mrb_debug_context *);
int32_t mrb_debug_check_breakpoint_line(mrb_state *, mrb_debug_context *, const char *, uint16_t);
int32_t mrb_debug_check_breakpoint_method(mrb_state *, mrb_debug_context *, struct RClass *, mrb_sym, mrb_bool*);
#endif /* APIBREAK_H_ */
+17 -12
View File
@@ -9,9 +9,9 @@
#include "mrdb.h"
#include "mrdberror.h"
#include "apilist.h"
#include "mruby/compile.h"
#include "mruby/irep.h"
#include "mruby/debug.h"
#include <mruby/compile.h>
#include <mruby/irep.h>
#include <mruby/debug.h>
#define LINE_BUF_SIZE MAX_COMMAND_LINE
@@ -48,7 +48,7 @@ build_path(mrb_state *mrb, const char *dir, const char *base)
len += strlen(dir) + sizeof("/") - 1;
}
path = mrb_malloc(mrb, len);
path = (char*)mrb_malloc(mrb, len);
memset(path, 0, len);
if (strcmp(dir, ".")) {
@@ -64,16 +64,17 @@ static char*
dirname(mrb_state *mrb, const char *path)
{
size_t len;
char *p, *dir;
const char *p;
char *dir;
if (path == NULL) {
return NULL;
}
p = strrchr(path, '/');
len = p != NULL ? p - path : strlen(path);
len = p != NULL ? (size_t)(p - path) : strlen(path);
dir = mrb_malloc(mrb, len + 1);
dir = (char*)mrb_malloc(mrb, len + 1);
strncpy(dir, path, len);
dir[len] = '\0';
@@ -83,9 +84,9 @@ dirname(mrb_state *mrb, const char *path)
static source_file*
source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename)
{
source_file *file = NULL;
source_file *file;
file = mrb_malloc(mrb, sizeof(source_file));
file = (source_file*)mrb_malloc(mrb, sizeof(source_file));
memset(file, '\0', sizeof(source_file));
file->fp = fopen(filename, "rb");
@@ -96,7 +97,7 @@ source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename)
}
file->lineno = 1;
file->path = mrb_malloc(mrb, strlen(filename) + 1);
file->path = (char*)mrb_malloc(mrb, strlen(filename) + 1);
strcpy(file->path, filename);
return file;
}
@@ -174,9 +175,13 @@ mrb_debug_get_source(mrb_state *mrb, mrdb_state *mrdb, const char *srcpath, cons
FILE *fp;
const char *search_path[3];
char *path = NULL;
const char *srcname = strrchr(filename, '/');
if (srcname) srcname++;
else srcname = filename;
search_path[0] = srcpath;
search_path[1] = dirname(mrb, mrb_debug_get_filename(mrdb->dbg->root_irep, 0));
search_path[1] = dirname(mrb, mrb_debug_get_filename(mrdb->dbg->irep, 0));
search_path[2] = ".";
for (i = 0; i < 3; i++) {
@@ -184,7 +189,7 @@ mrb_debug_get_source(mrb_state *mrb, mrdb_state *mrdb, const char *srcpath, cons
continue;
}
if ((path = build_path(mrb, search_path[i], filename)) == NULL) {
if ((path = build_path(mrb, search_path[i], srcname)) == NULL) {
continue;
}
+1 -1
View File
@@ -5,7 +5,7 @@
#ifndef APILIST_H_
#define APILIST_H_
#include "mruby.h"
#include <mruby.h>
#include "mrdb.h"
int32_t mrb_debug_list(mrb_state *, mrb_debug_context *, char *, uint16_t, uint16_t);
+6 -6
View File
@@ -5,12 +5,12 @@
#include <string.h>
#include "mrdb.h"
#include "mruby/value.h"
#include "mruby/class.h"
#include "mruby/compile.h"
#include "mruby/error.h"
#include "mruby/numeric.h"
#include "mruby/string.h"
#include <mruby/value.h>
#include <mruby/class.h>
#include <mruby/compile.h>
#include <mruby/error.h>
#include <mruby/numeric.h>
#include <mruby/string.h>
#include "apiprint.h"
static void
+1 -1
View File
@@ -5,7 +5,7 @@
#ifndef APIPRINT_H_
#define APIPRINT_H_
#include "mruby.h"
#include <mruby.h>
#include "mrdb.h"
mrb_value mrb_debug_eval(mrb_state*, mrb_debug_context*, const char*, size_t, mrb_bool*);
+53 -45
View File
@@ -5,10 +5,10 @@
#include <ctype.h>
#include <string.h>
#include "mruby.h"
#include "mruby/dump.h"
#include "mruby/debug.h"
#include "mruby/string.h"
#include <mruby.h>
#include <mruby/dump.h>
#include <mruby/debug.h>
#include <mruby/string.h>
#include "mrdb.h"
#include "mrdberror.h"
#include "apibreak.h"
@@ -70,12 +70,12 @@ parse_breakpoint_no(char* args)
char* ps = args;
uint32_t l;
if((*ps == '0')||(strlen(ps) >= BPNO_LETTER_NUM)) {
if ((*ps == '0')||(strlen(ps) >= BPNO_LETTER_NUM)) {
return 0;
}
while( !(ISBLANK(*ps)||ISCNTRL(*ps)) ) {
if(!ISDIGIT(*ps)) {
while (!(ISBLANK(*ps)||ISCNTRL(*ps))) {
if (!ISDIGIT(*ps)) {
return 0;
}
ps++;
@@ -90,7 +90,7 @@ exe_set_command_all(mrb_state *mrb, mrdb_state *mrdb, all_command_func func)
{
int32_t ret = MRB_DEBUG_OK;
if(mrdb->wcnt == 1) {
if (mrdb->wcnt == 1) {
ret = func(mrb, mrdb->dbg);
print_api_common_error(ret);
return TRUE;
@@ -109,15 +109,15 @@ exe_set_command_select(mrb_state *mrb, mrdb_state *mrdb, select_command_func fun
for(i=1; i<mrdb->wcnt; i++) {
ps = mrdb->words[i];
bpno = parse_breakpoint_no(ps);
if(bpno == 0) {
if (bpno == 0) {
printf(BREAK_ERR_MSG_INVALIDBPNO, ps);
break;
}
ret = func(mrb, mrdb->dbg, (uint32_t)bpno);
if(ret == MRB_DEBUG_BREAK_INVALID_NO) {
if (ret == MRB_DEBUG_BREAK_INVALID_NO) {
printf(BREAK_ERR_MSG_NOBPNO, bpno);
}
else if(ret != MRB_DEBUG_OK) {
else if (ret != MRB_DEBUG_OK) {
print_api_common_error(ret);
}
}
@@ -128,24 +128,24 @@ check_bptype(char* args)
{
char* ps = args;
if(ISBLANK(*ps)||ISCNTRL(*ps)) {
if (ISBLANK(*ps)||ISCNTRL(*ps)) {
puts(BREAK_ERR_MSG_BLANK);
return MRB_DEBUG_BPTYPE_NONE;
}
if(!ISDIGIT(*ps)) {
if (!ISDIGIT(*ps)) {
return MRB_DEBUG_BPTYPE_METHOD;
}
while( !(ISBLANK(*ps)||ISCNTRL(*ps)) ) {
if(!ISDIGIT(*ps)) {
while (!(ISBLANK(*ps)||ISCNTRL(*ps))) {
if (!ISDIGIT(*ps)) {
printf(BREAK_ERR_MSG_INVALIDSTR, args);
return MRB_DEBUG_BPTYPE_NONE;
}
ps++;
}
if((*args == '0')||(strlen(args) >= LINENO_MAX_DIGIT)) {
if ((*args == '0')||(strlen(args) >= LINENO_MAX_DIGIT)) {
puts(BREAK_ERR_MSG_RANGEOVER);
return MRB_DEBUG_BPTYPE_NONE;
}
@@ -158,12 +158,12 @@ print_breakpoint(mrb_debug_breakpoint *bp)
{
const char* enable_letter[] = {BREAK_INFO_MSG_DISABLE, BREAK_INFO_MSG_ENABLE};
if(bp->type == MRB_DEBUG_BPTYPE_LINE) {
if (bp->type == MRB_DEBUG_BPTYPE_LINE) {
printf(BREAK_INFO_MSG_LINEBREAK,
bp->bpno, enable_letter[bp->enable], bp->point.linepoint.file, bp->point.linepoint.lineno);
}
else {
if(bp->point.methodpoint.class_name == NULL) {
if (bp->point.methodpoint.class_name == NULL) {
printf(BREAK_INFO_MSG_METHODBREAK_NOCLASS,
bp->bpno, enable_letter[bp->enable], bp->point.methodpoint.method_name);
}
@@ -183,18 +183,18 @@ info_break_all(mrb_state *mrb, mrdb_state *mrdb)
mrb_debug_breakpoint *bp_list;
bpnum = mrb_debug_get_breaknum(mrb, mrdb->dbg);
if(bpnum < 0) {
if (bpnum < 0) {
print_api_common_error(bpnum);
return;
}
else if(bpnum == 0) {
else if (bpnum == 0) {
puts(BREAK_ERR_MSG_NOBPNO_INFOALL);
return;
}
bp_list = (mrb_debug_breakpoint*)mrb_malloc(mrb, bpnum * sizeof(mrb_debug_breakpoint));
ret = mrb_debug_get_break_all(mrb, mrdb->dbg, (uint32_t)bpnum, bp_list);
if(ret < 0) {
if (ret < 0) {
print_api_common_error(ret);
return;
}
@@ -219,21 +219,21 @@ info_break_select(mrb_state *mrb, mrdb_state *mrdb)
for(i=2; i<mrdb->wcnt; i++) {
ps = mrdb->words[i];
bpno = parse_breakpoint_no(ps);
if(bpno == 0) {
if (bpno == 0) {
puts(BREAK_ERR_MSG_INVALIDBPNO_INFO);
break;
}
ret = mrb_debug_get_break(mrb, mrdb->dbg, bpno, &bp);
if(ret == MRB_DEBUG_BREAK_INVALID_NO) {
if (ret == MRB_DEBUG_BREAK_INVALID_NO) {
printf(BREAK_ERR_MSG_NOBPNO_INFO, bpno);
break;
}
else if(ret != MRB_DEBUG_OK) {
else if (ret != MRB_DEBUG_OK) {
print_api_common_error(ret);
break;
}
else if(isFirst == TRUE) {
else if (isFirst == TRUE) {
isFirst = FALSE;
puts(BREAK_INFO_MSG_HEADER);
}
@@ -250,17 +250,18 @@ parse_breakcommand(mrdb_state *mrdb, const char **file, uint32_t *line, char **c
mrb_debug_bptype type;
uint32_t l;
if(mrdb->wcnt <= 1) {
if (mrdb->wcnt <= 1) {
puts(BREAK_ERR_MSG_BLANK);
return MRB_DEBUG_BPTYPE_NONE;
}
args = mrdb->words[1];
if((body = strrchr(args, ':')) == NULL) {
if ((body = strrchr(args, ':')) == NULL) {
body = args;
type = check_bptype(body);
} else {
if(body == args) {
}
else {
if (body == args) {
printf(BREAK_ERR_MSG_INVALIDSTR, args);
return MRB_DEBUG_BPTYPE_NONE;
}
@@ -271,26 +272,29 @@ parse_breakcommand(mrdb_state *mrdb, const char **file, uint32_t *line, char **c
switch(type) {
case MRB_DEBUG_BPTYPE_LINE:
STRTOUL(l, body);
if( l <= 65535 ) {
if (l <= 65535) {
*line = l;
*file = (body == args)? mrb_debug_get_filename(dbg->irep, (uint32_t)(dbg->pc - dbg->irep->iseq)): args;
} else {
*file = (body == args)? mrb_debug_get_filename(dbg->irep, dbg->pc - dbg->irep->iseq): args;
}
else {
puts(BREAK_ERR_MSG_RANGEOVER);
type = MRB_DEBUG_BPTYPE_NONE;
}
break;
case MRB_DEBUG_BPTYPE_METHOD:
if(body == args) {
if (body == args) {
/* method only */
if( ISUPPER(*body)||ISLOWER(*body)||(*body == '_') ) {
if (ISUPPER(*body)||ISLOWER(*body)||(*body == '_')) {
*method = body;
*cname = NULL;
} else {
}
else {
printf(BREAK_ERR_MSG_INVALIDMETHOD, args);
type = MRB_DEBUG_BPTYPE_NONE;
}
} else {
if( ISUPPER(*args) ) {
}
else {
if (ISUPPER(*args)) {
switch(*body) {
case '@': case '$': case '?': case '.': case ',': case ':':
case ';': case '#': case '\\': case '\'': case '\"':
@@ -302,7 +306,8 @@ parse_breakcommand(mrdb_state *mrdb, const char **file, uint32_t *line, char **c
*cname = args;
break;
}
} else {
}
else {
printf(BREAK_ERR_MSG_INVALIDCLASS, args);
type = MRB_DEBUG_BPTYPE_NONE;
}
@@ -343,12 +348,15 @@ dbgcmd_break(mrb_state *mrb, mrdb_state *mrdb)
if (ret >= 0) {
if (type == MRB_DEBUG_BPTYPE_LINE) {
printf(BREAK_SET_MSG_LINE, ret, file, line);
} else if ((type == MRB_DEBUG_BPTYPE_METHOD)&&(cname == NULL)) {
}
else if ((type == MRB_DEBUG_BPTYPE_METHOD)&&(cname == NULL)) {
printf(BREAK_SET_MSG_METHOD, ret, method);
} else {
}
else {
printf(BREAK_SET_MSG_CLASS_METHOD, ret, cname, method);
}
} else {
}
else {
switch (ret) {
case MRB_DEBUG_BREAK_INVALID_LINENO:
printf(BREAK_ERR_MSG_INVALIDLINENO, line, file);
@@ -379,7 +387,7 @@ dbgcmd_break(mrb_state *mrb, mrdb_state *mrdb)
dbgcmd_state
dbgcmd_info_break(mrb_state *mrb, mrdb_state *mrdb)
{
if(mrdb->wcnt == 2) {
if (mrdb->wcnt == 2) {
info_break_all(mrb, mrdb);
}
else {
@@ -395,7 +403,7 @@ dbgcmd_delete(mrb_state *mrb, mrdb_state *mrdb)
mrb_bool ret = FALSE;
ret = exe_set_command_all(mrb, mrdb, mrb_debug_delete_break_all);
if(ret != TRUE) {
if (ret != TRUE) {
exe_set_command_select(mrb, mrdb, mrb_debug_delete_break);
}
@@ -408,7 +416,7 @@ dbgcmd_enable(mrb_state *mrb, mrdb_state *mrdb)
mrb_bool ret = FALSE;
ret = exe_set_command_all(mrb, mrdb, mrb_debug_enable_break_all);
if(ret != TRUE) {
if (ret != TRUE) {
exe_set_command_select(mrb, mrdb, mrb_debug_enable_break);
}
@@ -421,7 +429,7 @@ dbgcmd_disable(mrb_state *mrb, mrdb_state *mrdb)
mrb_bool ret = FALSE;
ret = exe_set_command_all(mrb, mrdb, mrb_debug_disable_break_all);
if(ret != TRUE) {
if (ret != TRUE) {
exe_set_command_select(mrb, mrdb, mrb_debug_disable_break);
}
return DBGST_PROMPT;
+8 -7
View File
@@ -8,7 +8,7 @@
#include <string.h>
#include "apilist.h"
#include "mruby/compile.h"
#include <mruby/compile.h>
typedef struct help_msg {
const char *cmd1;
@@ -133,7 +133,7 @@ typedef struct listcmd_parser_state {
static listcmd_parser_state*
listcmd_parser_state_new(mrb_state *mrb)
{
listcmd_parser_state *st = mrb_malloc(mrb, sizeof(listcmd_parser_state));
listcmd_parser_state *st = (listcmd_parser_state*)mrb_malloc(mrb, sizeof(listcmd_parser_state));
memset(st, 0, sizeof(listcmd_parser_state));
return st;
}
@@ -227,7 +227,7 @@ parse_filename(mrb_state *mrb, char **sp, listcmd_parser_state *st)
}
if (len > 0) {
st->filename = mrb_malloc(mrb, len + 1);
st->filename = (char*)mrb_malloc(mrb, len + 1);
strncpy(st->filename, *sp, len);
st->filename[len] = '\0';
*sp += len;
@@ -242,7 +242,8 @@ char*
replace_ext(mrb_state *mrb, const char *filename, const char *ext)
{
size_t len;
char *p, *s;
const char *p;
char *s;
if (filename == NULL) {
return NULL;
@@ -255,7 +256,7 @@ replace_ext(mrb_state *mrb, const char *filename, const char *ext)
len = strlen(filename);
}
s = mrb_malloc(mrb, len + strlen(ext) + 1);
s = (char*)mrb_malloc(mrb, len + strlen(ext) + 1);
memset(s, '\0', len + strlen(ext) + 1);
strncpy(s, filename, len);
strcat(s, ext);
@@ -325,7 +326,7 @@ parse_listcmd_args(mrb_state *mrb, mrdb_state *mrdb, listcmd_parser_state *st)
static mrb_bool
check_cmd_pattern(const char *pattern, const char *cmd)
{
char *lbracket, *rbracket, *p, *q;
const char *lbracket, *rbracket, *p, *q;
if (pattern == NULL && cmd == NULL) {
return TRUE;
@@ -333,7 +334,7 @@ check_cmd_pattern(const char *pattern, const char *cmd)
if (pattern == NULL || cmd == NULL) {
return FALSE;
}
if((lbracket = strchr(pattern, '[')) == NULL) {
if ((lbracket = strchr(pattern, '[')) == NULL) {
return !strcmp(pattern, cmd);
}
if ((rbracket = strchr(pattern, ']')) == NULL) {
+6 -6
View File
@@ -5,12 +5,12 @@
#include <string.h>
#include "mrdb.h"
#include "mruby/value.h"
#include "mruby/class.h"
#include "mruby/compile.h"
#include "mruby/error.h"
#include "mruby/numeric.h"
#include "mruby/string.h"
#include <mruby/value.h>
#include <mruby/class.h>
#include <mruby/compile.h>
#include <mruby/error.h>
#include <mruby/numeric.h>
#include <mruby/string.h>
#include "apiprint.h"
dbgcmd_state
+18 -8
View File
@@ -3,7 +3,7 @@
**
*/
#include "mruby/opcode.h"
#include <mruby/opcode.h>
#include "mrdb.h"
dbgcmd_state
@@ -11,18 +11,19 @@ dbgcmd_run(mrb_state *mrb, mrdb_state *mrdb)
{
mrb_debug_context *dbg = mrdb->dbg;
if( dbg->xm == DBG_INIT ){
if (dbg->xm == DBG_INIT){
dbg->xm = DBG_RUN;
} else {
}
else {
dbg->xm = DBG_QUIT;
if( dbg->xphase == DBG_PHASE_RUNNING ){
if (dbg->xphase == DBG_PHASE_RUNNING){
struct RClass *exc;
puts("Start it from the beginning.");
exc = mrb_define_class(mrb, "DebuggerRestart", mrb_class_get(mrb, "Exception"));
mrb_raise(mrb, exc, "Restart mrdb.");
}
}
return DBGST_RESTART;
}
@@ -32,15 +33,16 @@ dbgcmd_continue(mrb_state *mrb, mrdb_state *mrdb)
mrb_debug_context *dbg = mrdb->dbg;
int ccnt = 1;
if( mrdb->wcnt > 1 ){
if (mrdb->wcnt > 1){
sscanf(mrdb->words[1], "%d", &ccnt);
}
dbg->ccnt = (uint16_t)(ccnt > 0 ? ccnt : 1); /* count of continue */
if( dbg->xphase == DBG_PHASE_AFTER_RUN ){
if (dbg->xphase == DBG_PHASE_AFTER_RUN){
puts("The program is not running.");
dbg->xm = DBG_QUIT;
} else {
}
else {
dbg->xm = DBG_RUN;
}
return DBGST_CONTINUE;
@@ -52,3 +54,11 @@ dbgcmd_step(mrb_state *mrb, mrdb_state *mrdb)
mrdb->dbg->xm = DBG_STEP;
return DBGST_CONTINUE;
}
dbgcmd_state
dbgcmd_next(mrb_state *mrb, mrdb_state *mrdb)
{
mrdb->dbg->xm = DBG_NEXT;
mrdb->dbg->prvci = mrb->c->ci;
return DBGST_CONTINUE;
}
+42 -29
View File
@@ -8,12 +8,12 @@
#include <stdio.h>
#include <ctype.h>
#include "mruby.h"
#include "mruby/dump.h"
#include "mruby/debug.h"
#include "mruby/class.h"
#include "mruby/opcode.h"
#include "mruby/variable.h"
#include <mruby.h>
#include <mruby/dump.h>
#include <mruby/debug.h>
#include <mruby/class.h>
#include <mruby/opcode.h>
#include <mruby/variable.h>
#include "mrdb.h"
#include "apibreak.h"
@@ -57,6 +57,7 @@ static const debug_command debug_command_list[] = {
{"quit", NULL, 1, 0, 0, DBGCMD_QUIT, dbgcmd_quit}, /* q[uit] */
{"run", NULL, 1, 0, 0, DBGCMD_RUN, dbgcmd_run}, /* r[un] */
{"step", NULL, 1, 0, 1, DBGCMD_STEP, dbgcmd_step}, /* s[tep] */
{"next", NULL, 1, 0, 1, DBGCMD_NEXT, dbgcmd_next}, /* n[ext] */
{NULL}
};
@@ -183,7 +184,7 @@ cleanup(mrb_state *mrb, struct _args *args)
static mrb_debug_context*
mrb_debug_context_new(mrb_state *mrb)
{
mrb_debug_context *dbg = mrb_malloc(mrb, sizeof(mrb_debug_context));
mrb_debug_context *dbg = (mrb_debug_context*)mrb_malloc(mrb, sizeof(mrb_debug_context));
memset(dbg, 0, sizeof(mrb_debug_context));
@@ -222,12 +223,12 @@ mrb_debug_context_free(mrb_state *mrb)
static mrdb_state*
mrdb_state_new(mrb_state *mrb)
{
mrdb_state *mrdb = mrb_malloc(mrb, sizeof(mrdb_state));
mrdb_state *mrdb = (mrdb_state*)mrb_malloc(mrb, sizeof(mrdb_state));
memset(mrdb, 0, sizeof(mrdb_state));
mrdb->dbg = mrb_debug_context_get(mrb);
mrdb->command = mrb_malloc(mrb, MAX_COMMAND_LINE+1);
mrdb->command = (char*)mrb_malloc(mrb, MAX_COMMAND_LINE+1);
mrdb->print_no = 1;
return mrdb;
@@ -405,7 +406,7 @@ print_info_stopped_break(mrb_state *mrb, mrdb_state *mrdb)
const char *class_name;
ret = mrb_debug_get_break(mrb, mrdb->dbg, mrdb->dbg->stopped_bpno, &bp);
if(ret == 0) {
if (ret == 0) {
switch(bp.type) {
case MRB_DEBUG_BPTYPE_LINE:
file = bp.point.linepoint.file;
@@ -415,13 +416,13 @@ print_info_stopped_break(mrb_state *mrb, mrdb_state *mrdb)
case MRB_DEBUG_BPTYPE_METHOD:
method_name = bp.point.methodpoint.method_name;
class_name = bp.point.methodpoint.class_name;
if(class_name == NULL) {
if (class_name == NULL) {
printf("Breakpoint %d, %s\n", bp.bpno, method_name);
}
else {
printf("Breakpoint %d, %s:%s\n", bp.bpno, class_name, method_name);
}
if(mrdb->dbg->isCfunc) {
if (mrdb->dbg->isCfunc) {
printf("Stopped before calling the C function.\n");
}
break;
@@ -444,7 +445,7 @@ print_info_stopped_code(mrb_state *mrb, mrdb_state *mrdb)
{
char* file = mrb_debug_get_source(mrb, mrdb, mrdb->srcpath, mrdb->dbg->prvfile);
uint16_t lineno = mrdb->dbg->prvline;
if(file != NULL) {
if (file != NULL) {
mrb_debug_list(mrb, mrdb->dbg, file, lineno, lineno);
mrb_free(mrb, file);
}
@@ -530,9 +531,9 @@ check_method_breakpoint(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value
sym = 0;
break;
}
if(sym != 0) {
if (sym != 0) {
dbg->method_bpno = mrb_debug_check_breakpoint_method(mrb, dbg, c, sym, &isCfunc);
if(isCfunc) {
if (isCfunc) {
bpno = dbg->method_bpno;
dbg->method_bpno = 0;
}
@@ -556,20 +557,20 @@ mrb_code_fetch_hook(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value *reg
dbg->pc = pc;
dbg->regs = regs;
if(dbg->xphase == DBG_PHASE_RESTART) {
if (dbg->xphase == DBG_PHASE_RESTART) {
dbg->root_irep = irep;
dbg->prvfile = NULL;
dbg->prvline = 0;
dbg->prvci = NULL;
dbg->xm = DBG_RUN;
dbg->xphase = DBG_PHASE_RUNNING;
}
file = mrb_debug_get_filename(irep, (uint32_t)(pc - irep->iseq));
line = mrb_debug_get_line(irep, (uint32_t)(pc - irep->iseq));
file = mrb_debug_get_filename(irep, pc - irep->iseq);
line = mrb_debug_get_line(irep, pc - irep->iseq);
switch (dbg->xm) {
case DBG_STEP:
case DBG_NEXT: // temporary
if (!file || (dbg->prvfile == file && dbg->prvline == line)) {
return;
}
@@ -577,6 +578,18 @@ mrb_code_fetch_hook(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value *reg
dbg->bm = BRK_STEP;
break;
case DBG_NEXT:
if (!file || (dbg->prvfile == file && dbg->prvline == line)) {
return;
}
if ((intptr_t)(dbg->prvci) < (intptr_t)(mrb->c->ci)) {
return;
}
dbg->prvci = NULL;
dbg->method_bpno = 0;
dbg->bm = BRK_NEXT;
break;
case DBG_RUN:
bpno = check_method_breakpoint(mrb, irep, pc, regs);
if (bpno > 0) {
@@ -610,7 +623,7 @@ mrb_code_fetch_hook(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value *reg
dbg->prvfile = file;
dbg->prvline = line;
if(dbg->bm == BRK_BREAK && --dbg->ccnt > 0) {
if (dbg->bm == BRK_BREAK && --dbg->ccnt > 0) {
return;
}
dbg->break_hook(mrb, dbg);
@@ -633,7 +646,7 @@ mrb_debug_break_hook(mrb_state *mrb, mrb_debug_context *dbg)
st = cmd->func(mrb, mrdb);
if( (st == DBGST_CONTINUE) || (st == DBGST_RESTART) ) break;
if ((st == DBGST_CONTINUE) || (st == DBGST_RESTART)) break;
}
return dbg->xm;
}
@@ -670,7 +683,7 @@ main(int argc, char **argv)
mrb_assert(mrdb && mrdb->dbg);
mrdb->srcpath = args.srcpath;
if(mrdb->dbg->xm == DBG_QUIT) {
if (mrdb->dbg->xm == DBG_QUIT) {
mrdb->dbg->xphase = DBG_PHASE_RESTART;
}
else {
@@ -678,7 +691,7 @@ main(int argc, char **argv)
}
mrdb->dbg->xm = DBG_INIT;
mrdb->dbg->ccnt = 1;
/* setup hook functions */
mrb->code_fetch_hook = mrb_code_fetch_hook;
mrdb->dbg->break_hook = mrb_debug_break_hook;
@@ -725,21 +738,21 @@ main(int argc, char **argv)
mrb_p(mrb, v);
}
}
mrdb->dbg->prvfile = "-";
mrdb->dbg->prvline = 0;
while (1) {
cmd = get_and_parse_command(mrb, mrdb);
mrb_assert(cmd);
if (cmd->id == DBGCMD_QUIT) {
break;
}
if( cmd->func(mrb, mrdb) == DBGST_RESTART ) goto l_restart;
if ( cmd->func(mrb, mrdb) == DBGST_RESTART ) goto l_restart;
}
cleanup(mrb, &args);
return 0;
+3 -1
View File
@@ -6,7 +6,7 @@
#ifndef MRDB_H
#define MRDB_H
#include "mruby.h"
#include <mruby.h>
#include "mrdbconf.h"
@@ -109,6 +109,7 @@ typedef struct mrb_debug_context {
const char *prvfile;
int32_t prvline;
mrb_callinfo *prvci;
mrdb_exemode xm;
mrdb_exephase xphase;
@@ -146,6 +147,7 @@ typedef dbgcmd_state (*debug_command_func)(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_run(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_continue(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_step(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_next(mrb_state*, mrdb_state*);
/* cmdbreak.c */
dbgcmd_state dbgcmd_break(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_info_break(mrb_state*, mrdb_state*);
View File
View File
+133 -15
View File
@@ -11,11 +11,20 @@
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <setjmp.h>
#ifdef ENABLE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#define MIRB_ADD_HISTORY(line) add_history(line)
#define MIRB_READLINE(ch) readline(ch)
#if !defined(RL_READLINE_VERSION) || RL_READLINE_VERSION < 0x600
/* libedit & older readline do not have rl_free() */
#define MIRB_LINE_FREE(line) free(line)
#else
#define MIRB_LINE_FREE(line) rl_free(line)
#endif
#define MIRB_WRITE_HISTORY(path) write_history(path)
#define MIRB_READ_HISTORY(path) read_history(path)
#define MIRB_USING_HISTORY() using_history()
@@ -24,16 +33,27 @@
#include <linenoise.h>
#define MIRB_ADD_HISTORY(line) linenoiseHistoryAdd(line)
#define MIRB_READLINE(ch) linenoise(ch)
#define MIRB_LINE_FREE(line) linenoiseFree(line)
#define MIRB_WRITE_HISTORY(path) linenoiseHistorySave(path)
#define MIRB_READ_HISTORY(path) linenoiseHistoryLoad(history_path)
#define MIRB_USING_HISTORY()
#endif
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/proc.h"
#include "mruby/compile.h"
#include "mruby/string.h"
#ifndef _WIN32
#define MIRB_SIGSETJMP(env) sigsetjmp(env, 1)
#define MIRB_SIGLONGJMP(env, val) siglongjmp(env, val)
#define SIGJMP_BUF sigjmp_buf
#else
#define MIRB_SIGSETJMP(env) setjmp(env)
#define MIRB_SIGLONGJMP(env, val) longjmp(env, val)
#define SIGJMP_BUF jmp_buf
#endif
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/proc.h>
#include <mruby/compile.h>
#include <mruby/string.h>
#ifdef ENABLE_READLINE
@@ -75,6 +95,7 @@ static void
p(mrb_state *mrb, mrb_value obj, int prompt)
{
mrb_value val;
char* msg;
val = mrb_funcall(mrb, obj, "inspect", 0);
if (prompt) {
@@ -88,7 +109,9 @@ p(mrb_state *mrb, mrb_value obj, int prompt)
if (!mrb_string_p(val)) {
val = mrb_obj_as_string(mrb, obj);
}
fwrite(RSTRING_PTR(val), RSTRING_LEN(val), 1, stdout);
msg = mrb_locale_from_utf8(RSTRING_PTR(val), RSTRING_LEN(val));
fwrite(msg, strlen(msg), 1, stdout);
mrb_locale_free(msg);
putc('\n', stdout);
}
@@ -194,6 +217,7 @@ is_code_block_open(struct mrb_parser_state *parser)
}
struct _args {
FILE *rfp;
mrb_bool verbose : 1;
int argc;
char** argv;
@@ -251,12 +275,30 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
return EXIT_FAILURE;
}
}
if (args->rfp == NULL) {
if (*argv != NULL) {
args->rfp = fopen(argv[0], "r");
if (args->rfp == NULL) {
printf("Cannot open program file. (%s)\n", *argv);
return EXIT_FAILURE;
}
argc--; argv++;
}
}
args->argv = (char **)mrb_realloc(mrb, args->argv, sizeof(char*) * (argc + 1));
memcpy(args->argv, argv, (argc+1) * sizeof(char*));
args->argc = argc;
return EXIT_SUCCESS;
}
static void
cleanup(mrb_state *mrb, struct _args *args)
{
if (args->rfp)
fclose(args->rfp);
mrb_free(mrb, args->argv);
mrb_close(mrb);
}
@@ -307,23 +349,43 @@ check_keyword(const char *buf, const char *word)
return 1;
}
#ifndef ENABLE_READLINE
volatile sig_atomic_t input_canceled = 0;
void
ctrl_c_handler(int signo)
{
input_canceled = 1;
}
#else
SIGJMP_BUF ctrl_c_buf;
void
ctrl_c_handler(int signo)
{
MIRB_SIGLONGJMP(ctrl_c_buf, 1);
}
#endif
int
main(int argc, char **argv)
{
char ruby_code[1024] = { 0 };
char ruby_code[4096] = { 0 };
char last_code_line[1024] = { 0 };
#ifndef ENABLE_READLINE
int last_char;
int char_index;
size_t char_index;
#else
char *history_path;
char* line;
#endif
mrbc_context *cxt;
struct mrb_parser_state *parser;
mrb_state *mrb;
mrb_value result;
struct _args args;
mrb_value ARGV;
int n;
int i;
mrb_bool code_block_open = FALSE;
int ai;
unsigned int stack_keep = 0;
@@ -334,7 +396,6 @@ main(int argc, char **argv)
fputs("Invalid mrb interpreter, exiting mirb\n", stderr);
return EXIT_FAILURE;
}
mrb_define_global_const(mrb, "ARGV", mrb_ary_new_capa(mrb, 0));
n = parse_args(mrb, argc, argv, &args);
if (n == EXIT_FAILURE) {
@@ -343,6 +404,16 @@ main(int argc, char **argv)
return n;
}
ARGV = mrb_ary_new_capa(mrb, args.argc);
for (i = 0; i < args.argc; i++) {
char* utf8 = mrb_utf8_from_locale(args.argv[i], -1);
if (utf8) {
mrb_ary_push(mrb, ARGV, mrb_str_new_cstr(mrb, utf8));
mrb_utf8_free(utf8);
}
}
mrb_define_global_const(mrb, "ARGV", ARGV);
#ifdef ENABLE_READLINE
history_path = get_history_path(mrb);
if (history_path == NULL) {
@@ -368,18 +439,34 @@ main(int argc, char **argv)
while (TRUE) {
char *utf8;
if (args.rfp) {
if (fgets(last_code_line, sizeof(last_code_line)-1, args.rfp) != NULL)
goto done;
break;
}
#ifndef ENABLE_READLINE
print_cmdline(code_block_open);
signal(SIGINT, ctrl_c_handler);
char_index = 0;
while ((last_char = getchar()) != '\n') {
if (last_char == EOF) break;
if (char_index > sizeof(last_code_line)-2) {
if (char_index >= sizeof(last_code_line)-2) {
fputs("input string too long\n", stderr);
continue;
}
last_code_line[char_index++] = last_char;
}
signal(SIGINT, SIG_DFL);
if (input_canceled) {
ruby_code[0] = '\0';
last_code_line[0] = '\0';
code_block_open = FALSE;
puts("^C");
input_canceled = 0;
continue;
}
if (last_char == EOF) {
fputs("\n", stdout);
break;
@@ -388,7 +475,19 @@ main(int argc, char **argv)
last_code_line[char_index++] = '\n';
last_code_line[char_index] = '\0';
#else
char* line = MIRB_READLINE(code_block_open ? "* " : "> ");
if (MIRB_SIGSETJMP(ctrl_c_buf) == 0) {
;
}
else {
ruby_code[0] = '\0';
last_code_line[0] = '\0';
code_block_open = FALSE;
puts("^C");
}
signal(SIGINT, ctrl_c_handler);
line = MIRB_READLINE(code_block_open ? "* " : "> ");
signal(SIGINT, SIG_DFL);
if (line == NULL) {
printf("\n");
break;
@@ -400,9 +499,11 @@ main(int argc, char **argv)
strcpy(last_code_line, line);
strcat(last_code_line, "\n");
MIRB_ADD_HISTORY(line);
free(line);
MIRB_LINE_FREE(line);
#endif
done:
if (code_block_open) {
if (strlen(ruby_code)+strlen(last_code_line) > sizeof(ruby_code)-1) {
fputs("concatenated input string too long\n", stderr);
@@ -437,9 +538,17 @@ main(int argc, char **argv)
/* no evaluation of code */
}
else {
if (0 < parser->nwarn) {
/* warning */
char* msg = mrb_locale_from_utf8(parser->warn_buffer[0].message, -1);
printf("line %d: %s\n", parser->warn_buffer[0].lineno, msg);
mrb_utf8_free(msg);
}
if (0 < parser->nerr) {
/* syntax error */
printf("line %d: %s\n", parser->error_buffer[0].lineno, parser->error_buffer[0].message);
char* msg = mrb_locale_from_utf8(parser->error_buffer[0].message, -1);
printf("line %d: %s\n", parser->error_buffer[0].lineno, msg);
mrb_utf8_free(msg);
}
else {
/* generate bytecode */
@@ -453,9 +562,16 @@ main(int argc, char **argv)
if (args.verbose) {
mrb_codedump_all(mrb, proc);
}
/* pass a proc for evaulation */
/* adjust stack length of toplevel environment */
if (mrb->c->cibase->env) {
struct REnv *e = mrb->c->cibase->env;
if (e && MRB_ENV_STACK_LEN(e) < proc->body.irep->nlocals) {
MRB_ENV_SET_STACK_LEN(e, proc->body.irep->nlocals);
}
}
/* pass a proc for evaluation */
/* evaluate the bytecode */
result = mrb_context_run(mrb,
result = mrb_vm_run(mrb,
proc,
mrb_top_self(mrb),
stack_keep);
@@ -486,6 +602,8 @@ main(int argc, char **argv)
mrb_free(mrb, history_path);
#endif
if (args.rfp) fclose(args.rfp);
mrb_free(mrb, args.argv);
mrbc_context_free(mrb, cxt);
mrb_close(mrb);
+4 -4
View File
@@ -1,10 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mruby.h"
#include "mruby/compile.h"
#include "mruby/dump.h"
#include "mruby/proc.h"
#include <mruby.h>
#include <mruby/compile.h>
#include <mruby/dump.h>
#include <mruby/proc.h>
#define RITEBIN_EXT ".mrb"
#define C_EXT ".c"
+1 -1
View File
@@ -23,7 +23,7 @@ MRuby.each_target do
FileUtils.copy "#{File.dirname(__FILE__)}/#{mruby_config}", t.name
config = Hash[open("#{build_dir}/lib/libmruby.flags.mak").read.split("\n").map {|x| a = x.split(/\s*=\s*/, 2); [a[0], a[1].gsub('\\"', '"') ]}]
IO.write(t.name, File.open(t.name) {|f|
f.read.gsub (/echo (MRUBY_CFLAGS|MRUBY_LIBS|MRUBY_LDFLAGS_BEFORE_LIBS|MRUBY_LDFLAGS)/) {|x| config[$1].empty? ? '' : "echo #{config[$1]}"}
f.read.gsub (/echo (MRUBY_CFLAGS|MRUBY_LIBS|MRUBY_LDFLAGS_BEFORE_LIBS|MRUBY_LDFLAGS|MRUBY_LIBMRUBY_PATH)/) {|x| config[$1].empty? ? '' : "echo #{config[$1]}"}
})
FileUtils.chmod(0755, t.name)
end
+3 -1
View File
@@ -6,12 +6,14 @@ while [ $# -gt 0 ]; do
--ldflags) echo MRUBY_LDFLAGS;;
--ldflags-before-libs) echo MRUBY_LDFLAGS_BEFORE_LIBS;;
--libs) echo MRUBY_LIBS;;
--libmruby-path) echo MRUBY_LIBMRUBY_PATH;;
--help) echo "Usage: mruby-config [switches]"
echo " switches:"
echo " --cflags print flags passed to compiler"
echo " --ldflags print flags passed to linker"
echo " --ldflags-before-libs print flags passwd to linker before linked libraries"
echo " --ldflags-before-libs print flags passed to linker before linked libraries"
echo " --libs print linked libraries"
echo " --libmruby-path print libmruby path"
exit 0;;
esac
shift
@@ -7,6 +7,7 @@ if "%0" equ "--cflags" goto cflags
if "%0" equ "--ldflags" goto ldflags
if "%0" equ "--ldflags-before-libs" goto ldflagsbeforelibs
if "%0" equ "--libs" goto libs
if "%0" equ "--libmruby-path" goto libmrubypath
if "%0" equ "--help" goto showhelp
echo Invalid Option
goto :eof
@@ -27,10 +28,15 @@ goto top
echo MRUBY_LDFLAGS_BEFORE_LIBS
goto top
:libmrubypath
echo MRUBY_LIBMRUBY_PATH
goto top
:showhelp
echo Usage: mruby-config [switches]
echo switches:
echo --cflags print flags passed to compiler
echo --ldflags print flags passed to linker
echo --ldflags-before-libs print flags passwd to linker before linked libraries
echo --ldflags-before-libs print flags passed to linker before linked libraries
echo --libs print linked libraries
echo --libmruby-path print libmruby path
+16 -2
View File
@@ -2,9 +2,9 @@ require 'tempfile'
assert('regression for #1564') do
o = `#{cmd('mruby')} -e #{shellquote('<<')} 2>&1`
assert_equal o, "-e:1:2: syntax error, unexpected tLSHFT\n"
assert_include o, "-e:1:2: syntax error"
o = `#{cmd('mruby')} -e #{shellquote('<<-')} 2>&1`
assert_equal o, "-e:1:3: syntax error, unexpected tLSHFT\n"
assert_include o, "-e:1:3: syntax error"
end
assert('regression for #1572') do
@@ -44,3 +44,17 @@ EOS
script.flush
assert_equal "\"test\"\n\"fin\"\n", `#{cmd('mruby')} #{script.path}`
end
assert('garbage collecting built-in classes') do
script = Tempfile.new('test.rb')
script.write <<RUBY
NilClass = nil
GC.start
Array.dup
print nil.class.to_s
RUBY
script.flush
assert_equal "NilClass", `#{cmd('mruby')} #{script.path}`
assert_equal 0, $?.exitstatus
end
+5
View File
@@ -4,4 +4,9 @@ MRuby::Gem::Specification.new('mruby-bin-mruby') do |spec|
spec.summary = 'mruby command'
spec.bins = %w(mruby)
spec.add_dependency('mruby-compiler', :core => 'mruby-compiler')
spec.add_dependency('mruby-error', :core => 'mruby-error')
if build.cxx_exception_enabled?
build.compile_as_cxx("#{spec.dir}/tools/mruby/mruby.c", "#{spec.build_dir}/tools/mruby/mruby.cxx")
end
end
+59 -53
View File
@@ -1,11 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/compile.h"
#include "mruby/dump.h"
#include "mruby/variable.h"
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/compile.h>
#include <mruby/dump.h>
#include <mruby/variable.h>
#ifdef MRB_DISABLE_STDIO
static void
@@ -188,59 +188,65 @@ main(int argc, char **argv)
usage(argv[0]);
return n;
}
else {
int ai = mrb_gc_arena_save(mrb);
ARGV = mrb_ary_new_capa(mrb, args.argc);
for (i = 0; i < args.argc; i++) {
char* utf8 = mrb_utf8_from_locale(args.argv[i], -1);
if (utf8) {
mrb_ary_push(mrb, ARGV, mrb_str_new_cstr(mrb, utf8));
mrb_utf8_free(utf8);
}
}
mrb_define_global_const(mrb, "ARGV", ARGV);
ARGV = mrb_ary_new_capa(mrb, args.argc);
for (i = 0; i < args.argc; i++) {
char* utf8 = mrb_utf8_from_locale(args.argv[i], -1);
if (utf8) {
mrb_ary_push(mrb, ARGV, mrb_str_new_cstr(mrb, utf8));
c = mrbc_context_new(mrb);
if (args.verbose)
c->dump_result = TRUE;
if (args.check_syntax)
c->no_exec = TRUE;
/* Set $0 */
zero_sym = mrb_intern_lit(mrb, "$0");
if (args.rfp) {
const char *cmdline;
cmdline = args.cmdline ? args.cmdline : "-";
mrbc_filename(mrb, c, cmdline);
mrb_gv_set(mrb, zero_sym, mrb_str_new_cstr(mrb, cmdline));
}
else {
mrbc_filename(mrb, c, "-e");
mrb_gv_set(mrb, zero_sym, mrb_str_new_lit(mrb, "-e"));
}
/* Load program */
if (args.mrbfile) {
v = mrb_load_irep_file_cxt(mrb, args.rfp, c);
}
else if (args.rfp) {
v = mrb_load_file_cxt(mrb, args.rfp, c);
}
else {
char* utf8 = mrb_utf8_from_locale(args.cmdline, -1);
if (!utf8) abort();
v = mrb_load_string_cxt(mrb, utf8, c);
mrb_utf8_free(utf8);
}
}
mrb_define_global_const(mrb, "ARGV", ARGV);
c = mrbc_context_new(mrb);
if (args.verbose)
c->dump_result = TRUE;
if (args.check_syntax)
c->no_exec = TRUE;
/* Set $0 */
zero_sym = mrb_intern_lit(mrb, "$0");
if (args.rfp) {
const char *cmdline;
cmdline = args.cmdline ? args.cmdline : "-";
mrbc_filename(mrb, c, cmdline);
mrb_gv_set(mrb, zero_sym, mrb_str_new_cstr(mrb, cmdline));
}
else {
mrbc_filename(mrb, c, "-e");
mrb_gv_set(mrb, zero_sym, mrb_str_new_lit(mrb, "-e"));
}
/* Load program */
if (args.mrbfile) {
v = mrb_load_irep_file_cxt(mrb, args.rfp, c);
}
else if (args.rfp) {
v = mrb_load_file_cxt(mrb, args.rfp, c);
}
else {
char* utf8 = mrb_utf8_from_locale(args.cmdline, -1);
if (!utf8) abort();
v = mrb_load_string_cxt(mrb, utf8, c);
mrb_utf8_free(utf8);
}
mrbc_context_free(mrb, c);
if (mrb->exc) {
if (!mrb_undef_p(v)) {
mrb_print_error(mrb);
mrb_gc_arena_restore(mrb, ai);
mrbc_context_free(mrb, c);
if (mrb->exc) {
if (mrb_undef_p(v)) {
mrb_p(mrb, mrb_obj_value(mrb->exc));
}
else {
mrb_print_error(mrb);
}
n = -1;
}
else if (args.check_syntax) {
printf("Syntax OK\n");
}
n = -1;
}
else if (args.check_syntax) {
printf("Syntax OK\n");
}
cleanup(mrb, &args);
@@ -1,9 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mruby.h"
#include "mruby/irep.h"
#include "mruby/dump.h"
#include <mruby.h>
#include <mruby/irep.h>
#include <mruby/dump.h>
struct strip_args {
int argc_start;
@@ -16,7 +16,7 @@ struct strip_args {
static void
irep_remove_lv(mrb_state *mrb, mrb_irep *irep)
{
size_t i;
int i;
if (irep->lv) {
mrb_free(mrb, irep->lv);
+5
View File
@@ -0,0 +1,5 @@
MRuby::Gem::Specification.new('mruby-class-ext') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'class/module extension'
end
+68
View File
@@ -0,0 +1,68 @@
#include "mruby.h"
#include "mruby/class.h"
#include "mruby/string.h"
static mrb_value
mrb_mod_name(mrb_state *mrb, mrb_value self)
{
mrb_value name = mrb_class_path(mrb, mrb_class_ptr(self));
return mrb_nil_p(name)? name : mrb_str_dup(mrb, name);
}
static mrb_value
mrb_mod_singleton_class_p(mrb_state *mrb, mrb_value self)
{
return mrb_bool_value(mrb_type(self) == MRB_TT_SCLASS);
}
/*
* call-seq:
* module_exec(arg...) {|var...| block } -> obj
* class_exec(arg...) {|var...| block } -> obj
*
* Evaluates the given block in the context of the
* class/module. The method defined in the block will belong
* to the receiver. Any arguments passed to the method will be
* passed to the block. This can be used if the block needs to
* access instance variables.
*
* class Thing
* end
* Thing.class_exec{
* def hello() "Hello there!" end
* }
* puts Thing.new.hello()
*/
static mrb_value
mrb_mod_module_exec(mrb_state *mrb, mrb_value self)
{
const mrb_value *argv;
mrb_int argc;
mrb_value blk;
mrb_get_args(mrb, "*&", &argv, &argc, &blk);
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
}
mrb->c->ci->target_class = mrb_class_ptr(self);
return mrb_yield_cont(mrb, blk, self, argc, argv);
}
void
mrb_mruby_class_ext_gem_init(mrb_state *mrb)
{
struct RClass *mod = mrb->module_class;
mrb_define_method(mrb, mod, "name", mrb_mod_name, MRB_ARGS_NONE());
mrb_define_method(mrb, mod, "singleton_class?", mrb_mod_singleton_class_p, MRB_ARGS_NONE());
mrb_define_method(mrb, mod, "module_exec", mrb_mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK());
mrb_define_method(mrb, mod, "class_exec", mrb_mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK());
}
void
mrb_mruby_class_ext_gem_final(mrb_state *mrb)
{
}
+55
View File
@@ -0,0 +1,55 @@
assert 'Module#name' do
module Outer
class Inner; end
const_set :SetInner, Class.new
end
assert_equal 'Outer', Outer.name
assert_equal 'Outer::Inner', Outer::Inner.name
assert_equal 'Outer::SetInner', Outer::SetInner.name
outer = Module.new do
const_set :SetInner, Class.new
end
Object.const_set :SetOuter, outer
assert_equal 'SetOuter', SetOuter.name
assert_equal 'SetOuter::SetInner', SetOuter::SetInner.name
mod = Module.new
cls = Class.new
assert_nil mod.name
assert_nil cls.name
end
assert 'Module#singleton_class?' do
mod = Module.new
cls = Class.new
scl = cls.singleton_class
assert_false mod.singleton_class?
assert_false cls.singleton_class?
assert_true scl.singleton_class?
end
assert 'Module#module_eval' do
mod = Module.new
mod.class_exec(1,2,3) do |a,b,c|
assert_equal([1,2,3], [a,b,c])
def hi
"hi"
end
end
cls = Class.new
cls.class_exec(42) do |x|
assert_equal(42, x)
include mod
def hello
"hello"
end
end
obj = cls.new
assert_equal("hi", obj.hi)
assert_equal("hello", obj.hello)
end
+5
View File
@@ -0,0 +1,5 @@
MRuby::Gem::Specification.new('mruby-compar-ext') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Enumerable module extension'
end
+31
View File
@@ -0,0 +1,31 @@
module Comparable
##
# Returns <i>min</i> if <i>obj</i> <code><=></code> <i>min</i> is less
# than zero, <i>max</i> if <i>obj</i> <code><=></code> <i>max</i> is
# greater than zero and <i>obj</i> otherwise.
#
# 12.clamp(0, 100) #=> 12
# 523.clamp(0, 100) #=> 100
# -3.123.clamp(0, 100) #=> 0
#
# 'd'.clamp('a', 'f') #=> 'd'
# 'z'.clamp('a', 'f') #=> 'f'
#
def clamp(min, max)
if (min <=> max) > 0
raise ArgumentError, "min argument must be smaller than max argument"
end
c = self <=> min
if c == 0
return self
elsif c < 0
return min
end
c = self <=> max
if c > 0
return max
else
return self
end
end
end
+18
View File
@@ -10,3 +10,21 @@ assert('Compiling multiple files without new line in last line. #2361') do
assert_equal "#{cmd('mrbc')}:#{a.path}:Syntax OK", result.chomp
assert_equal 0, $?.exitstatus
end
assert('parsing function with void argument') do
a, out = Tempfile.new('a.rb'), Tempfile.new('out.mrb')
a.write('f ()')
a.flush
result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} 2>&1`
assert_equal "#{cmd('mrbc')}:#{a.path}:Syntax OK", result.chomp
assert_equal 0, $?.exitstatus
end
assert('embedded document with invalid terminator') do
a, out = Tempfile.new('a.rb'), Tempfile.new('out.mrb')
a.write("=begin\n=endx\n")
a.flush
result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} 2>&1`
assert_equal "#{a.path}:3:0: embedded document meets end of file", result.chomp
assert_equal 1, $?.exitstatus
end
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More