Граф коммитов

861 Коммитов

Автор SHA1 Сообщение Дата
nobu 6f7fafbf00 random.c: prefixed fill_random_bytes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11 11:05:20 +00:00
shyouhei c2bfb4e93c add new instruction attribute called leaf
An instruction is leaf if it has no rb_funcall inside.  In order to
check this property, we introduce stack canary which is a random
number collected at runtime.  Stack top is always filled with this
number and checked for stack smashing operations, when VM_CHECK_MODE.
[GH-1947]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11 09:48:58 +00:00
nobu 868ad2104c ruby.h: removed internal macros
* include/ruby/ruby.h (RCOMPLEX_SET_REAL, RCOMPLEX_SET_IMAG): removed
  macros for internal use, which have been exposed by accident.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-04 12:30:34 +00:00
nobu 929e9713bb complex.c: simplify division result
* complex.c (f_divide): canonicalize rationals to simplify integer
  complex results.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-01 07:34:31 +00:00
ko1 1f4efb9aed rest parameter optimization [Feature #15010]
* vm_args.c: rb_ary_dup(args->rest) to be used at most once during
  parameter setup. [Feature #15010]
  A patch by chopraanmol1 (Anmol Chopra) <chopraanmol1@gmail.com>.

* array.c (rb_ary_behead): added to remove first n elements.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-28 07:06:06 +00:00
kazu 84fd997fe6 Avoid compiler depend error
ref r64492

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22 04:04:06 +00:00
normal 7e5423b8e7 internal.h: remove prototype for non-existent rb_divert_reserved_fd
I forgot to remove it 3 years ago in r51576

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-21 00:16:45 +00:00
normal 48b6bd74e2 thread_pthread.c: eliminate timer thread by restructuring GVL
This reverts commit 194a6a2c68 (r64203).

Race conditions which caused the original reversion will be fixed
in the subsequent commit.

[ruby-core:88360] [Misc #14937]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-13 21:34:20 +00:00
k0kubun 2e003f6c87 process.c: don't wait JIT queue flush on rb_f_exec
This wasn't intended in r64253.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09 11:39:07 +00:00
k0kubun 212a77ed46 process.c: fix outdated mjit_pause declaration
by sharing it with vm.c in internal.h.

vm.c: ditto
internal.h: ditto
mjit.h: share more.

mjit.c: make sure the third arguemnt is not used

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09 11:31:41 +00:00
mrkn f15069338d enumerator.c: Introduce Enumerator::ArithmeticSequence
This commit introduces new core class Enumerator::ArithmeticSequence.
Enumerator::ArithmeticSequence is a subclass of Enumerator, and
represents a number generator of an arithmetic sequence.

After this commit, Numeric#step and Range#step without blocks
returned an ArithmeticSequence object instead of an Enumerator.

This class introduces the following incompatibilities:

- You can create a zero-step ArithmeticSequence,
  and its size is not ArgumentError, but Infinity.
- You can create a negative-step ArithmeticSequence from a range.

[ruby-core:82816] [Feature #13904]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-06 09:08:28 +00:00
normal 194a6a2c68 thread_pthread.c: restore timer-thread for now :<
[ruby-core:88306]

Revert "process.c: ensure th->interrupt lock is held when migrating"

This reverts commit 5ca416bdf6 (r64201)

Revert "process.c (rb_waitpid): reduce sigwait_fd bouncing"

This reverts commit 217bdd776f (r64200).

Revert "test/ruby/test_thread.rb (test_thread_timer_and_interrupt): add timeouts"

This reverts commit 9f395f1120 (r64199).

Revert "thread_pthread.c (native_sleep): reduce ppoll sleeps"

This reverts commit b3aa256c4d (r64193).

Revert "thread.c (consume_communication_pipe): do not retry after short read"

This reverts commit 291a82f748 (r64185).

Revert "test/ruby/test_io.rb (test_race_gets_and_close): timeout each thread"

This reverts commit 3dbd8d1f66 (r64184).

Revert "thread_pthread.c (gvl_acquire_common): persist timeout across calls"

This reverts commit 8c2ae6e3ed (r64165).

Revert "test/ruby/test_io.rb (test_race_gets_and_close): use SIGABRT on timeout"

This reverts commit 931cda4db8 (r64135).

Revert "thread_pthread.c (gvl_yield): do ubf wakeups when uncontended"

This reverts commit 508f00314f (r64133).

Revert "thread_pthread.h (native_thread_data): split condvars on some platforms"

This reverts commit a038bf238b (r64124).

Revert "process.c (waitpid_nogvl): prevent conflicting use of sleep_cond"

This reverts commit 7018acc946 (r64117).

Revert "thread_pthread.c (rb_sigwait_sleep): th may be 0 from MJIT"

This reverts commit 56491afc79 (r64116).

Revert "thread*.c: waiting on sigwait_fd performs periodic ubf wakeups"

This reverts commit ab47a57a46 (r64115).

Revert "thread_pthread.c (gvl_destroy): make no-op on GVL bits"

This reverts commit 95cae74817 (r64114).

Revert "thread_pthread.c (rb_sigwait_sleep): fix uninitialized poll set in UBF case"

This reverts commit 4514362948 (r64113).

Revert "thread_pthread.c (rb_sigwait_sleep): re-fix [Bug #5343] harder"

This reverts commit 26b8a70bb3 (r64111).

Revert "thread.c: move ppoll wrapper into thread_pthread.c"

This reverts commit 3dc7727d22 (r64110).

Revert "thread.c: move ppoll wrapper before thread_pthread.c"

This reverts commit 2fa1e2e3c3 (r64109).

Revert "thread_pthread.c (ubf_select): refix [Bug #5343]"

This reverts commit 4c1ab82f06 (r64108).

Revert "thread_win32.c: suppress warnings by -Wsuggest-attribute"

This reverts commit 6a9b63e390 (r64159).

Revert "thread_pthread: remove timer-thread by restructuring GVL"

This reverts commit 708bfd2115 (r64107).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-06 05:22:00 +00:00
shyouhei 2dd0fb21bf fix typo(#2), sorry!
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-30 08:22:50 +00:00
shyouhei dc4e6a8ab2 fix typo; sorry!
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-30 08:21:01 +00:00
shyouhei d83536c980 reduce copy & paste
We see several occurrence of "diagnostic push/pop" so why not
make them macros.  Tested on GCC8 / Clang 6.

Note that ruby.h is intentionally left untouched because we don't
want to introduce new public macros.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-30 07:07:48 +00:00
normal 708bfd2115 thread_pthread: remove timer-thread by restructuring GVL
To reduce resource use and reduce CI failure; remove
timer-thread.  Single-threaded Ruby processes (including forked
children) will never see extra thread overhead.  This prevents
glibc and jemalloc from going into multi-threaded mode and
initializing locks or causing fragmentation via arena explosion.

The GVL is implements its own wait-queue as a ccan/list to
permit controlling wakeup order.  Timeslice under contention is
handled by a designated timer thread (similar to choosing a
"patrol_thread" for current deadlock checking).

There is only one self-pipe, now, as wakeups for timeslice are
done independently using condition variables.  This reduces FD
pressure slightly.

Signal handling is handled directly by a Ruby Thread (instead
of timer-thread) by exposing signal self-pipe to callers of
rb_thread_fd_select, native_sleep, rb_wait_for_single_fd, etc...
Acquiring, using, and releasing the self-pipe is exposed via 4
new internal functions:

1) rb_sigwait_fd_get - exclusively acquire timer_thread_pipe.normal[0]

2) rb_sigwait_fd_sleep - sleep and wait for signal (and no other FDs)

3) rb_sigwait_fd_put - release acquired result from rb_sigwait_fd_get

4) rb_sigwait_fd_migrate - migrate signal handling to another thread
                           after calling rb_sigwait_fd_put.

rb_sigwait_fd_migrate is necessary for waitpid callers because
only one thread can wait on self-pipe at a time, otherwise a
deadlock will occur if threads fight over the self-pipe.

TRAP_INTERRUPT_MASK is now set for the main thread directly in
signal handler via rb_thread_wakeup_timer_thread.

Originally, I wanted to use POSIX timers
(timer_create/timer_settime) for this.  Unfortunately, this
proved unfeasible as Mutex#sleep resumes on spurious wakeups and
test/thread/test_cv.rb::test_condvar_timed_wait failed.  Using
pthread_sigmask to mask out SIGVTALRM fixed that test,  but
test/fiddle/test_function.rb::test_nogvl_poll proved there'd be
some unavoidable (and frequent) incompatibilities from that
approach.

Finally, this allows us to drop thread_destruct_lock and
interrupt current ec directly.

We don't need to rely on vm->thread_destruct_lock or a coherent
vm->running_thread on any platform.  Separate timer-thread for
time slice and signal handling is relegated to thread_win32.c,
now.

[ruby-core:88088] [Misc #14937]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-29 20:47:33 +00:00
mame ffb09d8e87 eval.c: rename "rb_frozen_class_p" to "rb_class_modify_check"
Just refactoring.  Despite its name, the function does NOT return a
boolean but raises an exception when the class given is frozen.
I don't think the new name "rb_class_modify_check" is the best, but
it follows the precedeint "rb_ary_modify_check", and is definitely
better than "*_p".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-27 13:57:14 +00:00
normal b93dc84883 signal.c: preserve trap(:CHLD, "IGNORE") behavior with SIGCHLD
We need to preserve "IGNORE" behavior from Ruby 2.5 and earlier.
We can't rely on SA_NOCLDWAIT any more, since we always need
system() and MJIT to work; so we fake that behavior using
dedicated reaper (currently in timer-thread).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-08 00:02:27 +00:00
nobu 33354d2928 Prefixed reset_leap_second_info
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-06 01:40:04 +00:00
naruse 6538f67d4d Re-apply r63848 (Optimize Time.utc)
* Both timegmw and gmtimew ignores leap second if the timezone doesn't
  have leap seconds on the first call of init_leap_second_info()
* Add Bug::Time.reset_leap_second_info for testing

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-05 11:43:42 +00:00
normal 44fc3d08eb unrevert r63852 but keep SIGCHLD path disabled for win32
Reading win32/win32.c waitpid implementation, maybe waitpid(-1, ...)
on that platform will never conflict with mjit use of waitpid.

In any case, I've added WAITPID_USE_SIGCHLD macro to vm_core.h
so it can be easy for Linux/BSD users to test (hopefully!)
win32-compatible code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-05 03:02:33 +00:00
naruse df4a126d65 Revert r63758 and related commits
The change is unstable on Windows. Please re-commit it when it correctly
supports Windows.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04 15:08:56 +00:00
normal 4b20479f93 internal.h (rb_warning_string): use PRINTF_ARGS
Let compilers do a little extra validation for us

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04 01:26:36 +00:00
normal 054a412d54 hijack SIGCHLD handler for internal use
Use a global SIGCHLD handler to guard all callers of rb_waitpid.
To work safely with multi-threaded programs, we introduce a
VM-wide waitpid_lock to be acquired BEFORE fork/vfork spawns the
process.  This is to be combined with the new ruby_waitpid_locked
function used by mjit.c in a non-Ruby thread.

Ruby-level SIGCHLD handlers registered with Signal.trap(:CHLD)
continues to work as before and there should be no regressions
in any existing use cases.

Splitting the wait queues for PID > 0 and groups (PID <= 0)
ensures we favor PID > 0 callers.

The disabling of SIGCHLD in rb_f_system is longer necessary,
as we use deferred signal handling and no longer make ANY
blocking waitpid syscalls in other threads which could "beat"
the waitpid call made by rb_f_system.

We prevent SIGCHLD from firing in normal Ruby Threads and only
enable it in the timer-thread, to prevent spurious wakeups
from in test/-ext-/gvl/test_last_thread.rb with MJIT enabled.

I've tried to guard as much of the code for RUBY_SIGCHLD==0
using C "if" statements rather than CPP "#if" so to reduce
the likelyhood of portability problems as the compiler will
see more code.

We also work to suppress false-positives from
Process.wait(-1, Process::WNOHANG) to quiets warnings from
spec/ruby/core/process/wait2_spec.rb with MJIT enabled.

Lastly, we must implement rb_grantpt for ext/pty.  We need a
MJIT-compatible way of supporting grantpt(3) which may spawn
the `pt_chown' binary and call waitpid(2) on it.

[ruby-core:87605] [Ruby trunk Bug#14867]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27 03:14:30 +00:00
shyouhei 22444ae9b1 move function declarations from insns.def to internal.h
Just avoid being loose.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63755 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27 00:57:16 +00:00
nobu 4fedad85ef refine Integer#** and Float#**
* complex.c (rb_dbl_complex_polar): utility function, which
  returns more precise value in right angle cases.

* bignum.c (rb_big_pow): use rb_dbl_complex_polar().

* numeric.c (rb_float_pow, fix_pow): create a Complex by polar
  form.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-17 02:37:32 +00:00
nobu c9db11ea60 bignum.c: get rid of redefined method
* bignum.c (int_pow_tmp3): get rid of redefined Integer#> on
  internal calculations, as well as the GMP version.

* bignum.c (rb_int_powm): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-14 07:09:02 +00:00
normal 4e730838a0 encoding.c: remove rb_gc_mark_encodings
rb_gc_mark_encodings has been empty for a decade
(since r17875 / 28b216ac45).
Just remove it and its only caller in gc.c

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-05 22:01:43 +00:00
normal b32b2a6106 internal.h: export ruby_sized_* for systems w/o malloc_usable_size
[ruby-core:87232]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-23 05:51:43 +00:00
naruse bcdf08dd83 export rb_hash_bulk_insert
msgpack-ruby requests this function public because they want to
create a hash with bulk key value pairs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-22 07:31:36 +00:00
shyouhei 4f3c4c7d6d RSTRING_PTR is not guaranteed to be char*-aligned
This commit eliminates (char **)RSTRING_PTR(...) like usages.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-14 03:30:03 +00:00
mame e9303e1a00 Rename imemo_alloc with imemo_tmpbuf
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09 07:11:59 +00:00
mame af0696782d gc.c (rb_imemo_alloc_new): split for each purpose
imemo_alloc is used for three purposes: auto-free pointer (alternative
of alloca), alloc_tmp_buffer, and heap allocation for bison.
To make it clear, this change introduces three functions:
rb_imemo_alloc_auto_free_pointer,
rb_imemo_alloc_auto_free_maybe_mark_buffer, and
rb_imemo_alloc_parser_heap.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09 07:08:53 +00:00
mame 58823392b4 gc.c (rb_imemo_alloc_new): improve the API interface
rb_imemo_alloc_new returns rb_imemo_alloc_t*, but took VALUEs, which is
inconsistent.  To make the intention clear, it now takes only a pointer
to the buffer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09 06:12:17 +00:00
shyouhei b121cfde5f nobody is using the return value of rb_io_fptr_finalize
However this function is listed in ruby/io.h.  We cannot but
define a new, void-returning variant to use instead.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-04 15:03:37 +00:00
nobu 703a5dd3e0 string.c: adjust to rb_str_upto_each
* range.c (range_each_func): adjust the signature of the callback
  function to rb_str_upto_each, and exit the loop if the callback
  returned non-zero.

* string.c (rb_str_upto_endless_each): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-28 11:16:54 +00:00
normal 475b4aa40b simplify altstack and enable reuse with thread cache
Instead of allocating and registering the altstack in different
places, do it together to reduce code and improve readability.
When thread cache is enabled, storing altstack in rb_thread_t
is wasteful and we may reuse altstack in the same pthread.

This also lets us clearly allow use of xmalloc to allow GC to
recover from ENOMEM.

[ruby-core:85621] [Feature #14487]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-20 21:38:27 +00:00
k0kubun 46697c7e26 internal.h: use the same declaration as definition
range.c: cast the function type to meet the declaration

This change is for fixing build error on AppVeyor:
https://ci.appveyor.com/project/ruby/ruby/build/1.0.8177

string.c
../string.c(4330) : error C4028: formal parameter 2 different from declaration

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 16:19:48 +00:00
mame 7f95eed19e Introduce endless range [Feature#12912]
Typical usages:
```
p ary[1..]          # drop the first element; identical to ary[1..-1]
(1..).each {|n|...} # iterate forever from 1; identical to 1.step{...}
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 15:18:50 +00:00
nobu a72581d70f error.c: super in method_missing
* error.c (nometh_err_initialize): do not shirtcut rb_call_super,
  to push proper control frame.  [ruby-dev:50522] [Bug #14670]

* error.c (rb_nomethod_err_new): allocate and initialize a new
  NoMethodError instance.

* vm_eval.c (rb_make_no_method_exception): create a new exception
  instance directly without method calls, to prevent influence of
  ruby level method definitions, which can cause an unpredictable
  behavior, e.g., infinite recursion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-12 03:48:48 +00:00
mrkn 2cfc5b03da Add `exception:` keyword in Kernel#Integer()
Support `exception:` keyword argument in Kernel#Integer().
If `exception:` is `false`, `Kernel#Integer()` returns `nil` if the given
value cannot be interpreted as an integer value.
The default value of `exception:` is `true`.
This is part of [Feature #12732].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15 07:19:43 +00:00
nobu 0f0c32f24e mjit.c: no va_copy
* mjit.c (form_args): do not use va_copy, which cannot detect
  appropriate way to simulate when cross compiling.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18 05:10:52 +00:00
k0kubun 1fd816803b vm_insnhelper.c: inline array aref with integer
internal.h: define inlinable rb_ary_entry_internal.

array.c: use rb_ary_entry_internal.

* Benchmark
ruby --jit mame/optcarrot/bin/optcarrot --benchmark mame/optcarrot/examples/Lan_Master.nes

** Before

checksum: 59662
fps: 58.095175012159686

** After

fps: 59.874751599221526
checksum: 59662

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-12 15:25:58 +00:00
nobu 2b79ab512c _mjit_compile_send.erb: PRI_SERIALT_PREFIX
* tool/ruby_vm/views/_mjit_compile_send.erb: `printf` modifier for
  `rb_serial_t` which may not be `long long`, and '%ll' may not be
  supported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-11 00:19:03 +00:00
nobu ec0a0da84a internal.h: moved ruby_null_device declaration
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 08:09:49 +00:00
usa 714836c152 remove declaration of ruby_engine from internal.h
* internal.h (ruby_engine): remove declaration of ruby_engine because
	  it's declared at ruby/version.h.

	* ruby.c: include ruby/version.h for ruby_engine.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-07 04:04:33 +00:00
shyouhei 779c18bf23 va_copy is a C99ism
Should provide appropriate fallback implementation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-05 04:07:25 +00:00
k0kubun ed935aa5be mjit_compile.c: merge initial JIT compiler
which has been developed by Takashi Kokubun <takashikkbn@gmail> as
YARV-MJIT. Many of its bugs are fixed by wanabe <s.wanabe@gmail.com>.

This JIT compiler is designed to be a safe migration path to introduce
JIT compiler to MRI. So this commit does not include any bytecode
changes or dynamic instruction modifications, which are done in original
MJIT.

This commit even strips off some aggressive optimizations from
YARV-MJIT, and thus it's slower than YARV-MJIT too. But it's still
fairly faster than Ruby 2.5 in some benchmarks (attached below).

Note that this JIT compiler passes `make test`, `make test-all`, `make
test-spec` without JIT, and even with JIT. Not only it's perfectly safe
with JIT disabled because it does not replace VM instructions unlike
MJIT, but also with JIT enabled it stably runs Ruby applications
including Rails applications.

I'm expecting this version as just "initial" JIT compiler. I have many
optimization ideas which are skipped for initial merging, and you may
easily replace this JIT compiler with a faster one by just replacing
mjit_compile.c. `mjit_compile` interface is designed for the purpose.

common.mk: update dependencies for mjit_compile.c.

internal.h: declare `rb_vm_insn_addr2insn` for MJIT.

vm.c: exclude some definitions if `-DMJIT_HEADER` is provided to
compiler. This avoids to include some functions which take a long time
to compile, e.g. vm_exec_core. Some of the purpose is achieved in
transform_mjit_header.rb (see `IGNORED_FUNCTIONS`) but others are
manually resolved for now. Load mjit_helper.h for MJIT header.
mjit_helper.h: New. This is a file used only by JIT-ed code. I'll
refactor `mjit_call_cfunc` later.
vm_eval.c: add some #ifdef switches to skip compiling some functions
like Init_vm_eval.

win32/mkexports.rb: export thread/ec functions, which are used by MJIT.

include/ruby/defines.h: add MJIT_FUNC_EXPORTED macro alis to clarify
that a function is exported only for MJIT.

array.c: export a function used by MJIT.
bignum.c: ditto.
class.c: ditto.
compile.c: ditto.
error.c: ditto.
gc.c: ditto.
hash.c: ditto.
iseq.c: ditto.
numeric.c: ditto.
object.c: ditto.
proc.c: ditto.
re.c: ditto.
st.c: ditto.
string.c: ditto.
thread.c: ditto.
variable.c: ditto.
vm_backtrace.c: ditto.
vm_insnhelper.c: ditto.
vm_method.c: ditto.

I would like to improve maintainability of function exports, but I
believe this way is acceptable as initial merging if we clarify the
new exports are for MJIT (so that we can use them as TODO list to fix)
and add unit tests to detect unresolved symbols.
I'll add unit tests of JIT compilations in succeeding commits.

Author: Takashi Kokubun <takashikkbn@gmail.com>
Contributor: wanabe <s.wanabe@gmail.com>

Part of [Feature #14235]

---

* Known issues
  * Code generated by gcc is faster than clang. The benchmark may be worse
    in macOS. Following benchmark result is provided by gcc w/ Linux.
  * Performance is decreased when Google Chrome is running
  * JIT can work on MinGW, but it doesn't improve performance at least
    in short running benchmark.
  * Currently it doesn't perform well with Rails. We'll try to fix this
    before release.

---

* Benchmark reslts

Benchmarked with:
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores

- 2.0.0-p0: Ruby 2.0.0-p0
- r62186: Ruby trunk (early 2.6.0), before MJIT changes
- JIT off: On this commit, but without `--jit` option
- JIT on: On this commit, and with `--jit` option

** Optcarrot fps

Benchmark: https://github.com/mame/optcarrot

|         |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:--------|:--------|:--------|:--------|:--------|
|fps      |37.32    |51.46    |51.31    |58.88    |
|vs 2.0.0 |1.00x    |1.38x    |1.37x    |1.58x    |

** MJIT benchmarks

Benchmark: https://github.com/benchmark-driver/mjit-benchmarks
(Original: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch/MJIT-benchmarks)

|           |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:----------|:--------|:--------|:--------|:--------|
|aread      |1.00     |1.09     |1.07     |2.19     |
|aref       |1.00     |1.13     |1.11     |2.22     |
|aset       |1.00     |1.50     |1.45     |2.64     |
|awrite     |1.00     |1.17     |1.13     |2.20     |
|call       |1.00     |1.29     |1.26     |2.02     |
|const2     |1.00     |1.10     |1.10     |2.19     |
|const      |1.00     |1.11     |1.10     |2.19     |
|fannk      |1.00     |1.04     |1.02     |1.00     |
|fib        |1.00     |1.32     |1.31     |1.84     |
|ivread     |1.00     |1.13     |1.12     |2.43     |
|ivwrite    |1.00     |1.23     |1.21     |2.40     |
|mandelbrot |1.00     |1.13     |1.16     |1.28     |
|meteor     |1.00     |2.97     |2.92     |3.17     |
|nbody      |1.00     |1.17     |1.15     |1.49     |
|nest-ntimes|1.00     |1.22     |1.20     |1.39     |
|nest-while |1.00     |1.10     |1.10     |1.37     |
|norm       |1.00     |1.18     |1.16     |1.24     |
|nsvb       |1.00     |1.16     |1.16     |1.17     |
|red-black  |1.00     |1.02     |0.99     |1.12     |
|sieve      |1.00     |1.30     |1.28     |1.62     |
|trees      |1.00     |1.14     |1.13     |1.19     |
|while      |1.00     |1.12     |1.11     |2.41     |

** Discourse's script/bench.rb

Benchmark: https://github.com/discourse/discourse/blob/v1.8.7/script/bench.rb

NOTE: Rails performance was somehow a little degraded with JIT for now.
We should fix this.
(At least I know opt_aref is performing badly in JIT and I have an idea
 to fix it. Please wait for the fix.)

*** JIT off
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 17
  75: 18
  90: 22
  99: 29
home_admin:
  50: 21
  75: 21
  90: 27
  99: 40
topic_admin:
  50: 17
  75: 18
  90: 22
  99: 32
categories:
  50: 35
  75: 41
  90: 43
  99: 77
home:
  50: 39
  75: 46
  90: 49
  99: 95
topic:
  50: 46
  75: 52
  90: 56
  99: 101

*** JIT on
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 19
  75: 21
  90: 25
  99: 33
home_admin:
  50: 24
  75: 26
  90: 30
  99: 35
topic_admin:
  50: 19
  75: 20
  90: 25
  99: 30
categories:
  50: 40
  75: 44
  90: 48
  99: 76
home:
  50: 42
  75: 48
  90: 51
  99: 89
topic:
  50: 49
  75: 55
  90: 58
  99: 99

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 11:22:28 +00:00
nobu 4c577c4a45 backward.h: rb_mod_const_missing is internal function
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02 16:02:03 +00:00
normal 46bfa65fcc internal.h: add BITFIELD macro to aid C99 users
I plan to use this macro to pack other enums in the VM.

* internal.h: add BITFIELD macro
* method.h: use BITFIELD for rb_method_visibility_t
  [ruby-core:85074] [Misc #14395]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-27 21:04:42 +00:00
nobu d0fa578cdc array.c: rb_check_to_array
* array.c (rb_check_to_array): conversion to array by to_a method.
  returns nil if not possible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-27 09:27:47 +00:00
k0kubun fb29cffab0 process.c: add :exception option to Kernel.#system
to raise error when it fails.

[Feature 14386] [GH-1795]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-24 14:11:25 +00:00
shyouhei 449cceb8b1 merge extern declarations into internal.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 09:44:36 +00:00
yui-knk 0f3dcbdf38 Add tests for Node code locations
* test/-ext-/ast/test_ast.rb: Add tests for Node
  code locations. This file tests

  1. There are no Node whose code location is default
     value (#test_not_cared)

  2. There are no Node whose children's code locations
     exceed parent's code location (#test_ranges)

* ext/-test-/ast/ast.c, ext/-test-/ast/extconf.rb:
  Define AST module to help tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-15 23:43:17 +00:00
mame 7da7716159 internal.h (FLEX_ARY_LEN): Add a macro to define a flexible array
Also, use it in iseq.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-13 11:45:25 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
nobu ee85a6e72b internal.h: remove dependecy on ruby/io.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:10 +00:00
k0kubun 26df9588d6 marshal.c: allow marshalling keyword_init struct
struct.c: define rb_struct_s_keyword_init to shared with marshal.c

internal.h: add the declaration to be used by marshal.c

test/ruby/test_marshal.rb: add test for Bug#14314

[Feature #14314] [ruby-core:84629]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 11:44:31 +00:00
shyouhei a6b50f379d statement experssion is a GCCism
should mark as such.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:53 +00:00
shyouhei 8ebe5da2b3 _Static_assert is a C11ism
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:51 +00:00
shyouhei 91715ee53b long long is a C99ism
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:47 +00:00
shyouhei 67b547d06a __VA_ARGS__ is a C99ism
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:45 +00:00
shyouhei ef19834ed9 long long is a C99sim
Don't assume 8-bytes integers == "long long".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:44 +00:00
ngoto 2adf281593 bit fields treating negative values should be declared as signed int
* internal.h (struct vm_ifunc_argc): Bit fields are unsigned by default.
  For storing nagative values to bit fields, they must be declated as
  signed int. Fix multiple test failure observed by 32-bit binaries
  compiled with Oracle Developer Studio (Solaris Studio) 12.x on
  Solaris 10 on sparc architecture. [Bug #14260]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-30 16:38:22 +00:00
normal fc939f6697 hash literal deduplicates like Hash#[]=
From: Eric Wong <e@80x24.org>

* hash.c (rb_hash_key_str): new function
  (hash_aset_str): use rb_hash_key_str
* internal.h: add rb_hash_key_str
* st.c (st_stringify): use rb_hash_key_str
* test/ruby/test_hash.rb (test_NEWHASH_fstring_key): dynamic key
  [ruby-core:84554] [Feature #14258]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-30 00:00:23 +00:00
naruse 027b576b31 suppress warning: 'const' attribute on function returning 'void'
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-18 09:03:59 +00:00
k0kubun f5090e2f5c iseq.c: dump type of branchiftype on disasm
This makes easier to debug scripts related to r59950.

* before

$ ./ruby --dump=insns -e '"#{a}"'
== disasm: #<ISeq:<main>@-e>============================================
0000 putobject        ""                                              (   1)[Li]
0002 putself
0003 opt_send_without_block <callinfo!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0006 dup
0007 branchiftype     5, 15
0010 dup
0011 opt_send_without_block <callinfo!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>, <callcache>
0014 tostring
0015 concatstrings    2
0017 leave

* after

$ ./ruby --dump=insns -e '"#{a}"'
== disasm: #<ISeq:<main>@-e>============================================
0000 putobject        ""                                              (   1)[Li]
0002 putself
0003 opt_send_without_block <callinfo!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0006 dup
0007 branchiftype     T_STRING, 15
0010 dup
0011 opt_send_without_block <callinfo!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>, <callcache>
0014 tostring
0015 concatstrings    2
0017 leave

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-13 16:07:52 +00:00
mame 0a6816ecd7 Revamp method coverage to support define_method
Traditionally, method coverage measurement was implemented by inserting
`trace2` instruction to the head of method iseq.  So, it just measured
methods defined by `def` keyword.

This commit drastically changes the measuring mechanism of method
coverage; at `RUBY_EVENT_CALL`, it keeps a hash from rb_method_entry_t*
to runs (i.e., it counts the runs per method entry), and at
`Coverage.result`, it creates the result hash by enumerating all
`rb_method_entry_t*` objects (by `ObjectSpace.each_object`).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-05 07:16:42 +00:00
mrkn 9b09cc8a37 bignum.c, numeric.c: add Integer#pow(b, m)
This commit is based on the pull-request #1320 created by Makoto Kishimoto.
[Feature #12508] [Feature #11003] [close GH-1320]

* bignum.c (rb_int_powm): Added for Integer#pow(b, m).

* internal.h (rb_int_powm): Declared to refer in numeric.c.

* bignum.c (bary_powm_gmp): Added for Integer#pow(b, m) using GMP.

* bignum.c (int_pow_tmp1): Added for implementing Integer#pow(b, m).

* bignum.c (int_pow_tmp2, int_pow_tmp3): ditto.

* internal.h (rb_num_positive_int_p): Moved from numeric.c for sharing
  the definition with bignum.c.

* internal.h (rb_num_negative_int_p, rb_num_compare_with_zero): ditto.

* numeric.c(negative_int_p): Moved to internal.h for sharing the
  definition with bignum.c.

* numeric.c (positive_int_p, compare_with_zero): ditto.

* numeric.c (rb_int_odd_p): Exported (renamed from int_odd_p).

* internal.h (rb_int_odd_p): ditto.

* internal.h (HALF_LONG_MSB): Added.

* numeric.c (SQRT_LONG_MAX): Redefined by using HALF_LONG_MSB.

* test/ruby/test_numeric.rb (test_pow): Added for Integer#pow(b, m).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04 02:35:40 +00:00
ko1 360b78e4dc `rb_source_loc` -> `rb_source_location_cstr`
* vm.c (rb_source_loc): rename to rb_source_location_cstr()
  to make behavior clear compare with rb_source_location().

* error.c (warning_string): use rb_source_location_cstr() directly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 05:52:19 +00:00
ko1 b3cab0dc74 remove an unused function.
* vm.c (rb_sourcefilename): removed because nobody use it.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 05:18:29 +00:00
mame 1aa34afd41 Rename imemo_strterm to imemo_parser_strterm
Per ko1's request.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 10:56:50 +00:00
mame 12697c0867 Revert "Revert "Replace NODE_STRTERM and NODE_HEREDOC with imemo_strterm""
Retry r60634

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 07:21:36 +00:00
mame 96eefc0f44 Revert "Replace NODE_STRTERM and NODE_HEREDOC with imemo_strterm"
Due to build failure on mswin and mingw.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 04:59:19 +00:00
mame c1de9fc5ef Replace NODE_STRTERM and NODE_HEREDOC with imemo_strterm
Just refactoring.

NODE_STRTERM and NODE_HEREDOC are not an internal node of AST, but a
temporary storage for managing termination of string literals and
heredocs.  Instead of NODE abuse, I want to use imemo for the storage
in order to avoid (my) confusion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 03:04:54 +00:00
mame e35fe8d11b Revert "Revert "Manage AST NODEs out of GC""
This re-introduces r60485.
This reverts commit 5a176b75b1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 16:44:57 +00:00
mame 5a176b75b1 Revert "Manage AST NODEs out of GC"
This reverts commit 620ba74778.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 16:02:34 +00:00
mame 620ba74778 Manage AST NODEs out of GC
NODEs in AST are no longer objects managed by GC.  This change will
remove the restriction imposed by the GC.  For example, a NODE can use
more than five words (this is my primary purpose; we want to store the
position data for each NODE, for coverage library), or even a NODE can
have variable length (some kinds of NODEs have unused fields).
To do this, however, we need more work, since Ripper still uses T_NODE
objects managed by the GC.

The life time of NODEs is more obvious than other kinds of objects; they
are created at parsing, and they become disused immediately after
compilation.  This change releases all NODEs by a few `xfree`s after
compilation, so performance will be improved a bit.  In extreme example,
`eval("x=1;" * 10000000)` runs much faster (40 sec. -> 7.8 sec. on my
machine).

The most important part of this change is `ast_t` struct, which has
three contents: (1) NODE buffer (malloc'ed memory), (2) a reference to
the root NODE, and (3) an array that contains objects that must be
marked during parsing (such as literal objects).  Some functions that
had received `NODE*` arguments, must now receive `ast_t*`.

* node.c, node.h: defines `ast_t` struct and related operations.
* gc.c, internal.h: defines `imemo_ast`.
* parse.y: makes `parser_params` struct have a reference to `ast_t`.
  Instead of `rb_node_newnode`, use `rb_ast_newnode` to create a NODE.
* iseq.c, load.c, ruby.c, template/prelude.c.tmpl: modifies some
  functions to handle `ast_t*` instead of `NODE*`.
* test/ruby/test_gc.rb: ad-hoc fix for a failed test.  The test assumes
  GC eden is increased at startup by NODE object creation.  However,
  this change now create no NODE object, so GC eden is not necessarily
  increased.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 15:59:02 +00:00
ko1 837fd5e494 Use rb_execution_context_t instead of rb_thread_t
to represent execution context [Feature #14038]

* vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer.
  There are many code using `th` to represent execution context
  (such as cfp, VM stack and so on). To access `ec`, they need to
  use `th->ec->...` (adding one indirection) so that we need to
  replace them by passing `ec` instead of `th`.

* vm_core.h (GET_EC()): introduced to access current ec. Also
  remove `ruby_current_thread` global variable.

* cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of
  rb_context_t::thread_value.

* cont.c (ec_set_vm_stack): added to update vm_stack explicitly.

* cont.c (ec_switch): added to switch ec explicitly.

* cont.c (rb_fiber_close): added to terminate fibers explicitly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 08:32:49 +00:00
nobu 6b818dd961 common conversion functions
* array.c (rb_to_array_type): make public to share common code
  internally.

* hash.c (rb_to_hash_type): make public to share common code
  internally.

* symbol.c (rb_to_symbol_type): make public to share common code
  internally.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 07:23:23 +00:00
mame 09ea07e02c Refactoring by adding `rb_imemo_alloc_new` to create imemo_alloc buffer
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25 13:38:53 +00:00
nobu e480660b85 vm_insnhelper.c: array aref optimization
* vm_insnhelper.c (vm_opt_aref): optimize on other than fixnum
  argument too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 00:19:12 +00:00
sonots 47dd9bf7d8 Add doxygen comments
* include/ruby/ruby.h (enum ruby_value_type): add doxygen comments
* internal.h (enum imemo_type, struct vm_svar): add doxygen comments
* method.h (rb_method_type_t, rb_method_iseq_t): add doxygen comments

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 14:31:21 +00:00
tarui a2d6b37f0c fix comment abount IMEMO_FL_USHIFT
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 10:26:31 +00:00
ko1 2ab99609e0 imemo_mask (enum) -> IMEMO_MASK (immediate value).
* internal.h: imemo_mask is not a valid imemo type but
  switch statements show warnings.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 10:21:31 +00:00
nobu 719531dba5 fix up imemo_alloc
* internal.h (rb_imemo_alloc_struct), gc.c (gc_mark_imemo): turned
  next into the pointer to chain.

* parse.y (NEWHEAP): needs a cast.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 09:10:42 +00:00
mame ccfe37884a Replace NODE_ALLOCA with T_IMEMO (imemo_alloc)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 08:40:28 +00:00
naruse 6187b0001b [Feature #13712] String#start_with? supports regexp
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 06:51:01 +00:00
glass f5740d18bf Revert "vm_eval.c: add rb_yield_assoc_or_values()"
This reverts commit r60095 to prevent performance degradation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02 07:51:27 +00:00
glass 7ae65b24c2 vm_eval.c: add rb_yield_assoc_or_values()
The new function rb_yield_assoc_or_values() will reduce branching.

* vm_eval.c: add rb_yield_assoc_or_values()

* internal.h: ditto

* hash.c: use rb_yield_assoc_or_values()

* struct.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02 05:29:11 +00:00
glass c879b60152 hash.c: remove special treatments on deletion
st.c was improved in r56650 that it permits deletion during iteration.
In this commit, special treatments for previous implementation are
removed.

* hash.c: don't use *_check and *_safe functions in st.c

* internal.h: remove HASH_DELETED flag

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-30 11:58:33 +00:00
naruse c04b6232f8 Fix overflow detection for LLP64 arch [Bug #13748]
FIXNUMs are expected to fit into a long type, but the test is about a
VALUE type. Since long is < than VALUE on LLP64, the overflow is not
detected. As a result "2**31" evaluates to "-2147483648" on Windows with
gcc-7.1.0.
patched by Lars Kanis <lars@greiz-reinsdorf.de>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-25 08:19:10 +00:00
nobu 5754f15975 file.c: rb_check_realpath
* file.c (rb_check_realpath): returns real path which has no
  symbolic links.  similar to rb_realpath except for returning
  Qnil if any parts did not exist.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-21 07:29:16 +00:00
nobu 13f5dcb9f2 error.c: KeyError#receiver and KeyError#key
* error.c: new method KeyError#receiver and KeyError#key.
  [Feature #12063]

* hash.c: make KeyError object with receiver and key.

* sprintf.c: ditto.

Author:    ksss <co000ri@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-18 08:05:53 +00:00
ko1 b53b37758d store ec instead of thread in rb_context_t.
* cont.c (rb_context_t): introduce saved_ec instaad of saved_thread.
  We only need to transfer ec data (not all of thread data).

  Introduce `thread_value` field to point creation thread.
  To acccess this field, `cont_thread_value()` is introduced.

* vm.c (rb_execution_context_mark): remove `static` and use it
  from cont.c (use this function instead of `rb_thread_mark`).

* vm_insnhelper.c (rb_vm_push_frame): accept ec instead of th.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-10 19:00:08 +00:00
nobu 65b87de350 ruby.h: unnormalized Fixnum value
* include/ruby/ruby.h (ST2FIX): fix unnormalized Fixnum value bug
  on mingw/mswin.  [ruby-core:82687] [Bug #13877]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-07 03:24:08 +00:00
shyouhei 0eb7359cc7 add rb_hash_new_with_size()
Sometimes, size of a hash can be calcluated a priori.  By providing
such info to the constructor we can avoid unnecessary internal re-
allocations.  This can boost for instance creation of hash literals.
[Bug #13861]

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-05 04:48:19 +00:00
mame cd6df5fb3c Refactor the internal data format for coverage measurement
To prepare new measuring targets: branch and method coverages.
So far, iseq->coverage was an array of counts executed for line coverage.
Now, it is a three-element array for each measuring target,
whose first element is an array for line coverage.
The second element is planned for branch coverage, and the third will be
for method coverage.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-03 14:26:06 +00:00
ko1 43384ae978 Fiber#to_s (#inspect) return richer information.
* cont.c (fiber_to_s): return with block and status information.

* proc.c (proc_to_s_): removed and introduce rb_block_to_s() function
  to return block information string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10 02:58:36 +00:00
nobu 8458e709ab string.c: rb_str_initialize
* string.c (rb_str_initialize): new function to (re)initialize a
  string with data and encoding.  extracted from
  rb_external_str_new_with_enc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-30 02:56:29 +00:00
normal 0493b1ce3a revert r59359, r59356, r59355, r59354
These caused numerous CI failures I haven't been able to
reproduce [ruby-core:82102]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-19 01:35:04 +00:00
nobu 1f67a3900f vm_eval.c: rb_lambda_call
* enum.c (enum_collect): make the block arity same as the given
  block.  [Bug #13391]

* internal.h (vm_ifunc): store arity instead of unused id.

* proc.c (rb_vm_block_min_max_arity): return ifunc arity.

* vm_eval.c (rb_lambda_call): call method with lambda block.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-18 08:31:02 +00:00
nobu 8ffb23c2e1 proc.c: rb_block_min_max_arity
* proc.c (rb_block_min_max_arity): new function to get arity range
  from the current block.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-18 07:48:37 +00:00
normal d04c085b3c hash: keep fstrings of tainted strings for string keys
The same hash keys may be loaded from tainted data sources
frequently (e.g. parsing headers from socket or loading
YAML data from a file).  If a non-tainted fstring already
exists (because the application expects the hash key),
cache and deduplicate the tainted version in the new
tainted_frozen_strings table.

For non-embedded strings, this also allows sharing with the
underlying malloc-ed data.

* vm_core.h (rb_vm_struct): add tainted_frozen_strings
* vm.c (ruby_vm_destruct): free tainted_frozen_strings
  (Init_vm_objects): initialize tainted_frozen_strings
  (rb_vm_tfstring_table): accessor for tainted_frozen_strings
* internal.h: declare rb_fstring_existing, rb_vm_tfstring_table
* hash.c (fstring_existing_str): remove (moved to string.c)
  (hash_aset_str): use rb_fstring_existing
* string.c (rb_fstring_existing): new, based on fstring_existing_str
  (tainted_fstr_update): new
  (rb_fstring_existing0): new, based on fstring_existing_str
  (rb_tainted_fstring_existing): new, special case for tainted strings
  (rb_str_free): delete from tainted_frozen_strings table
* test/ruby/test_optimization.rb (test_hash_reuse_fstring): new test
  [ruby-core:82012] [Bug #13737]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-18 02:29:59 +00:00
normal f7f097a369 remove unused rb_obj_basic_to_s_p function
This hasn't been used since r36709 (2012-08-15)
("Kernel#inspect: improve consistency and do not call #to_s.")
and was never part of public API in include/ruby/

* class.c (rb_obj_basic_to_s_p): remove function
* internal.h (rb_obj_basic_to_s_p): remove declaration

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-29 22:34:19 +00:00
ko1 a90c696b8b rb_catch_protect() accepts enum ruby_tag_type *.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 08:24:54 +00:00
nobu aea98ff0d5 removed ruby_error_print
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-16 01:53:15 +00:00
ko1 6c3f1461cd remove ruby_kill() introduced for [Bug #7951].
* thread.c (rbuy_kill): removed. This function is used
  with SIGSEGV, SIGBUS, SIGKILL, SIGILL, SIGFPE and SIGSTOP
  and these signals are affect immediately. So that `kill(2)'
  is enough for them.

* signal.c (rb_f_kill): ditto.

* vm_core.h (rb_thread_t::interrupt_cond): removed because
  only `ruby_kill()' uses this field.

* test/ruby/test_signal.rb: Without this patch sending SIGSTOP to own
  process wait another interrupt even if another process sends SIGCONT.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-12 04:52:25 +00:00
nobu aac0b43ed5 file.c: realpath in OS path encoding
* dir.c (rb_dir_getwd_ospath): return cwd path in the OS path
  encoding.

* file.c (rb_realpath_internal): work in the OS path encoding

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-08 01:58:44 +00:00
ko1 ff18933b72 rename functions and clean parameters.
* internal.h (rb_yield_lambda): rename to rb_yield_force_blockarg()
  because this function prohibt lambda arg setup (strict setup).

* vm.c (invoke_iseq_block_from_c): remove splattable argument because
  it is not used.

* vm.c (invoke_block_from_c_splattable): rename to invoke_block_from_c_bh()
  because `splattable` doesn't make sense on current this function.

  Also accept `force_blockarg' parameter instead of `splattable` parameter.
  It is more clear.

* vm.c (invoke_block_from_c_unsplattable): rename to
  invoke_block_from_c_proc() and accept `proc` instead of `block'.
  This function is used only by proc block invocation.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-05 06:15:28 +00:00
nobu b9f5cab23a load.c: convert by rb_get_path_check
* load.c (rb_require_internal): convert to path name with the
  given safe level, without setting global safe level.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-01 13:05:54 +00:00
watson1978 d0015e4ac6 Improve performance of implicit type conversion
To convert the object implicitly, it has had two parts in convert_type() which are
  1. lookink up the method's id
  2. calling the method

Seems that strncmp() and strcmp() in convert_type() are slightly heavy to look up
the method's id for type conversion.

This patch will add and use internal APIs (rb_convert_type_with_id, rb_check_convert_type_with_id)
to call the method without looking up the method's id when convert the object.

Array#flatten -> 19 % up
Array#+       ->  3 % up

[ruby-dev:50024] [Bug #13341] [Fix GH-1537]

### Before
       Array#flatten    104.119k (± 1.1%) i/s -    525.690k in   5.049517s
             Array#+      1.993M (± 1.8%) i/s -     10.010M in   5.024258s

### After
       Array#flatten    124.005k (± 1.0%) i/s -    624.240k in   5.034477s
             Array#+      2.058M (± 4.8%) i/s -     10.302M in   5.019328s

### Test Code
require 'benchmark/ips'

class Foo
  def to_ary
    [1,2,3]
  end
end

Benchmark.ips do |x|

  ary = []
  100.times { |i| ary << i }
  array = [ary]

  x.report "Array#flatten" do |i|
    i.times { array.flatten }
  end

  x.report "Array#+" do |i|
    obj = Foo.new
    i.times { array + obj }
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-31 12:30:57 +00:00
watson1978 6fcb76ed80 Improve performance of some Time methods
internal.h : add rb_numeric_quo() as internal API.
rational.c : rename numeric_quo() to rb_numeric_quo() as internal API.
time.c (quov): optimize by invoking rb_numeric_quo() to retrieve a value of
    Numeric#quo instead of method dispatching via rb_funcall().

    Time#subsec ->  7 % up
    Time#-      -> 26 % up
    Time#to_f   -> 30 % up
    Time#to_r   ->  7 % up

    [ruby-core:80915] [Bug #13519] [Fix GH-1601]

### Before
         Time#subsec      2.024M (± 8.7%) i/s -     10.062M in   5.009762s
              Time#-      5.049M (± 4.7%) i/s -     25.186M in   5.002379s
           Time#to_f      5.625M (± 4.2%) i/s -     28.066M in   5.000749s
           Time#to_r      1.880M (± 9.7%) i/s -      9.361M in   5.027527s

### After
         Time#subsec      2.155M (± 9.7%) i/s -     10.724M in   5.022579s
              Time#-      6.362M (± 2.0%) i/s -     31.824M in   5.004625s
           Time#to_f      7.287M (± 4.8%) i/s -     36.402M in   5.010983s
           Time#to_r      2.020M (± 9.4%) i/s -     10.059M in   5.021852s

### Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "Time#subsec" do |t|
    time = Time.now
    t.times { time.subsec }
  end

  x.report "Time#-" do |t|
    time1 = Time.now
    time2 = Time.now
    t.times { time1 - time2 }
  end

  x.report "Time#to_f" do |t|
    time = Time.now
    t.times { time.to_f }
  end

  x.report "Time#to_r" do |t|
    time = Time.now
    t.times { time.to_r }
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-27 05:41:00 +00:00
nobu 7db534a20c vm_insnhelper.c: rb_eql_opt should call eql?
* vm_insnhelper.c (rb_eql_opt): should call #eql? on Float and
  String, not #==.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 05:29:35 +00:00
watson1978 b827fdffe6 Improve performance of rb_eql()
This improvement is similar with https://github.com/ruby/ruby/pull/1552

internal.h: add declaration of rb_eql_opt() API.

vm_insnhelper.c (rb_eql_opt): add rb_eql_opt() API which provides optimized
    path for #eql? method such as rb_equal_opt().

object.c (rb_eql): optimize using rb_eql_opt() such as rb_equal().
    Array#eql? and some methods have used rb_eql() and Array#eql? will be faster
    around 20%.

    [ruby-core:80761] [Bug #13447] [Fix GH-#1589]

### Before
       user     system      total        real
   1.570000   0.000000   1.570000 (  1.569754)

### After
       user     system      total        real
   1.300000   0.000000   1.300000 (  1.303624)

### Test code
require 'benchmark'

Benchmark.bmbm do |x|
  ary1 = Array.new(1000) { rand(1000) }
  ary2 = Array.new(1000) { rand(1000) }

  x.report do
    5000000.times do
      ary1.eql?(ary2)
    end
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 04:25:39 +00:00
ktsj 93a6178f56 internal.h (rb_gc_resurrect): remove stale declaration
rb_gc_resurrect is no longer defined since r47444.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-04 10:17:12 +00:00
nobu 6519aba3ba internal.h: rb_raise_static
* internal.h (rb_raise_static): raise with a static message string
  literal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-02 07:35:20 +00:00
eregon acde55201b Send the backtrace of the circular require warning as a single String to Warning.warn
* load.c: send as a single string.
* error.c: expose the string formatted by rb_warning as rb_warning_string().
* test/ruby/test_exception.rb: update tests.
  [ruby-core:80850] [Bug #13505]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-27 12:07:43 +00:00
shyouhei 29ca20de2d refactor newhash (revision 58463 another try) [fix GH-1600]
* st.c (rb_hash_bulk_insert): new API to bulk insert entries
	  into a hash. Given arguments are first inserted into the
	  table at once, then reindexed. This is faster than inserting
	  things using rb_hash_aset() one by one.

	  This arrangement (rb_ prefixed function placed in st.c) is
	  unavoidable because it both touches table internal and write
	  barrier at once.

	* internal.h: delcare the new function.

	* hash.c (rb_hash_s_create): use the new function.

	* vm.c (core_hash_merge): ditto.

	* insns.def (newhash): ditto.

	* test/ruby/test_hash.rb: more coverage on hash creation.

	* test/ruby/test_literal.rb: ditto.

-----------------------------------------------------------
benchmark results:
minimum results in each 7 measurements.
Execution time (sec)
name    before  after
loop_whileloop2  0.136  0.137
vm2_bighash*     1.249  0.623

Speedup ratio: compare with the result of `before' (greater is better)
name    after
loop_whileloop2 0.996
vm2_bighash*    2.004



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-27 04:21:04 +00:00
nobu 5ad56e7c0b load.c: backtrace of circular require
* load.c (load_lock): print backtrace of circular require via
  `Warning.warn` [ruby-core:80850] [Bug #13505]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-25 08:17:24 +00:00
shyouhei a15fd1d9f2 revert newhash refactoring
We need to fix GC bug before merging this.  Revert revisions
58452, 58435, 58434, 58428, 58427 in this order.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-24 01:40:51 +00:00
shyouhei 4ee09d914d refactor hash literal
Same as rb_ary_tmp_new_from_values(), it reduces vm_exec_core binary
size from 26,176 bytes to 26,080 bytes.  But this time, also with a
bit of optimizations:

  - Because we are allocating a new hash and no back references are
    introduced at all, we can safely skip write barriers.

  - Also, the iteration never recurs.  We can avoid complicated
    function callbacks by using st_insert instead of st_update.

----

	* hash.c (rb_hash_new_from_values): refactor
          extract the bulk insert into a function.

	* hash.c (rb_hash_new_from_object): also refactor.

	* hash.c (rb_hash_s_create): use the new functions.

	* insns.def (newhash): ditto.

	* vm.c (core_hash_from_ary): ditto.

	* iternal.h: export the new function.

-----------------------------------------------------------
benchmark results:
minimum results in each 7 measurements.
Execution time (sec)
name    before  after
loop_whileloop2  0.135  0.134
vm2_bighash*     1.236  0.687

Speedup ratio: compare with the result of `before' (greater is better)
name    after
loop_whileloop2 1.008
vm2_bighash*    1.798


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-21 04:21:14 +00:00
shyouhei 4d21d1f04b split insns.def into functions
Contemporary C compilers are good at function inlining.  They fold
multiple functions into one.  However they are not yet smart enough to
unfold a function into several ones.  So generally speaking, it is
wiser for a C programmer to manually split C functions whenever
possible.  That should make rooms for compilers to optimize at will.

Before this changeset insns.def was converted into single HUGE
function called vm_exec_core().  By moving each instruction's core
into individual functions, generated C source code is reduced from
3,428 lines to 2,847 lines.  Looking at the generated assembly
however, it seems my compiler (gcc 6.2) is extraordinary smart so that
it inlines almost all functions I introduced in this changeset back
into that vm_exec_core.  On my machine compiled machine binary of the
function does not shrink very much in size (28,432 bytes to 26,816
bytes, according to nm(1)).

I believe this change is zero-cost.  Several benchmarks I exercised
showed no significant difference beyond error mergin.  For instance
3 repeated runs of optcarrot benchmark on my machine resulted in:

   before this: 28.330329285707490, 27.513378371065920, 29.40420215754537
   after  this: 27.107195867280414, 25.549324021385907, 30.31581919050884

in fps (greater==faster).

----

	* internal.h (rb_obj_not_equal): used from vm_insnhelper.c
	* insns.def: move vast majority of lines into vm_insnhelper.c
	* vm_insnhelper.c: moved here.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-18 10:58:49 +00:00
nobu 269421084e vm_backtrace.c: backtrace functions per threads
* vm_backtrace.c (rb_threadptr_backtrace_object): rename and
  extern.

* vm_backtrace.c (rb_threadptr_backtrace_str_ary): rename as
  threadptr since the parameter is rb_thread_t*.

* vm_backtrace.c (rb_threadptr_backtrace_location_ary): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-17 01:23:50 +00:00
mrkn 1b5acc876b array.c: Improve performance of Array#sort with float elements
* array.c (sort_2): improve performance of Array#sort with float elements.

* internal.h (cmp_opt_Float, cmp_opt_data): added for checking whether or not
  Float#<=> can be optimizable.

* numeric.c (rb_float_cmp): added for internal use.

* internal.h (rb_float_cmp): ditto.

[Bug #13340]
[ruby-dev:50023]
[Fix GH-1539]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-13 07:22:35 +00:00
ko1 7519688ed8 introduce imemo_type_p(v, imemo_type)
* internal.h: introduce imemo_type_p() which checks the given value is
  T_IMEMO and imemo_type() == given imemo_type.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-07 06:41:32 +00:00
nobu 2e84bbd441 internal.h: parenthesize macro argument
* internal.h (THROW_DATA_P): parenthesize the argument which is
  casted.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-06 04:42:41 +00:00
ko1 e2fc01efa5 fix TracePoint#return_value with non-local exits
* vm.c: get return_value from imemo_throw_data object (THROW_DATA_VAL()).
  imemo_throw_data (TAG_BREAK) contains returned value.
  However, imemo_throw_data (TAG_BREAK) can skip several frames so that
  we need to use it only once (at most internal frame). To record it,
  we introduced THROW_DATA_CONSUMED and check it.

* internal.h: define THROW_DATA_CONSUMED flag.

* test/ruby/test_settracefunc.rb: add tests for [Bug #13369]

* vm_insnhelper.h: add THROW_DATA_CONSUMED_P() and
  THROW_DATA_CONSUMED_SET().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-06 02:56:23 +00:00
sorah 7dab0e07eb Remove unused Init_frozen_strings declaration
Init_frozen_strings definition is removed in r51511.
https://bugs.ruby-lang.org/issues/11423

Patch by Kohei Suzuki <eagletmt@gmail.com>

* internal.h: Remove declaration of unexist function
  [Fix GH-1558]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-29 04:32:00 +00:00
nobu 0d40bf8ffe error.c: warning functions
* error.c: define warning functions in all combinations of
  * no errno, system errno, argument
  * without/with encoding
  * enabled/disabled by default

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-27 13:15:48 +00:00
nobu 976becf7eb vm_args.c: arity check of lambda
* vm_eval.c (rb_yield_lambda): new function which yields an array
  to a proc and splat to a lambda.  mainly for Enumerable only.

* vm_args.c (setup_parameters_complex): remove special lambda
  splatting for [Bug #9605].  [ruby-core:77065] [Bug #12705]

* vm_insnhelper.c (vm_callee_setup_block_arg): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-19 01:11:12 +00:00
nobu 92e2a7048e bignum.c: rb_int_parse_cstr
* bignum.c (rb_int_parse_cstr): extend rb_cstr_parse_inum with
  flags.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 03:21:12 +00:00
shyouhei c56edb9a59 revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]
This commit is auto-generated using following command:

svn diff -r57807:57788 include internal.h bignum.c numeric.c compile.c insns.def object.c sprintf.c | patch -p0


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-09 02:31:23 +00:00
shyouhei b515528271 re-introduce __builtin_add_overflow
r57789 (74cdd89) was gradually "improve"d by naruse through r57793 to
r57806, resulted in reverting the efect of r57789 while retaining its
complexity.  I think the current situation is slightly worse than
before (same output complicated source code).

Here I introduce __builtin_add_overflow again, which (I think) is what
naruse wanted to do in r57793.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-08 04:50:22 +00:00
naruse d19d629eaa Use RB_POSFIXABLE and RB_NEGFIXABLE to avoid cast introduced at r57793
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-07 06:33:49 +00:00
shyouhei 74cdd893eb optimize FIXABLE macro
Looking at the source code, FIXABLE tends to be just before LOING2FIX
to check applicability of that operation.  Why not try computing first
then check for overflow, which should be optimial.

I also tried the same thing for unsigned types but resulted in slower
execution.  It seems RB_POSFIXABLE() is fast enough on modern CPUs.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 11:14:05 +00:00
shyouhei 5e62a1bd29 LONG_LONG_MAX not always available
I was not aware of cases when LONG_LONG_MAX is undefined.  Sorry.

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 07:25:18 +00:00
nobu 63f298b0c1 opt_eq_func refactor
* vm_insnhelper.c (opt_eq_func): method to dispatch is resolved by
  only the receiver's class, not including the argument class.
  even if basic operation is redefined, other class conditions
  never meet.  optimize Float and non-Float case, delegate to
  rb_float_equal directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 06:44:11 +00:00
shyouhei 3106f9412a use HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW
We already check for __builtin_mul_overflow in configure but never
actually referred it before.  Why not call it if available, because
that should render supposedly-optimial assembly outputs.

Optionally if __builtin_mul_overflow_p is available, which is the case
for recent GCC, use that to detect fixnum overflow.  This is much
faster than the previous.  On my machine generated assembly of
numeric.c:int_pow reduces from 480 to 448 bytes, according to nm(1).
Also on my machine, following script boosts from 7.819 to 6.929 sec.

time ./miniruby -e 'i=0; while i < 30_000_000 do i += 1; 7 ** 23; end'

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 06:04:52 +00:00
nobu 5318154fe1 eval_error.c: backstrace in reverse order
* eval_error.c (rb_threadptr_error_print): print backtrace and
  error message in reverse order if STDERR is unchanged and a tty.
  [Feature #8661]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22 08:50:25 +00:00
nobu 31ef3124a9 numeric.c: Numeric#clone and #dup
* numeric.c (num_clone, num_dup): no longer raises TypeError,
  returns the receiver instead as well as Integer and Float.
  [ruby-core:79636] [Bug #13237]

* object.c (rb_immutable_obj_clone): immutable object clone with
  freeze optional keyword argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22 02:02:11 +00:00
nobu bd26c796a1 internal.h: removed function declaration
* internal.h (rb_compile_error_str): remove declaration of removed
  internal function at r54189.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21 05:16:49 +00:00
nobu 6877de73de DEPRECATED_INTERNAL_FEATURE
* error.c (ruby_deprecated_internal_feature): renamed, to
  explicitly represent deprecation.

* internal.h (DEPRECATED_INTERNAL_FEATURE): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-17 05:45:44 +00:00
naruse 68e10755d4 fix description for current implementation
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-04 18:14:42 +00:00
nobu c2a6adc5fb internal.h: fix r57507
* internal.h (rb_overflowed_fix_to_int): invert sign bit.  should
  not set LSB of fixnum value, which is always set, to MSB.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-03 06:11:32 +00:00
naruse 038ccbd112 Use carry flag to reduce instructions
NOTE:
(1) Fixnum's LSB is always 1.
    It means you can always run `x - 1` without overflow.
(2) Of course `z = x + (y-1)` may overflow.
    Now z's LSB is always 1, and the MSB of true result is also 1.
    You can get true result in long as `(1<<63)|(z>>1)`,
    and it equals to `(z<<63)|(z>>1)` == `ror(z)`.

GCC and Clang have __builtin_add_ovewflow:
* https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
* https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-02 15:54:51 +00:00
normal 9c4ba969a5 io.c: recycle garbage on write
* string.c (STR_IS_SHARED_M): new flag to mark shared mulitple times
  (STR_SET_SHARED): set STR_IS_SHARED_M
  (rb_str_tmp_frozen_acquire, rb_str_tmp_frozen_release): new functions
  (str_new_frozen): set/unset STR_IS_SHARED_M as appropriate
* internal.h: declare new functions
* io.c (fwrite_arg, fwrite_do, fwrite_end): new
  (io_fwrite): use new functions

Introduce rb_str_tmp_frozen_acquire and rb_str_tmp_frozen_release
to manage a hidden, frozen string.  Reuse one bit of the embed
length for shared strings as STR_IS_SHARED_M to indicate a string
has been shared multiple times.  In the common case, the string
is only shared once so the object slot can be reclaimed immediately.

minimum results in each 3 measurements. (time and size)

Execution time (sec)
name                            trunk   built
io_copy_stream_write            0.682   0.254
io_copy_stream_write_socket     1.225   0.751

Speedup ratio: compare with the result of `trunk' (greater is better)
name    built
io_copy_stream_write            2.680
io_copy_stream_write_socket     1.630

Memory usage (last size) (B)
name                            trunk           built
io_copy_stream_write            95436800.000    6512640.000
io_copy_stream_write_socket     117628928.000   7127040.000

Memory consuming ratio (size) with the result of `trunk' (greater is better)
name    built
io_copy_stream_write            14.654
io_copy_stream_write_socket     16.505

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-30 20:40:18 +00:00
nobu 9e03ee87bf fix up r57461
* internal.h: Microsoft Visual C++ has never supported C99 yet,
  even in 2017.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-30 04:54:52 +00:00
shyouhei 7c7133b718 #include <stdbool.h>
17+ years passed since standardized in ISO, 8 years since we added
AC_HEADER_STDBOOL to configure.in.  I'm quite confident that it's
already safe to use <stdbool.h>.

I understand that when we introduced AC_HEADER_STDBOOL, <stdbool.h>
was remain not included because C standard and SVR4 curses conflicted
miserably back then (#1).  Though I believe such situation has been
fixed already(#2), I'm afraid of your operating system might ship a
proprietary curses that still conflicts with the standard. So to avoid
potential problem, we limit the inclusion to our internal use only.

#1 : 1997 version of SUSv2 said bool is "defined though typedef" in
     <curses.h>, while C99 said bool is a macro, plus in C++ bool is a
     keyword.  AFASIK the curses library has never been a part of
     POSIX.

#2 : In reality ncurses and NetBSD curses both just follow C99 to
     include <stdbool.h> from <curses.h>.  I think C99 is now widely
     adopted.

----

	* internal.h: #include <stdbool.h> if present.  That is
	  believed to be the case for 99.9% systems that lives today.
	  Non-C99, non-C++ situations are intentionally left
	  undefined, advised by Motohiro Kosaki.  If you have such
	  compiler, please fill the definition appropriately.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-30 04:42:04 +00:00
nobu 54fa9f9e13 eval.c: copy special exception
* eval.c (setup_exception): make unfrozen copy of special
  exception before setting up a cause.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-24 14:52:07 +00:00
nobu 803621f6d7 file.c: refine message
* file.c (rb_get_path_check_convert): refine the error message
  when the path name contains null byte.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-16 02:43:55 +00:00
eregon ac9f8145f1 fix optimization for hash aset/aref with fstring
Patch by Eric Wong [ruby-core:78797].
I don't like the idea of making insns.def any bigger to support
a corner case, and "test_hash_aref_fstring_identity" shows
how contrived this is.

[ruby-core:78783] [Bug #12855]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-07 11:31:53 +00:00
nobu 1778ed59e7 numeric.c: reduce fdiv
* numeric.c (rb_int_fdiv_double): reduce first for more precise
  result.  [ruby-core:78886] [Bug #13078]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-28 04:40:58 +00:00
nobu 353395f969 get rid of implicit signedness conversions
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-22 20:58:55 +00:00
nobu 6dd5ee752a String#match? and Symbol#match?
* string.c (rb_str_match_m_p): inverse of Regexp#match?.  based on
  the patch by Herwin Weststrate <herwin@snt.utwente.nl>.
  [Fix GH-1483] [Feature #12898]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-12 02:56:12 +00:00
mrkn f72be814d9 internal.h: change the default rounding mode to half-up
* internal.h (ROUND_DEFAULT): changed to RUBY_NUM_ROUND_HALF_UP.
  [Bug #12958] [ruby-core:78204]

* test/ruby/test_integer.rb: fix assertions for the above change.

* test/ruby/test_rational.rb: ditto.

* test/test_mathn.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-10 02:36:16 +00:00
nobu 631dde2572 round-down
* numeric.c (round_half_down, int_round_half_down): support
  round-down mode.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-25 06:28:00 +00:00
mrkn b920d9545c complex.c: optimize f_gt_p some cases
* complex.c (f_gt_p): optimize f_gt_p for specific types of arguments.

* internal.h (rb_int_gt, rb_float_gt, rb_rational_cmp): exported.

* numeric.c (rb_float_gt): rename from flo_gt and be exported.

* numeric.c (rb_int_gt): rename from int_gt and be exported.

* rational.c (rb_rational_cmp): rename from nurat_cmp and be exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-22 05:21:12 +00:00
mrkn c151aa88a9 complex.c: optimize f_negate
* complex.c (f_negate): optimize for special numeric types.

* complex.c (nucomp_expt): use rb_int_uminus instead of f_negate for
  fixnum value.

* internal.h (rb_float_uminus, rb_rational_uminus): exported.

* numeric.c (rb_float_uminus): rename from flo_uminus.

* rational.c (rb_rational_uminus): rename from nurat_negate, and add
  assertion for the parameter.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-18 15:17:19 +00:00
nobu 81ec47ea18 internal.h: round macros
* internal.h (ROUND_FUNC, ROUND_CALL): macros wrapping round
  functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-18 06:29:51 +00:00
mrkn affa0f845c complex.c: optimize Numeric#polar and Numeric#arg
* complex.c (numeric_polar): optimize for Integer, Float, and Rational.

* complex.c (numeric_arg): directly create the value of pi.

* complex.c (f_negative_p): optimize for Integer, Float, and Rational.

* rational.c (INT_NEGATIVE_P): move the definition into internal.h.

* internal.h (INT_NEGATIVE_P): ditto.

* numeric.c (rb_float_abs): rename from flo_abs and export to be used
  from other source files..

* internal.h (rb_float_abs): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-16 04:25:35 +00:00
mrkn bdd18a2c31 rational.c: optimize Integer#lcm
* rational.c (f_div, f_mul, f_abs): optimize Integer#lcm
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_int_abs): rename from int_abs to be exported.

* internal.h (rb_int_div, rb_int_abs): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 15:43:26 +00:00
mrkn f40607d15d rational.c: optimize Float#to_r
* rational.c (float_to_r): optimize Float#to_r.

* numeric.c (rb_int_lshift): exported.

* internal.h (rb_int_lshift): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 11:52:00 +00:00
mrkn 9bb3022475 rational.c: optimize Rational#{floor,ceil,round,truncate}
* rational.c (f_{expt10,round_common},nurat_{floor,ceil,round_half_{up,even}}):
  optimize Rational#{floor,ceil,round,truncate}.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_int_divmod): rename from int_divmod to be exported.

* numeric.c (rb_int_and): rename from int_and to be exported.

* intern.h (rb_int_{divmod,and}): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 06:45:11 +00:00
mrkn e5aa590637 rational.c: purge f_cmp
* rational.c (f_cmp, nurat_expt): purge f_cmp.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* rational.c (INT_POSITIVE_P): added.

* numeric.c (FIXNUM_POSITIVE_P): move the definition into internal.h.

* internal.h (FIXNUM_POSITIVE_P): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 06:07:24 +00:00
mrkn d611a7c77b rational.c: optimize Rational#==
* rational.c (nurat_eqeq_p): optimize Rational#==.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_int_equal): rename from int_equal and remove static
  to be exported.

* internal.h (rb_int_equal): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 02:24:32 +00:00
mrkn fb40c3776a rational.c: optimize Rational#<=>
* rational.c (nurat_cmp): optimize Rational#<=>.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_int_cmp): rename from int_cmp and remove static
  to be exported.

* internal.h (rb_int_cmp): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 01:29:01 +00:00
mrkn d8769bffe5 rational.c: optimize Rational#**
* rational.c (nurat_expt): optimize Rational#**.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_float_pow): rename flo_pow() to rb_float_pow()
  and remove static to be exporetd.

* internal.h (rb_int_pow, rb_float_pow): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 16:38:28 +00:00
mrkn 06d701a1f0 rational.c: avoid needless object allocation with nurat_to_double
* rational.c (nurat_to_double): introduce to convert rational to double
  without object allocation.

* rational.c (rb_rational_plus, nurat_{sub,mul,to_f}): rewrite by using
  nurat_to_double.

* bignum.c (rb_big_fdiv_double): introduce to calculate fdiv and return
  the result as a double value.

* bignum.c (big_fdiv{,_int,_float}): change the return types for
  implementing rb_big_fdiv_double.

* bignum.c (rb_big_fdiv): rewrite by using rb_big_fdiv_double.

* numeric.c (rb_int_fdiv_double): introduce to calculate fdiv and return
  the result as a double value.

* numeric.c (fix_fdiv_double): rewrite from fix_fdiv to return the
  result as a double value.

* numeric.c (rb_int_fdiv): rewrite by using rb_int_fdiv_double.

* internal.h (rb_{big,int}_fdiv_double): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 15:55:30 +00:00
mrkn f64a53462e numeric.c, rational.c: refactor by using FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P
* numeric.c (num_zero_p, fix_divide, fix_mod, fix_divmod): refactor by using
  FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P.

* rational.c (INT_NEGATIVE_P, INT_ZERO_P): ditto.

* internal.h: move FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P from numeric.c

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 14:39:25 +00:00
mrkn c05cfe3739 numeric.c, internal.h: export int_fdiv() as rb_int_fdiv()
* numeric.c (rb_int_fdiv): export int_fdiv() as rb_int_fdiv().

* internal.h (rb_int_fdiv): add declaration of rb_int_fdiv().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-10 15:23:33 +00:00
ko1 75775157ea Introduce table improvement by Vladimir Makarov <vmakarov@redhat.com>.
[Feature #12142]
	See header of st.c for improvment details.

	You can see all of code history here:
	<https://github.com/vnmakarov/ruby/tree/hash_tables_with_open_addressing>

	This improvement is discussed at
	<https://bugs.ruby-lang.org/issues/12142>
	with many people, especially with Yura Sokolov.

	* st.c: improve st_table.

	* include/ruby/st.h: ditto.

	* internal.h, numeric.c, hash.c (rb_dbl_long_hash): extract a function.

	* ext/-test-/st/foreach/foreach.c: catch up this change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-07 00:45:00 +00:00
nobu 4b7fd61a05 process.c: PATH env in spawn
* process.c (rb_exec_fillarg): honor the given path environment
  variable.  [ruby-core:53103] [Bug #8004]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-06 00:58:49 +00:00
nobu dfe91fcd08 numeric.c: round to nearest even
* numeric.c (flo_round, int_round): support round-to-nearest-even
  semantics of IEEE 754 to match sprintf behavior, and add `half:`
  optional keyword argument for the old behavior.
  [ruby-core:76273] [Bug #12548]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 09:49:39 +00:00
nobu a2144bd72a chomp option
* io.c (extract_getline_opts): extract chomp option.
  [Feature #12553]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 07:28:09 +00:00
nobu 9e75488ac8 internal.h: RB_OBJ_BUILTIN_TYPE
* internal.h (RB_OBJ_BUILTIN_TYPE): special-const safe
  BUILTIN_TYPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-28 06:58:19 +00:00
nobu 4065c38a6a class.c: rb_undef_methods_from
* class.c (rb_undef_methods_from): undefine methods defined in
  super from klass.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-24 01:49:52 +00:00
usa c2dd2d268e * internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.
a hash value of Object might be Bignum, but it causes many troubles
  expecially the Object is used as a key of a hash.  so I've gave up
  to do so.

* array.c (rb_ary_hash): use above macro.

* bignum.c (rb_big_hash): ditto.

* hash.c (rb_obj_hash, rb_hash_hash): ditto.

* numeric.c (rb_dbl_hash): ditto.

* proc.c (proc_hash): ditto.

* re.c (rb_reg_hash, match_hash): ditto.

* string.c (rb_str_hash_m): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-04 16:25:01 +00:00
ngoto 16391af2e2 * internal.h (MAYBE_UNUSED): The fallback definition is needed.
Fix compile error with some non-GCC compilers such as
  Oracle Solaris Studio 12.3 on Solaris 10.
  [Bug #12767] [ruby-dev:49807]

* internal.h (WARN_UNUSED_RESULT): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-16 12:29:42 +00:00
shyouhei 2fc5210f31 * internal.h (WARN_UNUSED_RESULT): moved to configure.in, to
actually check its availability rather to check GCC's version.

	* configure.in (WARN_UNUSED_RESULT): moved to here.

	* configure.in (RUBY_FUNC_ATTRIBUTE): change function declaration
	  to return int rather than void, because it makes no sense for a
	  warn_unused_result attributed function to return void.

	  Funny thing however is that it also makes no sense for noreturn
	  attributed function to return int.  So there is a fundamental
	  conflict between them.  While I tested this, I confirmed both
	  GCC 6 and Clang 3.8 prefers int over void to correctly detect
	  necessary attributes under this setup.  Maybe subject to change
	  in future.

	* internal.h (UNINITIALIZED_VAR): renamed to MAYBE_UNUSED, then
	  moved to configure.in for the same reason we move
	  WARN_UNUSED_RESULT.

	* configure.in (MAYBE_UNUSED): moved to here.

	* internal.h (__has_attribute): deleted, because it has no use now.

	* string.c (rb_str_enumerate_lines): refactor macro rename.

	* string.c (rb_str_enumerate_bytes): ditto.

	* string.c (rb_str_enumerate_chars): ditto.

	* string.c (rb_str_enumerate_codepoints): ditto.

	* thread.c (do_select): ditto.

	* vm_backtrace.c (rb_debug_inspector_open): ditto.

	* vsnprintf.c (BSD_vfprintf): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-16 06:15:55 +00:00
nobu e6a260ecdb variable.c: rb_deprecate_constant
* variable.c (rb_deprecate_constant): new function to deprecate a
  constant by the name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-09 03:02:22 +00:00
nobu 7615362d64 internal.h: fix typos
* internal.h (MEMO_V1_SET, MEMO_V2_SET): fix typos.  use the macro
  parameter, not the local variable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-02 07:07:01 +00:00
nobu 6a6a4126d4 internal.h: fix r55831
* internal.h (RBASIC_CLEAR_CLASS): fix compile error and size to
  fill.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-08 05:11:51 +00:00
shyouhei 869e7809a3 * internal.h (RBASIC_CLEAR_CLASS): Reroute ANSI C's strict
aliasing rule.
  	  [ruby-core:74427][Bug #12191][ruby-core:76747][Bug #12657]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-08 04:19:58 +00:00
shyouhei 26f59b09fe hide struct internal [Feature #9916]
* include/ruby/ruby.h (struct RStruct): no longer.

	* internal.h (struct RStruct): moved here.

	* struct.c (rb_struct_ptr): a compensation function for the lack
	  of RSTRUCT_PTR.  But now that we have RSTRUCT_GET/SET, that must
	  not be used anyway.  I mark this deprecated.  Dont use it.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-01 07:23:56 +00:00
ko1 e06698d257 * vm.c, internal.h: remove RubyVM::Env class and all of env objects
are imemo objects (imemo_env).

* NEWS: describe this change. I believe nobody touch these objects
  because there are no method defined.

* vm_core.h: remove the following definitions.
  * rb_cEnv decl.
  * GetEnvPtr() because Env is no longer T_DATA object.

* vm_core.h (rb_env_t): fix layout for imemo values.

* vm_core.h (vm_assert_env): added.

* vm_core.h (vm_env_new): added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-28 19:13:26 +00:00
ko1 9f60791a04 * vm_core.h: revisit the structure of frame, block and env.
[Bug #12628]

  This patch introduce many changes.

  * Introduce concept of "Block Handler (BH)" to represent
    passed blocks.

  * move rb_control_frame_t::flag to ep[0] (as a special local
    variable). This flags represents not only frame type, but also
    env flags such as escaped.

  * rename `rb_block_t` to `struct rb_block`.

  * Make Proc, Binding and RubyVM::Env objects wb-protected.

  Check [Bug #12628] for more details.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-28 11:02:30 +00:00
nobu 9662ee0584 internal.h: inline Check_Type
* internal.h (Check_Type): inline check for the object type.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-23 13:43:44 +00:00
nobu aa0e51b529 hash.c: rb_hash_add_new_element
* hash.c (rb_hash_add_new_element): add new element or do nothing
  if it is contained already.
* array.c (ary_add_hash, ary_add_hash_by): use
  rb_hash_add_new_element.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-20 08:35:25 +00:00
nobu 745a2aac69 math.c: Complex sqrt
* math.c (rb_math_sqrt): [EXPERIMENTAL] move Complex sqrt support
  from mathn.rb.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-12 14:13:46 +00:00
nobu 89ed4f41a3 complex.c: rb_complex prefix
* complex.c (rb_complex_plus, rb_complex_mul): rename to
  rb_complex prefix.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-12 13:17:04 +00:00
ngoto 5eff15d1bd * string.c (rb_str_change_terminator_length): New function to change
termlen and resize heap for the terminator. This is split from
  rb_str_fill_terminator (str_fill_term) because filling terminator
  and changing terminator length are different things. [Bug #12536]

* internal.h: declaration for rb_str_change_terminator_length.

* string.c (str_fill_term): Simplify only to zero-fill the terminator.
  For non-shared strings, it assumes that (capa + termlen) bytes of
  heap is allocated. This partially reverts r55557.

* encoding.c (rb_enc_associate_index): rb_str_change_terminator_length
  is used, and it should be called whenever the termlen is changed.

* string.c (str_capacity): New static function to return capacity
  of a string with the given termlen, because the termlen may
  sometimes be different from TERM_LEN(str) especially during
  changing termlen or filling terminator with specific termlen.

* string.c (rb_str_capacity): Use str_capacity.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-05 10:45:23 +00:00
nobu c071c05229 Integer unification macro
* include/ruby/ruby.h (RUBY_INTEGER_UNIFICATION): macro to tell if
  Integer is integrated.  [ruby-core:75718][Bug #12427]
* include/ruby/backward.h, internal.h (rb_cFixnum, rb_cBignum):
  fallback to rb_cInteger.
* bignum.c, numeric.c, ext/json/generator/generator.{c,h}: use the
  macro.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-13 11:34:56 +00:00
nobu 2667d1b38f hash.c: ensure NUL-terminated for ENV
* hash.c (get_env_cstr): ensure NUL-terminated.
  [ruby-dev:49655] [Bug #12475]
* string.c (rb_str_fill_terminator): return the pointer to the
  NUL-terminated content.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-10 05:48:38 +00:00
ngoto fd25eea0e4 * include/ruby/intern.h: Remove excess semicolons in PUREFUNC().
Fix failure of TestMkmf::TestConvertible on Solaris with
  Oracle Solaris Studio 12. [ruby-dev:49651] [Bug #12470]
* internal.h: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-08 11:36:57 +00:00
nobu 4fad63da01 transcode.c: scrub in the given encoding
* transcode.c (str_transcode0): scrub in the given encoding when
  the source encoding is given, not in the encoding of the
  receiver.  [ruby-core:75732] [Bug #12431]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-27 08:09:46 +00:00
ngoto 2b97ab88e0 Use RB_GNUC_EXTENSION_BLOCK instead of __extension__
* include/ruby/defines.h (RB_GNUC_EXTENSION, RB_GNUC_EXTENSION_BLOCK):
  macros for skipping __extension__ on non-GCC compilers.
* eval_error.c (warn_print): use RB_GNUC_EXTENSION_BLOCK instead of
  __extension__ because __extension__ is a GNU extension.
  Fix compile error on Solaris 10 with Oracle Solaris Studio 12.x.
  [Bug #12397] [ruby-dev:49629].
* internal.h (rb_fstring_cstr, rb_fstring_enc_cstr): ditto
* include/ruby/encoding.h (rb_enc_str_new, rb_enc_str_new_cstr): ditto
* include/ruby/intern.h (rb_str_new, rb_str_new_cstr,
  rb_usascii_str_new, rb_utf8_str_new, rb_tainted_str_new_cstr,
  rb_usascii_str_new_cstr, rb_utf8_str_new_cstr,
  rb_external_str_new_cstr, rb_locale_str_new_cstr,
  rb_str_buf_new_cstr, rb_str_cat_cstr, rb_exc_new_cstr): ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 12:29:06 +00:00
nobu b7733bf6c5 exclude non-VALUE in memo from GC
* internal.h (NEW_PARTIAL_MEMO_FOR): shrink buffer array not to
  mark non-VALUE fields.  fix check_rvalue_consistency abort with
  RGENGC_CHECK_MODE=2.
* internal.h (NEW_CMP_OPT_MEMO): exclude struct cmp_opt_data from
  the valid array range.
* enum.c (slicewhen_i): exclude inverted too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 10:48:51 +00:00
mrkn d5595a9627 Optimize enum_sum for a range from int to int
* enum.c (enum_sum): Optimize for a range from int to int.

* test/ruby/test_enum.rb (test_range_sum): Move from test_range.rb,
  and add assertions for some conditions.

* test/ruby/test_enum.rb (test_hash_sum): Move from test_hash.rb.

* test/ruby/test_hash.rb, test/ruby/test_range.rb: Remove test_sum.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-17 15:08:33 +00:00
naruse b207e7cd1d include/ruby/defines.h (GCC_VERSION_SINCE): moved from internal.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-12 18:12:47 +00:00
naruse ac11f944e1 Use HAVE_BUILTIN___BUILTIN_CONSTANT_P
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-12 18:12:46 +00:00
naruse 91e3c8b370 * configurein: use alternative keyword
to avoid macros conflicts with them.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-12 18:12:45 +00:00
naruse 28f5e12c24 * configure.in: check function attirbute const and pure,
and define CONSTFUNC and PUREFUNC if available.
  Note that I don't add those options as default because
  it still shows many false-positive (it seems not to consider
  longjmp).

* vm_eval.c (stack_check): get rb_thread_t* as an argument
  to avoid duplicate call of GET_THREAD().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-08 17:44:51 +00:00
yui-knk 903161e0af numeric.c: Remove prototype declarations to internal.h
* numeric.c (fix_plus): Remove rb_nucomp_add prototype
  declaration.

* numeric.c (fix_mul): Remove rb_nucomp_mul prototype
  declaration.

* internal.h (rb_nucomp_add, rb_nucomp_mul): add prototype
  declarations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-04 14:12:10 +00:00
yui-knk 5bc03ef459 * internal.h (RCOMPLEX_SET_IMAG): undef RCOMPLEX_SET_IMAG
instead of duplicated undef RCOMPLEX_SET_REAL.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-03 14:12:02 +00:00
naruse cdef0bc833 * string.c (count_utf8_lead_bytes_with_word): Use __builtin_popcount
only if it can use SSE 4.2 POPCNT whose latency is 3 cycle.

* internal.h (rb_popcount64): use __builtin_popcountll because now
  it is in fast path.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-03 13:14:30 +00:00
naruse 0f0121fe1a * string.c (search_nonascii): use nlz on big endian environments.
* internal.h (nlz_intpr): defined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 22:32:05 +00:00
naruse 4cf460a7bb * string.c (search_nonascii): unroll and use ntz
* configure.in (__builtin_ctz): check.

* configure.in (__builtin_ctzll): check.

* internal.h (rb_popcount32): defined for ntz_int32.
  it can use __builtin_popcount but this function is not used on
  GCC environment because it uses __builtin_ctz.
  When another function uses this, using __builtin_popcount
  should be re-considered.

* internal.h (rb_popcount64): ditto.

* internal.h (ntz_int32): defined for ntz_intptr.

* internal.h (ntz_int64): defined for ntz_intptr.

* internal.h (ntz_intptr): defined as ntz for uintptr_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 15:39:02 +00:00
akr 70279a5700 Define Integer#> instead of Bignum#>.
* numeric.c (int_gt): Define Integer#>.

* bignum.c (rb_big_gt): Don't define Bignum#>.
  Renamed from big_gt.

* internal.h (rb_big_gt): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 10:42:06 +00:00
akr 289c3f40a1 Define Integer#>= instead of Bignum#>=.
* numeric.c (int_ge): Define Integer#>=.

* bignum.c (rb_big_ge): Don't define Bignum#>=.
  Renamed from big_ge.

* internal.h (rb_big_ge): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 10:26:17 +00:00
akr 6b16db9c80 Define Integer#< instead of Bignum#<.
* numeric.c (int_lt): Define Integer#<.

* bignum.c (rb_big_lt): Don't define Bignum#<.
  Renamed from big_lt.

* internal.h (rb_big_lt): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 10:10:23 +00:00
akr d00bca92a9 Define Integer#<= instead of Bignum#<=.
* numeric.c (int_le): Define Integer#<=.

* bignum.c (rb_big_le): Don't define Bignum#<=.
  Renamed from big_le.

* internal.h (rb_big_le): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 09:48:25 +00:00
akr 635cff451f Define Integer#remainder instead of Bignum#remainder.
* numeric.c (int_remainder): Define Integer#remainder.

* bignum.c (rb_big_remainder): Don't define Bignum#remainder.

* internal.h (rb_big_remainder): Declared.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 08:27:30 +00:00
akr d73b431e50 Rename fix_rev and rb_big_neg to fix_comp and rb_big_comp.
* bignum.c (rb_big_comp): Renamed from rb_big_neg.

* numeric.c (fix_comp): Renamed from fix_rev.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 03:30:53 +00:00
akr 10fb4e151d {Fixnum,Bignum}#~ is unified into Integer.
* numeric.c (int_comp): {Fixnum,Bignum}#~ is unified into
  Integer.

* bignum.c (rb_big_neg): Don't define Bignum#~.

* internal.h (rb_big_neg): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 03:27:20 +00:00
akr d5a7299bca {Fixnum,Bignum}#[] is unified into Integer.
* numeric.c (int_aref): {Fixnum,Bignum}#[] is unified into
  Integer.

* bignum.c (rb_big_aref): Don't define Bignum#<<.

* internal.h (rb_big_aref): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 11:56:03 +00:00
nobu d226ce8dec internal.h: ONLY_FOR_INTERNAL_USE
* error.c (ruby_only_for_internal_use): raise fatal error when
  deprecated function only for internal use is called, not just a
  warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54791 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 05:29:49 +00:00
nobu f8fe534980 internal.h: adjust style
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 05:29:07 +00:00
akr 8f045eddb2 {Fixnum,Bignum}#size is unified into Integer.
* numeric.c (int_size): {Fixnum,Bignum}#size is unified into Integer.

* bignum.c (rb_big_size_m): Don't define Bignum#size.

* internal.h (rb_big_size_m): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 11:47:14 +00:00
akr bcc1796983 {Fixnum,Bignum}#bit_length is unified into Integer.
* numeric.c (rb_int_bit_length): {Fixnum,Bignum}#bit_length is
  unified into Integer.

* bignum.c (rb_big_bit_length): Don't define Bignum#bit_length.

* internal.h (rb_big_bit_length): Declared.

--This iine, and those below, will be ignored--

M    ChangeLog
M    bignum.c
M    internal.h
M    numeric.c


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 11:17:37 +00:00
akr 9368d7515b * numeric.c (int_abs): Integer#{abs,magnitude} moved from Fixnum and Bignum.
* internal.h (rb_big_abs): Declared.

* bignum.c (rb_big_abs): Don't define Bignum#{abs,magnitude}.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 10:59:27 +00:00
naruse 5587badf24 * include/ruby/ruby.h (RB_LIKELY): use prefix in ruby.h.
* intern.h (LIKELY): define with RB_LIKELY.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-23 07:15:25 +00:00
naruse 54c1f47930 * include/ruby/ruby.h (LIKELY): moved from internal.h.
* include/ruby/ruby.h (UNLIKELY): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-21 20:59:39 +00:00
nobu 97177a2d99 refactor syntax error
* compile.c (append_compile_error): use rb_syntax_error_append.
* error.c (rb_syntax_error_append): append messages into a
  SyntaxError exception instance.
* parse.y (yycompile0): make new SyntaxError instance in main
  mode, otherwize error_buffer should be a SyntaxError if error
  has occurred.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-20 01:25:55 +00:00
nobu 51612505f7 appending compile error without rb_errinfo
* compile.c (append_compile_error, compile_bug): pass iseq and get
  error info and file from it, not by the thread error info.
* error.c (rb_report_bug_valist): take va_list instead of variadic
  arguments, and just report the bug but not abort.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-19 04:46:20 +00:00
nobu 912948c7f5 error.c: remove unused function
* error.c (rb_compile_bug): remove unused function, which has
  never been exposed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-17 12:37:15 +00:00
mrkn d1d95056a3 rename rb_rational_add -> rb_rational_plus
* rational.c (rb_rational_plus): rename from rb_rational_add
  to be aligned with rb_fix_plus.

* array.c (rb_ary_sum): ditto.

* internal.h: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-15 14:54:39 +00:00
mrkn 0a267b79f6 array.c (rb_ary_sum): use rb_rational_add directly
* rational.c (rb_rational_add): rename from nurat_add.

* array.c (rb_ary_sum): use rb_rational_add directly.

* test/ruby/test_array.rb (test_sum): add assertions for an array of
  Rational values.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-15 14:46:35 +00:00
nobu 1ea1d2e4a7 numeric.c: int_round_zero_p
* bignum.c (rb_big_size): add wrapper function of BIGSIZE and
  rename the method funtion with _m suffix.
* numeric.c (int_round_zero_p): extracted from rb_int_round.
  optimize for Bignum, and convert VALUE returned by Numeric#size
  to long.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 05:12:01 +00:00
nobu 3b6c4dad0c bignum.c: rb_cstr_parse_inum
* bignum.c (rb_cstr_parse_inum): [EXPERIMENTAL] new function to
  parse integer in C-string with length.  the name and the
  arguments may be changed in the future.
* bignum.c (rb_str_to_inum): preserve encoding of the argument in
  error messages, and no longer needs to copy non-terminated
  strings.
* bignum.c (rb_str2big_{poweroftwo,normal,karatsuba,gmp}): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-08 17:05:12 +00:00
nobu d7935475fc remove rb_thread_t::parse_in_eval
* parse.y (struct parser_params): move parse_in_eval flag from
  rb_thread_t.
* parse.y (rb_parser_set_context): set parsing context, not only
  mild error flag.
* iseq.c (rb_iseq_compile_with_option): the parser now refers no
  thread local states to be restored.
* vm_eval.c (eval_string_with_cref): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-28 21:39:24 +00:00
nobu 23e5b482ca numeric.c: rb_int2str
* numeric.c (rb_int2str): conversion function to String for
  generic Integer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-26 01:55:14 +00:00
nobu e9dc649d66 numeric.c: rb_int_round
* numeric.c (rb_int_round): rounding function for generic
  Integers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-26 01:54:50 +00:00
nobu 79b209f19a numeric.c: basic arithmetic
* numeric.c (rb_int_{uminus,plus,minus,mul,idiv,modulo}): basic
  arithmetic functions for generic Integers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-26 01:54:16 +00:00
nobu 5396d8a1ab strftime.c: format in String
* strftime.c (rb_strftime_with_timespec): append formatted results
  to the given string with expanding, and also deal with NUL chars.
* strftime.c (rb_strftime, rb_strftime_timespec): return formatted
  string, not the length put in the given buffer.
* time.c (rb_strftime_alloc): no longer needs to retry with
  reallocating buffers.
* time.c (time_strftime): no longer needs to split by NUL chars.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-23 11:57:01 +00:00
naruse 51c4ffa45b * internal.h (rb_fix_divmod_fix): like r54213, use FIX2NUM only if
x == FIXNUM_MIN && y == -1. This must be a rare case and it is
  expected compiler to handle well.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:36:03 +00:00
nobu d17852b9d5 internal.h: fix no-DLONG case
* internal.h (rb_fix_mul_fix): multiply converted values, not
  object VALUEs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:09:26 +00:00
naruse b48fce265c fix r54203's typo (no DLONG case)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 18:28:21 +00:00
usa 6d97a5de09 * internal.h (rb_int128t2big): declare only when HAVE_INT128_T.
fixed a compile error with VC++ introduced at r54203.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 12:18:28 +00:00
naruse 148f1b9d57 * internal.h (DLONG): defined if long is 32bit (and LONG_LONG is 64bit;
but LONG_LONG is always defined as 64bit), or there's int128_t.

* internal.h (DL2NUM): defined if DLONG is defined.

* internal.h (rb_fix_mul_fix): defined for `Fixnum * Fixnum`.

* insns.def (opt_mul): use rb_fix_mul_fix().

* numeric.c (fix_mul): ditto.

* time.c (mul): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 11:10:43 +00:00
mrkn fa860a9497 * include/ruby/intern.h (rb_big_odd_p, rb_big_even_p): move to
internal.h so that they are exported only for ruby itself.

* internal.h (rb_big_odd_p, rb_big_even_p): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-19 16:08:52 +00:00
nobu bc343b851d SyntaxError message at iseq compile
* iseq.c (rb_iseq_compile_with_option): make the parser in mild
  error.
* load.c (rb_load_internal0): ditto.
* parse.y (yycompile0): return the error message within the error
  to be raised.  [Feature #11951]
* parse.y (parser_compile_error): accumulate error messages in the
  error_buffer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-19 05:46:20 +00:00
mrkn 2897eb11a0 * include/ruby/intern.h (rb_big_hash): Move to internal.h.
* internal.h: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 13:33:42 +00:00
mame 4ca0483a28 * array.c (rb_ary_max, rb_ary_min): implement Array#max and min with
arguments.  replace super call with rb_nmin_run.

* enum.c (nmin_run): exported (as rb_nmin_run).

* internal.h: added a prototype for rb_nmin_run.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 12:37:20 +00:00
mame 68a6f2e9e0 * array.c (rb_ary_max, rb_ary_min): Array#max and Array#min added.
[Feature #12172]

* internal.h (OPTIMIZED_CMP): moved from enum.c so that array.c can
  use it.

* test/ruby/test_array.rb (test_max, test_min): tests for Array#max
  and Array#min.

* test/ruby/test_enum.rb (test_max, test_min): revised a bit to test
  Enumerable#max and #min explicitly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 12:14:21 +00:00
mame a22455199b * internal.c: struct cmp_opt_data added for refactoring out a data
structure for CMP_OPTIMIZABLE

* array.c (struct ary_sort_data): use struct cmp_opt_data.

* enum.c (struct min_t, max_t, min_max_t): use struct cmp_opt_data.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 12:03:48 +00:00
akr fa153d7435 * enum.c (enum_inject): Implement the specialized code for sum of
integers including Bignums.

* internal.h (rb_fix_plus): Declared to be usable from enum_inject.

* numeric.c (rb_fix_plus): Defined.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 09:50:19 +00:00
nobu 5d6349aefe internal.h: private rb_gc_mark_global_tbl
* internal.h (rb_gc_mark_global_tbl): should be private,
  but was accidentally exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-15 04:41:24 +00:00
naruse 1b49df0b3d * intern.h (rb_divmod): assume compilers `/` and `%` comply C99
and reduce branching. If a compiler doesn't comply, add #ifdefs.

* intern.h (rb_div): added for Ruby's behavior.

* intern.h (rb_mod): added for Ruby's behavior.

* insns.def (opt_div): use rb_div.

* insns.def (opt_mod): use rb_mod.

* numeric.c (fixdivmod): removed.

* numeric.c (fix_divide): use rb_div.

* numeric.c (fix_mod): use rb_mod.

* numeric.c (fix_divmod): use rb_divmod.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-08 09:15:18 +00:00
nobu 8e1a0856ed internal.h: functions for class internals
* internal.h: move function declarations for class internals from
  include/ruby/intern.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-07 04:28:32 +00:00