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

819 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Nobuyoshi Nakada 4ba9347554
`Object#=~` warning also obeys `Warning[:deprecated]` 2019-12-24 18:53:14 +09:00
zverok c1bd1bf272 Document Module#const_source_location 2019-12-23 08:30:21 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Nobuyoshi Nakada f72dc407f2
Prohibit calling undefined allocator [Bug #16297] 2019-11-06 11:17:09 +09:00
Jean Boussier eff15a269f [EXPERIMENTAL] Make NilClass#to_s, TrueClass#to_s and FalseClass#to_s return a frozen String
* Always the same frozen String for each of these values.
    * Avoids extra allocations whenever calling these 3 methods.
    * See [Feature #16150]
2019-09-27 13:52:33 +09:00
Jeremy Evans 27b6746872 Make passing empty keywords to dig pass empty keywords to next dig method
If defined in Ruby, dig would be defined as def dig(arg, *rest) end,
it would not use keywords.  If the last dig argument was an empty
hash, it could be treated as keyword arguments by the next dig
method.  Allow dig to pass along the empty keyword flag if called
with an empty keyword, to suppress the previous behavior and force
treating the hash as a positional argument and not keywords.

Also handle the case where dig calls method_missing, passing the
empty keyword flag to that as well.

This requires adding rb_check_funcall_with_hook_kw functions, so
that dig can specify how arguments are treated.  It also adds
kw_splat arguments to a couple static functions.
2019-09-20 07:45:11 -07:00
Jeremy Evans b78a345bd6 Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from Ruby
It is not safe to set this in C functions that can be called from
other C functions, as in the non argument-delegation case, you
can end up calling a Ruby method with a flag indicating keywords
are set without passing keywords.

Introduce some new *_kw functions that take a kw_splat flag and
use these functions to set RB_PASS_CALLED_KEYWORDS in places where
we know we are delegating methods (e.g. Class#new, Method#call)
2019-09-14 01:49:33 -07:00
卜部昌平 bfe5d22f89 drop-in type check for rb_define_private_method
We can check the function pointer passed to rb_define_private_method
like how we do so in rb_define_method.  Doing so revealed some
problematic usages of rb_obj_dummy.  They had to be split according
to their arity.
2019-08-29 18:34:09 +09:00
卜部昌平 0766f67168 move docs around [ci skip]
To properly generate documents.
2019-08-29 18:34:09 +09:00
卜部昌平 7bcfd9189a drop-in type check for rb_define_global_function
We can check the function pointer passed to rb_define_global_function
like we do so in rb_define_method.  It turns out that almost anybody
is misunderstanding the API.
2019-08-29 18:34:09 +09:00
Jeremy Evans 04735c48ab Minor documentation fixes [ci skip]
From zverok (Victor Shepelev)

Fixes [Misc #16126]
2019-08-24 14:05:19 -07:00
Jeremy Evans e1c991f8d7 Move Object#hash rdoc to hash.c [ci skip]
This gets RDoc to pick up the documentation correctly.

Problem pointed out by zverok (Victor Shepelev).
2019-08-24 09:09:53 -07:00
songhuangcn d2070f2e45 Fix doc in Object#respond_to_missing? (#2239) 2019-08-16 00:20:52 +09:00
Yusuke Endoh 086ffe72c7 Revert "Revert "Add a specialized instruction for `.nil?` calls""
This reverts commit a0980f2446.

Retry for macOS Mojave.
2019-08-02 23:25:38 +09:00
Yusuke Endoh a0980f2446 Revert "Add a specialized instruction for `.nil?` calls"
This reverts commit 9faef3113f.

It seemed to cause a failure on macOS Mojave, though I'm unsure how.
https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1014/ruby-master/log/20190802T034503Z.fail.html.gz

This tentative revert is to check if the issue is actually caused by the
change or not.
2019-08-02 15:03:34 +09:00
Aaron Patterson 31ec475ad8
Update object.c
Co-Authored-By: Takashi Kokubun <takashikkbn@gmail.com>
2019-07-31 16:36:25 -07:00
Aaron Patterson 9faef3113f
Add a specialized instruction for `.nil?` calls
This commit adds a specialized instruction for called to `.nil?`.  It is
about 27% faster than master in the case where the object is nil or not
nil.  In the case where an object implements `nil?`, I think it may be
slightly slower.  Here is a benchmark:

```ruby
require "benchmark/ips"

class Niller
  def nil?; true; end
end

not_nil = Object.new
xnil = nil
niller = Niller.new

Benchmark.ips do |x|
  x.report("nil?")    { xnil.nil? }
  x.report("not nil") { not_nil.nil? }
  x.report("niller")   { niller.nil? }
end
```

On Ruby master:

```
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   429.195k i/100ms
             not nil   437.889k i/100ms
              niller   437.935k i/100ms
Calculating -------------------------------------
                nil?     20.166M (± 8.1%) i/s -    100.002M in   5.002794s
             not nil     20.046M (± 7.6%) i/s -     99.839M in   5.020086s
              niller     22.467M (± 6.1%) i/s -    112.111M in   5.013817s
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   449.660k i/100ms
             not nil   433.836k i/100ms
              niller   443.073k i/100ms
Calculating -------------------------------------
                nil?     19.997M (± 8.8%) i/s -     99.375M in   5.020458s
             not nil     20.529M (± 7.0%) i/s -    102.385M in   5.020689s
              niller     21.796M (± 8.0%) i/s -    108.110M in   5.002300s
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   402.119k i/100ms
             not nil   438.968k i/100ms
              niller   398.226k i/100ms
Calculating -------------------------------------
                nil?     20.050M (±12.2%) i/s -     98.519M in   5.008817s
             not nil     20.614M (± 8.0%) i/s -    102.280M in   5.004531s
              niller     22.223M (± 8.8%) i/s -    110.309M in   5.013106s

```

On this branch:

```
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   468.371k i/100ms
             not nil   456.517k i/100ms
              niller   454.981k i/100ms
Calculating -------------------------------------
                nil?     27.849M (± 7.8%) i/s -    138.169M in   5.001730s
             not nil     26.417M (± 8.7%) i/s -    131.020M in   5.011674s
              niller     21.561M (± 7.5%) i/s -    107.376M in   5.018113s
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   477.259k i/100ms
             not nil   428.712k i/100ms
              niller   446.109k i/100ms
Calculating -------------------------------------
                nil?     28.071M (± 7.3%) i/s -    139.837M in   5.016590s
             not nil     25.789M (±12.9%) i/s -    126.470M in   5.011144s
              niller     20.002M (±12.2%) i/s -     98.144M in   5.001737s
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   467.676k i/100ms
             not nil   445.791k i/100ms
              niller   415.024k i/100ms
Calculating -------------------------------------
                nil?     26.907M (± 8.0%) i/s -    133.755M in   5.013915s
             not nil     25.319M (± 7.9%) i/s -    125.713M in   5.007758s
              niller     19.569M (±11.8%) i/s -     96.286M in   5.008533s
```

Co-Authored-By: Ashe Connor <kivikakk@github.com>
2019-07-31 16:21:25 -07:00
Jeremy Evans 8bccbf3cfe Add more documentation on #eql?/#hash relationship [ci skip]
Fixes [Bug #14263]
2019-07-26 17:05:46 -07:00
Jeremy Evans 6279cf8b2b Restore documentation for Object#hash [ci skip]
Object#hash documentation was removed (probably by accident) in
7b19e6f3fd.
2019-07-26 16:57:42 -07:00
Nobuyoshi Nakada 3e7d002118
Check exception flag as a bool [Bug #15987] 2019-07-11 20:04:29 +09:00
Nobuyoshi Nakada 4cda2e5013
Moved error messages 2019-07-09 10:58:12 +09:00
git c5c3486340 * expand tabs. 2019-06-23 01:47:40 +09:00
Nobuyoshi Nakada 9384383019
Module#constant_source_location [Feature #10771] 2019-06-23 01:46:38 +09:00
Luke Gruber 02b1a85385
remove 2 redundant calls to rb_str_dup
Because `rb_class_path` calls `rb_str_dup` already.

Closes: https://github.com/ruby/ruby/pull/2232
2019-06-13 18:05:04 +09:00
Jean Boussier 7d805e67f3
Avoid triggering autoload in Module#const_defined?(String)
[Bug #15780]
2019-05-07 21:20:01 +09:00
nobu d10451f3fd object.c: fix searching nested const paths
* object.c (rb_mod_const_get, rb_mod_const_defined): nested const
  paths should not search from toplevel constants.
  [ruby-core:92202] [Bug #15758]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-08 13:47:37 +00:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
nobu 7fa16fd962 Fix `Module#const_defined?` on inherited constants
[Fix GH-2061]

From: manga_osyo <manga.osyo@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-28 13:32:32 +00:00
nobu 4e28fdf417 No FloatDomainError at non-finitive number if exception: false
[ruby-core:91021] [Bug #15525]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-12 09:36:52 +00:00
kazu bace0d4cdc [DOC] Add `or nil` to call-seq [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-03 05:51:18 +00:00
mame e030e9f0b8 object.c (rb_obj_match): use rb_warn for deprecation warning
Now the warning is printed even without -w option.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-26 09:04:12 +00:00
stomar 9166fdac50 complex.c, object.c: [DOC] improve "exception: false" docs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-24 20:41:15 +00:00
normal 9b9fe826fd {complex,object,rational}.c: document exception: false
From: Victor Shepelev <zverok.offline@gmail.com>

[ruby-core:90673] [Bug #15452]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22 22:39:31 +00:00
nobu 8ef2aae2d0 Use idException
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22 10:23:06 +00:00
kazu 968fcd8346 [DOC] Update Object#=~ [ci skip]
see r65989

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-16 14:54:05 +00:00
nobu 973f84ef55 Show the class of the receiver [Feature #15231]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 23:03:54 +00:00
nobu 09ef29a78f Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05 01:09:44 +00:00
mame ebff9dc10e object.c: Deprecate Object#=~ and add NilClass#=~`
Object#=~ always returns nil.  This behavior is not only unuseful but
also troublesome because it may hide a type error.

This change deprecates Object#=~.  For compatibility, NilClass#=~ is
newly introduced.  [Feature #15231]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 07:55:07 +00:00
k0kubun 38caab29bc Always inline rb_to_integer to prevent a method call penalty
for integer types

Close https://github.com/ruby/ruby/pull/2001

Co-Authored-By: methodmissing <lourens@methodmissing.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-03 12:24:49 +00:00
stomar 905be736f7 object.c: [DOC] fix typos in doc for yield_self
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-26 12:19:04 +00:00
aycabta d67b903519 Improve doc of yield_self
* object.c: Add code samples for yield_self.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21 07:15:44 +00:00
nobu e1966b31e9 Get rid of calling to_f in rat2dbl_without_to_f
[Bug #15189]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-02 18:03:43 +00:00
nobu 603f95a0ed Fix Rational of Float
[ruby-core:89239] [Bug #15189]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-02 16:42:21 +00:00
nobu 02cae85e34 object.c: prefer base optarg
* object.c (rb_f_integer): prefer `base` optional argument over
  keyword arguments.  this issue should be resolved more generally
  by separating keyword arguments from hashes in the future.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-22 16:03:58 +00:00
ko1 38e05ff3e1 Don't copy FL_USER* on Kernel#clone. [Bug #14847]
* object.c (mutable_obj_clone): `Kernel#clone` should not copy
  FL_USER* flags because they are copied unexpectedly.
  Unexpected copy will break internal data consistency.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-09 08:07:26 +00:00
matz d53ee00891 object.c: Add a new alias `then` to `Kernel#yield_self`; [Feature #14594]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-30 08:24:52 +00:00
nobu 955849c126 object.c: raise on long invalid float string
* object.c (rb_cstr_to_dbl_raise): check long invalid float
  string more precisely when truncating insignificant part.
  [ruby-core:86800] [Bug #14729]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-04 06:12:12 +00:00
nobu 853707123e object.c: fix exponent with underscore
* object.c (rb_cstr_to_dbl_raise): do not ignore exponent part
  when the input string longer than internal buffer contains
  underscore(s).  [ruby-core:86836] [Bug #14731]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-02 13:37:18 +00:00
nobu f852af0e59 symbol.c: non-ASCII constant names
* symbol.c (rb_sym_constant_char_p): support for non-ASCII
  constant names.  [Feature #13770]

* object.c (rb_mod_const_get, rb_mod_const_defined): support for
  non-ASCII constant names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-10 00:41:47 +00:00
mrkn 2993b4423d Add `exception:` keyword in Kernel#Float()
Support `exception:` keyword argument in `Kernel#Float()`.
If `exception:` is `false`, `Kernel#Float()` returns `nil` if the given
value cannot be interpreted as a float 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@62758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15 07:19:45 +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 a13b044109 object.c: conversions with ID
* object.c (rb_to_integer, rb_check_to_int): convert to Integer
  with method ID.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07 07:43:07 +00:00
nobu 86d9071e0b defs/id.def: predefine to_f ID
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-27 08:15:27 +00:00
nobu 08ba29ac06 use convert_type_with_id
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-26 14:39:16 +00:00
nobu 914444e45e use convert_type_with_id
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-26 14:30:39 +00:00
mrkn 2234edf0b1 Use RB_INTEGER_TYPE_P instead of rb_obj_is_kind_of
For checking whether an object is an Integer, because a subclass of
Integer is meaningless in Ruby, RB_INTEGER_TYPE_P is better than
rb_obj_is_kind_of for speed.

* object.c (rb_to_integer): Use RB_INTEGER_TYPE_P instead of rb_obj_is_kind_of.

* object.c (rb_check_to_integer): ditto.

* range.c (range_max): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-26 07:57:15 +00:00
mrkn cc4be225a8 Check the result of to_int in Kernel#Integer
[ruby-core:85813] [Bug #14552]

* object.c (rb_convert_to_integer):
  Check the result of to_int in Kernel#Integer

* test/ruby/test_integer.rb: add tests.

* spec/ruby/core/kernel/Integer_spec.rb: fix examples.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-26 07:31:10 +00:00
nobu 4739266ad4 [DOC] hide declaration from rdoc
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:16:41 +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 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
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
shyouhei b57915eddc Add FrozenError as a subclass of RuntimeError
FrozenError will be used instead of RuntimeError for exceptions
raised when there is an attempt to modify a frozen object. The
reason for this change is to differentiate exceptions related
to frozen objects from generic exceptions such as those generated
by Kernel#raise without an exception class.

From: Jeremy Evans <code@jeremyevans.net>
Signed-off-by: Urabe Shyouhei <shyouhei@ruby-lang.org>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 00:46:34 +00:00
marcandre 7298ae9e4b Make Module#attr{accessor|reader|writer|} public [#14132]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-29 17:47:47 +00:00
nobu 684bdf6171 object.c: deprecate Data
* object.c (InitVM_Object): Data is deprecated now.
  [Feature #3072]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-29 08:23:16 +00:00
sonots 2adcc0b8fa * object.c: Improve documentation of Kernel#Array
Array(arg) does more than just call to_ary or to_a on the argument.
It also falls back to returning [arg] if neither method is available.
This patch extends the description and adds a few examples of how it
handles common types of arguments, including an integer
(which does not implement to_ary or to_a).

Extend Kernel#Array doc to mention TypeError

patched by ragesoss (Sage Ross) [fix GH-1663]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 23:44:15 +00:00
nobu 581be44ede object.c: fix conversion failure message
* object.c (convert_type_with_id): fix failure message for
  explicit conversion.  rb_convert_type_with_id and
  rb_check_convert_type_with_id are not only for implicit
  conversions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59919 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-15 02:01:59 +00:00
rhe fc188f1646 object.c: fix potential oob write in rb_str_to_dbl()
Ensure space for the terminating NUL byte. Note that this code path is
reachable only when Ruby is compiled with SHARABLE_MIDDLE_SUBSTRING=1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-01 08:16:38 +00:00
yugui b44a588ea8 Add Doxygen comments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-22 12:26:19 +00:00
kazu 1782a2cf36 Fix documents
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-22 08:07:58 +00:00
kazu 135204eb38 Fix typos and indent
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-22 08:07:56 +00:00
svn 22224a45df * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-22 06:30:54 +00:00
yugui 7b19e6f3fd Add documents
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-22 06:30:53 +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
stomar 8bce215fa2 object.c: improve docs
* object.c: [DOC] add an example for Object#yield_self that
  better illustrates its purpose; other small improvements.
  Reported by Vitaly Tatarintsev (ck3g).  Patch by Marcus Stollsteimer.
  [Fix GH-1637]

* object.c: [DOC] improve docs for Object#{itself,tap}.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-30 18:17:55 +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
watson1978 6e0e067de3 Improve performance of rb_equal()
* object.c (rb_equal): add optimized path to compare the objects using
    rb_equal_opt(). Previously, if not same objects were given, rb_equal() would
    call `==' method via rb_funcall() which took a long time.

    rb_equal_opt() has provided faster comparing for Fixnum/Float/String objects.
    Now, Time#eql? uses rb_equal() to compare with argument object and it will
    be faster around 40% on 64-bit environment.

* array.c (rb_ary_index): remove redundant rb_equal_opt() calling.
    Now, rb_equal() was optimized using rb_equal_opt().
    If rb_equal_opt() returns Qundef, it will invoke rb_equal() -> rb_equal_opt(),
    and it will cause the performance regression.

    So, this patch will remove first redundant rb_equal_opt() calling.

* array.c (rb_ary_rindex): ditto.
* array.c (rb_ary_includes): ditto.

    [ruby-core:80360] [Bug #13365] [Fix GH-#1552]

### Before
Time#eql? with other      7.309M (± 1.4%) i/s -     36.647M in   5.014964s
    Array#index(val)      1.433M (± 1.2%) i/s -      7.207M in   5.030942s
   Array#rindex(val)      1.418M (± 1.6%) i/s -      7.103M in   5.009164s
 Array#include?(val)      1.451M (± 0.9%) i/s -      7.295M in   5.026392s

### After
Time#eql? with other     10.321M (± 1.9%) i/s -     51.684M in   5.009203s
    Array#index(val)      1.474M (± 0.9%) i/s -      7.433M in   5.044384s
   Array#rindex(val)      1.449M (± 1.7%) i/s -      7.292M in   5.034436s
 Array#include?(val)      1.466M (± 1.7%) i/s -      7.373M in   5.030047s

### Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  t1 = Time.now
  t2 = Time.now

  x.report "Time#eql? with other" do |i|
    i.times { t1.eql?(t2) }
  end

  # Benchmarks to check whether it didn't introduce the regression
  obj = Object.new
  x.report "Array#index(val)" do |i|
    ary = [1, 2, true, false, obj]
    i.times { ary.index(obj) }
  end

  x.report "Array#rindex(val)" do |i|
    ary = [1, 2, true, false, obj].reverse
    i.times { ary.rindex(obj) }
  end

  x.report "Array#include?(val)" do |i|
    ary = [1, 2, true, false, obj]
    i.times { ary.include?(obj) }
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 04:25:37 +00:00
nobu dc6d7cc58e object.c: use a sized enumerator with #yield_self
* object.c (rb_obj_size): The #yield_self Enumerator instance
  always has a #count of `1`.  This provides a lazy #size of `1`
  to match the count instead of `nil`.  [Fix GH-1615]

Author:    Shannon Skipper <shannonskipper@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-14 11:45:00 +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
nobu cec0668209 object.c: Kernel#yield_self
* object.c (rb_obj_yield_self): new method which yields the
  receiver and returns the result.
  [ruby-core:46320] [Feature #6721]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-01 07:50:53 +00:00
mrkn 8561baf340 Improve performance of type conversion using to_r
* object.c: Add to_r in conv_method_tbl.

* defs/id.def: add to_r.

* benchmark/bm_int_quo.rb: added.

* benchmark/bm_time_subsec.rb: added.

[Bug #13426]
[ruby-core:80665]
[Fix GH-1582]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-14 05:19:12 +00:00
nobu 0b1f6aed94 object.c: make String#to_f consistent with literal
* object.c (rb_cstr_to_dbl): stop at successive underscores, as
  well as Float literals.  [ruby-core:80098] [Bug #13105]

  * `_` should be within digits
  * only one `_` allowed between digits

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-15 08:15:32 +00:00
stomar 4f2db15b42 object.c: [DOC] simplify Object#tap example
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-09 19:48:09 +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 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
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 80b8ee9794 object.c: refactor rb_obj_clone and rb_obj_clone2
* object.c (rb_obj_clone2): extract option for clone, and split by
  whether the object is immutable or mutable.

* object.c (rb_obj_clone): no arguments, return immutable object
  immediately.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22 01:55:10 +00:00
nobu f2c5146dc4 object.c: message encoding
* object.c (rb_obj_clone2): preserve encoding in error messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21 14:51:22 +00:00
nobu 11e6bd5ac2 object.c: no TypeError at Symbol
* object.c (special_object_p): uninterned Symbol also should not
  raise a TypeError but return itself instead, as well as interned
  Symbols.  [ruby-core:79216] [Bug #13145]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-23 06:16:04 +00:00
nobu 03b8cb9548 object.c: rb_class_alloc
* object.c (rb_obj_alloc): add pathological check of klass for
  extension libraries which do not check given arguments properly.
  [ruby-core:78934] [Bug #13093]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-02 00:22:46 +00:00
nobu 42361548d8 object.c: rb_class_s_new
* object.c (rb_class_new_instance): add pathological check of
  klass for extension libraries which do not check given arguments
  properly.  [ruby-core:78934] [Bug #13093]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-02 00:03:28 +00:00
nobu 7f30d00b53 object.c: no TypeError at special const
* object.c (special_object_p): no longer raise a TypeError for
  Integer and Float, and return itself instead.  [Feature#12979]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-29 15:34:31 +00:00
nobu fe3b21bb8c object.c: no TypeError at special const clone
* object.c (rb_obj_clone2): no longer raise a TypeError for
  special constants, and return itself instead.  however, if
  freeze option is false, raise an ArgumentError.  [Feature#12979]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-29 15:14:05 +00:00
nobu 70d8e6cf22 object.c: no TypeError at special const dup
* object.c (rb_obj_dup): no longer raise a TypeError for special
  constants, and return itself instead.  [Feature#12979]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-27 11:07:27 +00:00
nobu c94855855e object.c: fixable float to fixnum
* object.c (rb_convert_to_integer): convert a fixable float to a
  fixnum directly without the convesion method, as well as bignum
  case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-27 00:42:11 +00:00
nobu 9396660a4a object.c: use converted string
* object.c (rb_convert_to_integer): should not drop the converted
  string.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-27 00:12:33 +00:00
nobu 4e44f6ef86 [DOC] replace Fixnum with Integer [ci skip]
* numeric.c: [DOC] update document for Integer class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-26 06:11:23 +00:00
hsbt 3827c23af5 * object.c: Improve documentation for Integer conversion.
[ruby-core:71661][Bug #11736][ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-14 09:27:23 +00:00
hsbt 6b35c34c68 * basictest/test.rb: Adjust spaces in class declarations
with inheritance. [fix GH-1227] Patch by @adrfer
* lib/irb/*: ditto.
* lib/prime.rb: ditto.
* lib/shell/builtin-command.rb: ditto.
* object.c: ditto.
* sample/*.rb: ditto.
* test/-ext-/method/test_arity.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-07 05:18:57 +00:00
nobu 4785df5527 object.c: update rdoc
* object.c (InitVM_Object): update rdoc of NIL/TRUE/FALSE, and use
  rb_deprecate_constant.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-09 03:02:23 +00:00
akr 577de1e93d replace fixnum by integer in documents.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 04:57:49 +00:00
nobu 20e0f1e712 object.c: fix {Module,Class}.new rdoc [ci skip]
* object.c (rb_mod_initialize, rb_class_initialize): [DOC] these
  methods do not invoke module_eval/class_eval, just eval the
  given block under the new module/class but sharing the context
  with the surrounding scope like those methods.
  [ruby-core:77023] [Bug #12696]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-24 03:57:58 +00:00
kou b9a82eaa13 * object.c (InitVM_Object): Update referenced document path.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-14 05:55:04 +00:00
nobu 41d220441d deprecate TRUE,FALSE,NIL
* object.c (InitVM_Object): deprecate toplevel constants TRUE,
  FALSE, and NIL.  [Feature #12574]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-07 09:08:29 +00:00
nobu e821f97451 object.c: restrict freeze option
* object.c (rb_obj_clone2): restrict freeze option to true other
  than false which only has the effect.  [Feature #12300]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-03 08:15:08 +00:00
nobu 8610ea732a object.c: suppress warning
* object.c (rb_obj_clone2): remove set but not used variable to
  suppress unused-but-set-variable warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-03 06:03:50 +00:00
shyouhei 320ae01c5f Object#clone with freeze: false [Feature #12300]
* object.c (rb_obj_clone2): Allow Object#clone to take freeze:
	  false keyword argument to not freeze the clone.
  	  [ruby-core:75017][Feature #12300]

 	* test/ruby/test_object.rb (TestObject): test for it.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-01 05:55:35 +00:00
nobu f1707e44fb Fix typo [ci skip]
* object.c (rb_mod_eqq): [DOC] Fix typo in RDoc.  [Fix GH-1393]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-28 00:56:31 +00:00
akr 449fbfd4d4 Use Integer instead of Fixnum and Bignum.
* object.c, numeric.c, enum.c, ext/-test-/bignum/mul.c,
  lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rexml/xpath_parser.rb,
  lib/rubygems/specification.rb, lib/uri/generic.rb,
  bootstraptest/test_eval.rb, basictest/test.rb,
  test/-ext-/bignum/test_big2str.rb, test/-ext-/bignum/test_div.rb,
  test/-ext-/bignum/test_mul.rb, test/-ext-/bignum/test_str2big.rb,
  test/csv/test_data_converters.rb, test/date/test_date.rb,
  test/json/test_json_generate.rb, test/minitest/test_minitest_mock.rb,
  test/openssl/test_cipher.rb, test/rexml/test_jaxen.rb,
  test/ruby/test_array.rb, test/ruby/test_basicinstructions.rb,
  test/ruby/test_bignum.rb, test/ruby/test_case.rb,
  test/ruby/test_class.rb, test/ruby/test_complex.rb,
  test/ruby/test_enum.rb, test/ruby/test_eval.rb,
  test/ruby/test_iseq.rb, test/ruby/test_literal.rb,
  test/ruby/test_math.rb, test/ruby/test_module.rb,
  test/ruby/test_numeric.rb, test/ruby/test_range.rb,
  test/ruby/test_rational.rb, test/ruby/test_refinement.rb,
  test/ruby/test_rubyvm.rb, test/ruby/test_struct.rb,
  test/ruby/test_variable.rb, test/rubygems/test_gem_specification.rb,
  test/thread/test_queue.rb: Use Integer instead of Fixnum and Bignum.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-17 13:15:57 +00:00
naruse 3738fe3333 * variable.c: use uint32_t instead of long to avoid confusion about
the type of ivtbl->numiv.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-22 09:47:34 +00:00
nobu 8790fdce57 object.c: fix error message
* object.c (rb_mod_const_get): make error message at uninterned
  string consistent with symbols.  [ruby-dev:49498] [Bug #12089]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-19 16:54:08 +00:00
normal 244916d43b resolve class name earlier and more consistently
This further avoids class name resolution issues which came
about due to relying on hash table ordering before r53376.

Pre-caching the class name when it is never used raises memory
use, but the overall gain from moving away from st still gives
us a small gain.  Reverting r53376 and this patch and testing with
"valgrind -v ./ruby -rrdoc -eexit" on x86 (32-bit) shows:

before:
    in use at exit: 1,662,239 bytes in 25,286 blocks
  total heap usage: 49,514 allocs, 24,228 frees, 6,005,561 bytes allocated

after, with this change:
    in use at exit: 1,646,529 bytes in 24,572 blocks
  total heap usage: 48,891 allocs, 24,319 frees, 6,003,921 bytes allocated

* class.c (Init_class_hierarchy): resolve name for rb_cObject ASAP
* object.c (rb_mod_const_set): move name resolution to rb_const_set
* variable.c (rb_const_set): do class resolution here
  [ruby-core:72807] [Bug #11977]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-12 19:26:07 +00:00
nobu a974041b0e object.c: fix prepend cmp
* object.c (rb_class_inherited_p): search the corresponding
  ancestor to prepended module from prepending class itself.
  [ruby-core:72493] [Bug #11878]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-30 00:58:58 +00:00
normal 1142de8e2a use id_table for constant tables
valgrind 3.9.0 on x86-64 reports a minor reduction in memory usage
when loading only RubyGems and RDoc by running: ruby -rrdoc -eexit

before: HEAP SUMMARY:
    in use at exit: 2,913,448 bytes in 27,394 blocks
  total heap usage: 48,362 allocs, 20,968 frees, 9,034,621 bytes alloc

after: HEAP SUMMARY:
    in use at exit: 2,880,056 bytes in 26,712 blocks
  total heap usage: 47,791 allocs, 21,079 frees, 9,046,507 bytes alloc

* class.c (struct clone_const_arg): adjust for id_table
  (clone_const): ditto
  (clone_const_i): ditto
  (rb_mod_init_copy): ditto
  (rb_singleton_class_clone_and_attach): ditto
  (rb_include_class_new): ditto
  (include_modules_at): ditto
* constant.h (rb_free_const_table): ditto
* gc.c (free_const_entry_i): ditto
  (rb_free_const_table): ditto
  (obj_memsize_of): ditto
  (mark_const_entry_i): ditto
  (mark_const_tbl): ditto
* internal.h (struct rb_classext_struct): ditto
* object.c (rb_mod_const_set): resolve class name on assignment
* variable.c (const_update): replace with const_tbl_update
  (const_tbl_update): new function
  (fc_i): adjust for id_table
  (find_class_path): ditto
  (autoload_const_set): st_update => const_tbl_update
  (rb_const_remove): adjust for id_table
  (sv_i): ditto
  (rb_local_constants_i): ditto
  (rb_local_constants): ditto
  (rb_mod_const_at): ditto
  (rb_mod_const_set): ditto
  (rb_const_lookup): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-29 20:19:14 +00:00
shugo 2854a7f121 * object.c (rb_inspect): check the default internal encoding as
String#inspect do.
  [ruby-dev:49415] [Bug #11787]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-13 02:48:34 +00:00
nobu 975c414b91 object.c: raise TypeError
* object.c (rb_obj_dig): raise TypeError if an element does not
  have #dig method.  [ruby-core:71798] [Bug #11762]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-12 09:52:36 +00:00
naruse e3ab670a71 * object.c (rb_inspect): dump inspected result with rb_str_escape()
instead of raising Encoding::CompatibilityError. [Feature #11801]

* string.c (rb_str_escape): added to dump given string like
  rb_str_inspect without quotes and always dump in US-ASCII
  like rb_str_dump.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-10 18:57:08 +00:00
normal 4ebab10bf5 compile optimized case dispatch for nil/true/false
nil/true/false are special literals just like floats, integers,
literal strings, and symbols.  Optimize when statements with
them by using a jump table, too.

target 0: a (ruby 2.3.0dev (2015-12-08 trunk 52928) [x86_64-linux]) at "/home/ew/rrrr/b/ruby"
target 1: b (ruby 2.3.0dev (2015-12-08 master 52928) [x86_64-linux]) at "/home/ew/ruby/b/ruby"

benchmark results:
minimum results in each 5 measurements.
Execution time (sec)
name	a	b
loop_whileloop2	0.102	0.103
vm2_case_lit*	1.657	0.549

Speedup ratio: compare with the result of `a' (greater is better)
name	b
loop_whileloop2	0.988
vm2_case_lit*	3.017

* benchmark/bm_vm2_case_lit.rb: new benchmark
* compile.c (case_when_optimizable_literal): add nil/true/false
* insns.def (opt_case_dispatch): ditto
* vm.c (vm_redefinition_check_flag): ditto
* vm.c (vm_init_redefined_flag): ditto
* vm_core.h: ditto
* object.c (InitVM_Object): define === explicitly for nil/true/false
* test/ruby/test_case.rb (test_deoptimize_nil): new test
* test/ruby/test_optimization.rb (test_opt_case_dispatch): update
  (test_eqq): new test
  [ruby-core:71923] [Feature #11769]
  Original patch by Aaron Patterson <tenderlove@ruby-lang.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 01:46:45 +00:00
nobu 2a66cc554d encoding.c: defer finding encoding
* encoding.c (enc_m_loader): defer finding encoding object not to
  be infected by marshal source.  [ruby-core:71793] [Bug #11760]
* marshal.c (r_object0): enable compatible loader on USERDEF
  class.  the loader function is called with the class itself,
  instead of an allocated object, and the loaded data.
* marshal.c (compat_allocator_table): intialize
  compat_allocator_tbl on demand.
* object.c (rb_undefined_alloc): extract from rb_obj_alloc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-02 07:27:22 +00:00
nobu 20690026a7 struct.c: dig
* object.c (rb_obj_dig): dig in nested structs too.
* struct.c (rb_struct_dig): new method Struct#dig.
  [Feature #11688]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-16 09:21:56 +00:00
akr 8b129406c6 Module#<=> is not suitable for Comparable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-12 03:50:58 +00:00
nobu 748abedf9b vm_eval.c: rb_check_funcall_default
* vm_eval.c (rb_check_funcall_default): split from
  rb_check_funcall to return the given fallback value.
* object.c (rb_obj_dig): use rb_check_funcall_default so that tail
  call optimization will be possible.  [Feature #11643]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-09 12:48:20 +00:00
nobu 29862685c0 dig
* array.c (rb_ary_dig): new method Array#dig.
* hash.c (rb_hash_dig): new method Hash#dig.
* object.c (rb_obj_dig): dig in nested arrays/hashes.
  [Feature #11643]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-09 12:27:26 +00:00
nobu 645116ff25 RUBY_DTRACE_CREATE_HOOK
* internal.h (RUBY_DTRACE_CREATE_HOOK): macro to call hook at
  object creation.

* vm.c (rb_source_location, rb_source_loc): retrieve source path
  and line number at once.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-29 05:32:57 +00:00
nobu 72ff61f4a8 NameError#receiver of uninitialized constant
* error.c (name_err_mesg_to_str): quote the name if unprintable.
* object.c (check_setter_id): use rb_check_id to convert names.
* variable.c (uninitialized_constant): use NameError::message to
  keep the receiver of uninitialized constant.  [Feature #10881]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-28 06:24:12 +00:00
nobu f830ace8a8 object.c: rb_num_to_dbl
* object.c (rb_num_to_dbl): move from num2dbl_with_to_f in math.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-13 05:36:33 +00:00
zzak f47473acd1 * object.c: [DOC] Improve grammar for Module#===
Patch by @SkyBirdSoar in documenting-ruby/ruby#52:
  https://github.com/documenting-ruby/ruby/pull/52


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-07 19:00:59 +00:00
nobu 83cd51e3fe variable.c: Module#deprecate_constant
* variable.c (rb_const_get_0): warn deprecated constant reference.
* variable.c (rb_mod_deprecate_constant): mark constants to be
  warned as deprecated.  [Feature #11398]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-30 04:20:00 +00:00
nobu 987df2ece6 hash.c: move rb_obj_hash
* hash.c (rb_obj_hash): move in order to share with rb_any_hash.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-29 08:25:49 +00:00
nobu b2a36083f8 object.c: fix up r51039
* object.c (convert_type): conversion without "to_" prefix is not
  implicit.  fix up r51039.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-02 23:19:18 +00:00
nobu 20cecf1d33 object.c: common prefix of converter methods
* object.c (convert_type): check common prefix of converter
  method names first.  shrink conv_method_names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-26 08:57:45 +00:00
nobu d92b0dc58a vm_method.c: remove redundant check
* vm_method.c (rb_attr): remove redundant check.  attribute names
  given in ruby level should be checked before calling this
  function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-24 08:29:03 +00:00
ktsj f7547ae6af * object.c (rb_obj_taint): [DOC] $SAFE=3 is obsolete.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-20 08:32:54 +00:00
hsbt bbf440c90b * include/ruby/ruby.h: $SAFE=3 is now obsolete.
* ext/socket/init.c, ext/socket/socket.c, ext/socket/tcpsocket.c
  ext/socket/udpsocket.c, gc.c, object.c, re.c, safe.c: removed code
  for $SAFE=3
* bootstraptest/test_method.rb, test/erb/test_erb.rb, test/ruby/test_dir.rb
  test/ruby/test_file.rb, test/ruby/test_method.rb, test/ruby/test_regexp.rb
  test/ruby/test_thread.rb: remove tests for $SAFE=3

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-17 05:29:51 +00:00
ko1 6964df9a21 * object.c (rb_obj_clone): do not touch age (FL_PROMOTED[01]) because
rb_obj_alloc() can return old object in debug.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-18 21:31:55 +00:00
ko1 8f88ff4e37 * internal.h: remove struct method_table_wrapper.
struct method_table_wrapper was introduced to avoid duplicate marking
  for method tables.
  For example, `module M1; def foo; end; end` make one method table
  (mtbl) contains a method `foo`. M1 (T_MODULE) points mtbl.
  Classes C1 and C2 includes M1, then two T_ICLASS objects are created
  and they points mtbl too. In this case, three objects (one T_MODULE
  and two T_ICLASS objects) points same mtbl. On marking phase, these
  three objects mark same mtbl. To avoid such duplication, struct
  method_table_wrapper was introduced.
  However, created two T_ICLASS objects have same or shorter lifetime
  than M1 (T_MODULE) object. So that we only need to mark mtbl from M1,
  not from T_ICLASS objects. This patch tries marking only from M1.
  Note that one `Module#prepend` call creates two T_ICLASS objects.
  One for refering to a prepending Module object, same as
  `Module#include`. We don't nedd to care this T_ICLASS.
  One for moving original mtbl from a prepending class. We need to
  mark such mtbl from this T_ICLASS object. To mark the mtbl,
  we need to use `RCLASS_ORIGIN(klass)` on marking from a prepended
  class `klass`.
* class.c: ditto.
* eval.c (rb_using_refinement): ditto.
* gc.c: ditto.
* include/ruby/ruby.h: define m_tbl directly. The definition of
  struct RClass should be moved to (srcdir)/internal.h.
* method.h: remove decl of rb_free_m_tbl_wrapper().
* object.c: use RCLASS_M_TBL() directly.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-05 22:20:14 +00:00
nobu 16294913f7 use rb_funcallv
* use rb_funcallv() for no arguments call instead of variadic
  rb_funcall().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-16 04:08:52 +00:00
nobu 9e256261b3 object.c: [DOC] Revise documentation
* object.c: [DOC] Revise documentation by Marcus Stollsteimer at
  [ruby-core:66368].  [Bug #10526]
  * #inspect: be more specific about generated string, remove
    obsolete example.
  * #nil?: use code examples instead of different call-seq's.
  * #tap: clarify what is yielded.
  * Integer(): be more specific about to_int and to_i, remove
    reference to Ruby 1.8.
  * Array(): fix error.
  * Class: fix variable name style and indentation in example.
  * improve consistency, fix typos and formatting.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-09 09:20:05 +00:00
nobu d0ac6d5879 object.c: preserve encodings
* object.c (inspect_i): preserve encodings in inspected result
  string.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-25 18:44:16 +00:00
nobu 8eb0c810b2 get rid of inadvertent ID creation
* object.c (rb_mod_const_get, rb_mod_const_defined): ditto.
* variable.c (rb_const_missing, rb_mod_const_missing): call
  const_missing without new ID to get rid of inadvertent ID
  creation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-21 16:11:55 +00:00
akr 2b9191e557 * internal.h: Gather declarations in non-header files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-18 15:13:05 +00:00
nobu 358840fa7d object.c: fix error message
* object.c (check_setter_id): show the original argument instead
  of nil on TypeError.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-17 18:23:09 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
eregon 61ad543a33 * object.c (Module#const_defined?): [DOC] Revise the documentation.
Patch by Xavier Noria.
  [Fixes GH-754] https://github.com/ruby/ruby/pull/754

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-08 16:54:15 +00:00
hsbt 5363dce938 * object.c: fix document of Kernel.Stirng by @suzukaze
[fix GH-743][ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-04 03:33:50 +00:00
zzak 856624228c * error.c: [DOC] Fix case of type in exception message by @tricknotes
[Fixes GH-740] https://github.com/ruby/ruby/pull/740

* object.c: ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-14 19:54:36 +00:00
normal 0ef94bd2af object.c (rb_class_real): do not dereference 0 VALUE
* test/ruby/test_module.rb (test_inspect_segfault):
  Test case and bug report by Thomas Stratmann.
  [ruby-core:65214] [Bug #10282]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-25 20:29:15 +00:00
ko1 cc3088ea51 * include/ruby/ruby.h: freeze nil/true/false.
* gc.c (should_be_finalizable): check frozen after checkin FL_ABLE.
* object.c (rb_obj_taint): check
  OBJ_TAINTABLE(obj).
* object.c (rb_obj_freeze): remove immediate_frozen_tbl
   because all of immediate values are frozen. YAY!
* object.c (rb_obj_frozen_p): ditto.
* test/ruby/test_eval.rb: skip instance_variable_set for
  frozen objects.
* test/ruby/test_weakmap.rb: check ArgumentError instead of
  RuntimeError.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-11 05:37:32 +00:00
ko1 123eeb1c1a * gc.c: add incremental GC algorithm. [Feature #10137]
Please refer this ticket for details.
  This change also introduces the following changes.
  * Remove RGENGC_AGE2_PROMOTION and introduce object age (0 to 3).
    Age can be count with FL_PROMOTE0 and FL_PROMOTE1 flags in
    RBasic::flags (2 bit). Age == 3 objects become old objects.
  * WB_PROTECTED flag in RBasic to WB_UNPROTECTED bitmap.
  * LONG_LIVED bitmap to represent living objects while minor GCs
    It specifies (1) Old objects and (2) remembered shady objects.
  * Introduce rb_objspace_t::marked_objects which counts marked
    objects in current marking phase. marking count is needed to
    introduce incremental marking.
  * rename mark related function and sweep related function to
    gc_(marks|sweep)_(start|finish|step|rest|continue).
  * rename rgengc_report() to gc_report().
  * Add obj_info() function to get cstr of object details.
  * Add MEASURE_LINE() macro to measure execution time of specific line.
  * and many small fixes.
* include/ruby/ruby.h: add flag USE_RINCGC.
  Now USE_RINCGC can be set only with USE_RGENGC.
* include/ruby/ruby.h: introduce FL_PROMOTED0 and add FL_PROMOTED1
  to count object age.
* include/ruby/ruby.h: rewrite write barriers for incremental marking.
* debug.c: catch up flag name changes.
* internal.h: add rb_gc_writebarrier_remember() instead of
  rb_gc_writebarrier_remember_promoted().
* array.c (ary_memcpy0): use rb_gc_writebarrier_remember().
* array.c (rb_ary_modify): ditto.
* hash.c (rb_hash_keys): ditto.
* hash.c (rb_hash_values): ditto.
* object.c (init_copy): use rb_copy_wb_protected_attribute() because
  FL_WB_PROTECTED is moved from RBasic::flags.
* test/objspace/test_objspace.rb: catch up ObjectSpace.dump() changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-08 04:11:00 +00:00
nobu b46b1e3f5a object.c: fix memory leak
* object.c (rb_obj_copy_ivar): allocate no memory for empty
  instance variables.  [ruby-core:64700] [Bug #10191]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-03 07:56:09 +00:00
nobu 0a0160d6b6 object.c: Object#itsef
* object.c (rb_obj_itself): new method Object#itsef.  based on the
  patch by Rafael França in [ruby-core:64156].
  [EXPERIMENTAL] this method may be renamed due to compatibilities.
  [ruby-core:44704] [Feature #6373]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-02 01:26:58 +00:00
nobu aa3b506270 add some documents [ci skip]
* bignum.c (Init_Bignum): [DOC] Bignum::GMP_VERSION.

* complex.c (Init_Complex): [DOC] ignore an internal class.

* dir.c (Init_Dir): [DOC] File::FNM_SYSCASE.

* file.c (rb_file_exists_p): [DOC] File.exists? is deprecated.

* object.c (rb_mod_initialize_clone): [DOC] ignore implementation
  detail.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-28 11:28:55 +00:00
ko1 76a929a7fc * parse.y: change Symbol <-> ID relationship to avoid
exposing IDs from collectable symbols.
  [Bug #10014]
  Now, rb_check_id() returns 0 if corresponding symbol is
  pinned dynamic symbol.
  There is remaining intern_cstr_without_pindown(), it can return
  IDs from collectable symbols. We must be careful to use it
  (only used in parse.y).  I think it should be removed if
  it does not have impact for performance.
* parse.y:
  add:
  * STATIC_SYM2ID()
  * STATIC_ID2SYM()
  rename:
  * rb_pin_dynamic_symbol() -> dsymbol_pindown()
* internal.h:
  remove:
  * rb_check_id_without_pindown()
  * rb_sym2id_without_pindown()
  add:
  * rb_check_symbol()
  * rb_check_symbol_cstr()
* load.c: use rb_check_id() or rb_check_id_cstr().
* object.c: ditto.
* struct.c: ditto.
* thread.c: ditto.
* vm_method.c: ditto.
* string.c (sym_find): use only rb_check_symbol().
* sprintf.c (rb_str_format): use rb_check_symbol_cstr().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-09 06:14:41 +00:00
nobu cf3890205f object.c: rb_obj_copy_ivar
* object.c (rb_obj_copy_ivar): extract function to copy instance
  variables only for T_OBJECT from init_copy.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-23 02:33:15 +00:00
akr 4169440f38 * object.c (rb_mod_initialize_clone): Override Kernel#initialize_clone
to avoid an exception on Class.new.freeze.clone.to_s.
  Reported by Andrew Grimm.  [ruby-core:41858] [Bug #5828]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-07 02:41:01 +00:00
nobu c0dba956d1 id.def: predefine to_i
* defs/id.def: predefine `to_i` as well as `to_int`.

* numeric.c (id_to_i): use predefined `idTo_i`.

* object.c (conv_method_names): add `to_i` ID.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-20 08:28:33 +00:00
nobu 6a2ef9d6c3 id.def: predefine conversion method IDs
* defs/id.def: predefine conversion method name IDs.

* object.c (conv_method_names): consitify with predefined IDs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-20 06:28:52 +00:00
nobu 16b8aadc75 object.c: no longer copy tables of classes/modules
* object.c (init_copy): no longer copy tables of classes/modules,
  since r45874 rb_mod_init_copy() does it instead.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-08 05:45:00 +00:00
nobu c2a7a091cc object.c: rb_class_search_ancestor
* object.c (rb_class_search_ancestor): return ancestor class or
  iclass if inherited.

* object.c (rb_obj_is_kind_of, rb_class_inherited_p): share
  function to search the ancestor.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-14 07:59:42 +00:00
nari 90b7073842 * parse.y: support Symbol GC. [ruby-trunk Feature #9634]
See this ticket about Symbol GC.

* include/ruby/ruby.h:
  Declare few functions.
  * rb_sym2id: almost same as old SYM2ID but support dynamic symbols.
  * rb_id2sym: almost same as old ID2SYM but support dynamic symbols.
  * rb_sym2str: almost same as `rb_id2str(SYM2ID(sym))` but not
    pin down a dynamic symbol.
  Declare a new struct.
  * struct RSymbol: represents a dynamic symbol as object in
    Ruby's heaps.
  Add few macros.
  * STATIC_SYM_P: check a static symbol.
  * DYNAMIC_SYM_P: check a dynamic symbol.
  * RSYMBOL: cast to RSymbol

* gc.c: declare RSymbol. support T_SYMBOL.

* internal.h: Declare few functions.
  * rb_gc_free_dsymbol: free up a dynamic symbol. GC call this
    function at a sweep phase.
  * rb_str_dynamic_intern: convert a string to a dynamic symbol.
  * rb_check_id_without_pindown: not pinning function.
  * rb_sym2id_without_pindown: ditto.
  * rb_check_id_cstr_without_pindown: ditto.

* string.c (Init_String): String#intern and String#to_sym use
  rb_str_dynamic_intern.

* template/id.h.tmpl: use LSB of ID as a flag for determining a
  static symbol, so we shift left other ruby_id_types.

* string.c: use rb_sym2str instead `rb_id2str(SYM2ID(sym))` to
  avoid pinning.

* load.c: use xx_without_pindown function at creating temporary ID
  to avoid pinning.

* object.c: ditto.

* sprintf.c: ditto.

* struct.c: ditto.

* thread.c: ditto.

* variable.c: ditto.

* vm_method.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-26 04:57:47 +00:00
hsbt cbf4eca61e * complax.c: [DOC] Document number conversion of `nil` by @skade [fix GH-570] [ci skip]
* object.c, rational.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-21 00:45:52 +00:00
ko1 53bd4502d8 * include/ruby/intern.h (rb_obj_call_init, rb_class_new_instance):
constify a parameter (VALUE *).
  I believe this incompatibility doesn't break any code.
  However, if you have trouble, please tell us.
* eval.c, object.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-20 04:03:11 +00:00
nobu 1b9ff04f65 object.c: [DOC] merge rdoc
* gc.c (rb_obj_id): remove unused rdoc.

* object.c (rb_obj_hash): [DOC] merge unused rdoc from rb_obj_id()
  in gc.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-15 00:08:24 +00:00
nobu be604acda7 object.c: error message encoding
* object.c (convert_type, rb_convert_type, rb_check_convert_type),
  (rb_to_integer): preserve class name encoding error messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-30 06:16:15 +00:00
marcandre a91bad28d4 * object.c: Add rdoc for classes frozen by default
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-09 17:34:14 +00:00
usa ac2864a871 * hash.c (rb_objid_hash): should return `long'. brushup r44534.
* object.c (rb_obj_hash): follow above change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-09 11:34:17 +00:00
nobu ab6efa5be2 object.c: hash value from objid with salt
* hash.c (rb_objid_hash): return hash value from object ID with a
  salt, extract from rb_any_hash().
* object.c (rb_obj_hash): return same value as rb_any_hash().
  fix r44125.  [ruby-core:59638] [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-08 06:55:24 +00:00
eregon 58a60b264d * object.c (Kernel#<=>) surround Comparable operators with <code> tags.
The #== method was hidden in ri/rdoc's output and was highlighting
  the line instead.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-28 13:22:42 +00:00
tmm1 3409690957 ruby.h: swap iv_index_tbl and super for struct RClass
* include/ruby/ruby.h (struct RClass): add super, remove iv_index_tbl.
  since RCLASS_SUPER() is commonly used inside while loops, we move it
  back inside struct RClass to improve cache hits. this provides a
  small improvement (1%) in hotspots like rb_obj_is_kind_of()
* internal.h (struct rb_classext_struct): remove super, add
  iv_index_table
* internal.h (RCLASS_SUPER): update for new location
* internal.h (RCLASS_SET_SUPER): ditto
* internal.h (RCLASS_IV_INDEX_TBL): ditto
* object.c (rb_class_get_superclass): ditto
* include/ruby/backward/classext.h (RCLASS_SUPER): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 05:10:07 +00:00
nobu a370556cd2 object.c: check const names
* object.c (rb_mod_const_get, rb_mod_const_defined): check
  constant names more strictly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-14 03:38:22 +00:00
nobu 241ca7bfff object.c: nested path const_defined?
* object.c (rb_mod_const_defined): support nested class path as
  well as const_get.  [Feature #7414]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-14 02:25:58 +00:00
nobu a68c69d196 object.c: remove unnecessary assignment
* object.c (rb_mod_const_get): remove unnecessary assignment and
  set path together.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-14 02:24:47 +00:00
nobu db318509d5 object.c: fix typo
* object.c (rb_mod_const_get): fix typo.  should use SYM2ID() not
  ID2SYM().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-14 02:24:35 +00:00
nobu ae1a466401 object.c: fix r44189
* object.c (rb_mod_const_get): already interned junk name may be
  valid nested class path.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-14 02:11:37 +00:00
nobu 33fddfe585 object.c: optimize rb_mod_const_get for symbol
* object.c (rb_mod_const_get): Symbol must be the entire name, not
  a nested constant path, so achieve by its ID directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-14 01:50:49 +00:00
tmm1 c2dcb947aa object.c: use RCLASS_M_TBL_WRAPPER for equality checks
* class.c (include_modules_at): use RCLASS_M_TBL_WRAPPER for
  equality checks. this avoids an unnecessary deference inside a tight
  loop, fixing a performance regression from r43973.
* object.c (rb_obj_is_kind_of): ditto.
* object.c (rb_class_inherited_p): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-12 23:19:02 +00:00
ktsj 40468b5bf1 * object.c: [DOC] document Module#singleton_class?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44070 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 08:54:23 +00:00
nari 7e1f3c636b * object.c (rb_obj_clone): don't copy FL_WB_PROTECTED of a
original object.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 14:14:09 +00:00
nari 53f1de2f49 * object.c (rb_obj_clone): Protect FL_PROMOTED and FL_WB_PROTECTED
flags of a destination object.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 11:24:11 +00:00
zzak 6869a65a8c * object.c: [DOC] Clarify Object#dup vs #clone [Bug #9128]
Moving existing doc for this comparison to separate section of #dup
  Adding examples to document behavior of #dup with Module#extend.
  Based on a patch by stevegoobermanhill


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21 05:19:32 +00:00
ko1 42bd731dc5 * include/ruby/ruby.h: rename FL_OLDGEN to FL_PROMOTED.
This flag represents that "this object is promoted at least once."
* gc.c, debug.c, object.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-04 15:04:10 +00:00
zzak ec9ec26430 * object.c: [DOC] Document first argument also takes string for:
rb_mod_const_get, rb_mod_const_set, rb_mod_const_defined

  Also added note about NameError exception for invalid constant name


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-24 03:48:54 +00:00
nobu 24cf72029f object.c: avoid inadvertent symbol creation
* object.c (id_for_attr): avoid inadvertent symbol creation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-09 14:57:04 +00:00
ktsj 36c4a3015f * object.c: [DOC] remove comment about trust/untrust.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-25 11:48:24 +00:00
ktsj 00b8bd5c87 * error.c, object.c, ext/readline/README.ja: [DOC] $SAFE=4 is obsolete.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-18 10:36:54 +00:00
nobu 944c620dfa object.c: undef Module#prepend_features on Class
* object.c (Init_Object): undef Module#prepend_features on Class, as
  well as Module#append_features.  [Fixes GH-376]
* test_class.rb: Added test for above. And ensure type checking
  on similar methods as module_function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-13 12:52:25 +00:00
nobu a25d02b144 object.c: Module#singleton_class?
* object.c (rb_mod_singleton_p): new method Module#singleton_class? to
  return whether the receiver is a singleton class or not.
  [ruby-core:51087] [Feature #7609]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-08 14:01:23 +00:00
charliesome 5e98991f1b * object.c (rb_class_inherited_p): allow iclasses to be tested for
inheritance. [Bug #8686] [ruby-core:56174]

* test/ruby/test_method.rb: add test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-05 01:02:22 +00:00
eregon 59d1fc3615 * object.c (rb_obj_cmp): Improve doc for Kernel#<=>
to clarify #equal? is not called. [See GH-352]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-09 13:25:57 +00:00
hsbt 331f22cd30 Module extended doc by @PragTob [fixes GH-335]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-09 12:03:07 +00:00
knu b0bc85f933 * object.c: Fix rdoc for Kernel#<=>. [Fix GH-352]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-09 07:02:06 +00:00
charliesome 3d8deb6e1b * object.c (rb_obj_equal): Fixed an rb_obj_equal documentation typo
where "a" was used instead of "obj".
  Fixes GH-349. Patch by @adnandoric

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-04 13:31:11 +00:00
ko1 87a120fbdc * class.c, include/ruby/ruby.h: add write barriers for T_CLASS,
T_MODULE, T_ICLASS.
* constant.h: constify rb_const_entry_t::value and file to detect
  assignment.
* variable.c, internal.h (rb_st_insert_id_and_value, rb_st_copy):
  added. update table with write barrier.
* method.h: constify some variables to detect assignment.
* object.c (init_copy): add WBs.
* variable.c: ditto.
* vm_method.c (rb_add_method): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-14 09:23:54 +00:00
shugo 1f828497d1 * safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4.  $SAFE=4 is now obsolete.
  [ruby-core:55222] [Feature #8468]

* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
  Kernel#untrusted?, untrust, and trust are now deprecated.
  Their behavior is same as tainted?, taint, and untaint,
  respectively.

* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
  and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
  respectively.

* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
  ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
  ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
  ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
  ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
  ext/socket/socket.c, ext/socket/udpsocket.c,
  ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
  ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
  load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
  safe.c, string.c, thread.c, transcode.c, variable.c,
  vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
  $SAFE=4.

* test/dl/test_dl2.rb, test/erb/test_erb.rb,
  test/readline/test_readline.rb,
  test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
  test/ruby/test_array.rb, test/ruby/test_dir.rb,
  test/ruby/test_encoding.rb, test/ruby/test_env.rb,
  test/ruby/test_eval.rb, test/ruby/test_exception.rb,
  test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
  test/ruby/test_io.rb, test/ruby/test_method.rb,
  test/ruby/test_module.rb, test/ruby/test_object.rb,
  test/ruby/test_pack.rb, test/ruby/test_rand.rb,
  test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
  test/ruby/test_struct.rb, test/ruby/test_thread.rb,
  test/ruby/test_time.rb: remove tests for $SAFE=4.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 14:20:51 +00:00
ayumin aff64b9478 * object.c (rb_Hash): fix docs. patched by Stefan Schüßler.
[ruby-core:55299] [Bug #8487]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-04 14:47:33 +00:00
zzak acae96deb7 * object.c, proc.c: s/call_seq/call-seq in rdoc. [Fix GH-322]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-31 07:04:33 +00:00
ko1 b8b26d05ce * object.c (rb_obj_clone): should not propagate OLDGEN status.
This propagation had caused WB miss for class.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-23 18:01:46 +00:00
eregon 30f813ddf2 * object.c (rb_inspect): fix typo and error message
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-18 21:23:15 +00:00
ko1 4f401816ff * gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
  check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
  you want to access raw pointers. If you modify the contents which
  pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
  and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
  barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
  generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
  FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
  move flag bits.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 18:07:47 +00:00
ko1 83aba04862 * include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
  This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
  This function reveal interal (hidden) object by rb_obj_hide().
  Note that do not change class before and after hiding.
  Only permitted example is:
  klass = RBASIC_CLASS(obj);
  rb_obj_hide(obj);
  ....
  rb_obj_reveal(obj, klass);
  TODO: API design. rb_obj_reveal() should be replaced with others.
  TODO: modify constified variables using cast may be harmful for
  compiler's analysis and optimizaton.
  Any idea to prohibt inserting RBasic::klass directly?
  If rename RBasic::klass and force to use RBASIC_CLASS(obj),
  then all codes such as `RBASIC(obj)->klass' will be
  compilation error. Is it acceptable? (We have similar
  experience at Ruby 1.9,
  for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
  object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
  without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
  file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
  parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
  string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
  Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
  ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 10:49:11 +00:00
ko1 b6b85f6eaf * object.c (rb_obj_setup): added.
* include/ruby/ruby.h (OBJSETUP): ues rb_obj_setup() instead of
  a macro.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 06:33:48 +00:00
nobu a58c224dcf object.c: skip prepending modules
* object.c (rb_obj_is_kind_of): skip prepending modules.
  [ruby-core:54742] [Bug #8357]
* object.c (rb_class_inherited_p): ditto.
  [ruby-core:54736] [Bug #8357]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-02 14:23:56 +00:00
nobu 97982e823f id.def: predefined IDs
* defs/id.def: add more predefined IDs used in core.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-02 07:54:17 +00:00
zzak 9ef25d883d * object.c: With feedback from Steve Klabnik, reverted a change to
#untrusted? and #tainted?. Also adjusted grammar for $SAFE levels


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-28 01:35:56 +00:00
zzak 6fe3e9e488 * object.c: Documentation for taint and trust [Bug #8162]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-28 00:51:46 +00:00
nobu f507cce021 object.c: extract common code
* object.c (id_for_setter): extract common code from const, class
  variable, instance variable setters.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-08 14:57:29 +00:00
naruse ae13ab2466 * object.c (rb_obj_ivar_set): call to_str for string only once.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-08 03:05:15 +00:00
naruse 6cb682a480 * object.c (rb_mod_const_set): call to_str for string only once.
to_str was called from rb_is_const_name and rb_to_id before.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-07 12:28:21 +00:00
naruse d9ff5c2230 * object.c (rb_mod_cvar_set): call to_str for string only once.
to_str was called from rb_is_class_name and rb_to_id before.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-07 12:18:26 +00:00
nobu 672b8bf1c0 object.c: avoid inadvertent symbol creation
* object.c (rb_mod_cvar_set): fix typo.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-04 21:36:38 +00:00
akr a4587840cc * object.c (rb_mod_cvar_set): Reverted "avoid inadvertent
symbol creation" to avoid SEGV by
  Class.new.class_variable_set(1, 2).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-04 13:26:39 +00:00
nobu 5e2c39ed22 object.c: avoid inadvertent symbol creation
* object.c (rb_mod_const_set): fix symbol name check.
  (rb_obj_ivar_set): ditto.
  (rb_mod_cvar_set): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-04 08:18:54 +00:00
nobu 4e59c822a0 object.c: avoid inadvertent symbol creation
* object.c (rb_mod_const_set): avoid inadvertent symbol creation.
  (rb_obj_ivar_set): ditto.
  (rb_mod_cvar_set): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-04 07:54:44 +00:00
nobu adf1c94ffe bignum.c: hide intermediate Bignums
* bignum.c (rb_big_eq): hide intermediate Bignums not just freeing
  memory.  [ruby-core:53893] [Bug #8204]
* object.c (rb_obj_hide): hide an object by clearing klass.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-03 07:35:35 +00:00
shugo c851bd00a3 * object.c (Init_Object): remove Module#used, which has been
introduced in Ruby 2.0 by mistake.  [Bug #7916] [ruby-core:52719]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-13 02:43:09 +00:00
zzak bd88e6c0b5 * object.c: Document methods receiving string and convert to symbol
Patch by Stefan Rusterholz
* vm_eval.c: ditto
* vm_method.c: ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-24 04:24:52 +00:00
zzak c2204ca328 * array.c: Document #<=> return values and formatting
* bignum.c: ditto
* file.c: ditto
* object.c: ditto
* numeric.c: ditto
* rational.c: ditto
* string.c: ditto
* time.c: ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-23 03:35:38 +00:00
zzak c135883d37 * object.c (rb_obj_comp): Documenting Object#<=> return values
Patch by Stefan Rusterholz


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-23 02:11:53 +00:00
marcandre eff6180e53 * object.c: Add doc for Module.prepended
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-22 23:18:33 +00:00
zzak c7bb797410 * object.c: Document Data class [Bug #7890] [ruby-core:52549]
Patch by Matthew Mongeau


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-20 03:19:01 +00:00
zzak 281e6e1b3b * object.c: rdoc formatting for Kernel#Array()
* array.c: Add rdoc for Array() method to Creating Arrays section


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-19 03:32:11 +00:00
marcandre c34e9f23aa * object.c: Improve error for failed implicit conversions [Bug #7539]
* error.c: Adapt rdoc

* test/ruby/test_object.rb: Test for above

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-29 22:00:58 +00:00
marcandre bca544340b * object.c: Fix rdoc typo, patch by Narsimham Chelluri [#7753].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-29 18:58:37 +00:00
eregon 3a50fb15d0 * object.c: Typo in Kernel#hash documentation.
Patch by zed_0xff [Github Fixes #237]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-17 11:28:52 +00:00
nobu d2a176028f object.c: CLASS_OR_MODULE_P
* object.c (rb_mod_to_s, rb_class_inherited_p, rb_mod_ge, rb_mod_cmp):
  use BUILTIN_TYPE() instead of TYPE() for optimization.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-15 14:07:24 +00:00
nobu e4ebf6d946 object.c: two literals
* object.c (rb_mod_to_s): concatenate two literals.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-15 14:07:22 +00:00
nobu ad6f06aed8 object.c: singleton class clone
* object.c (rb_obj_clone): attach clone to its singleton class during
  cloning singleton class so that singleton_method_added will be called
  on it.  based on the patch by shiba (satoshi shiba)[Bug #5283] in
  [ruby-dev:44477].  [Bug #5283]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-29 02:37:47 +00:00
nobu 6f02547d83 internal.h: quote unprintable
* internal.h (QUOTE, QUOTE_ID): quote unprintable chars in strings and
  IDs. [Bug #7574] [ruby-dev:46749]
* string.c (rb_str_quote_unprintable): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-22 15:04:57 +00:00
nobu f3b132faac object.c: no nested symbol
* object.c (rb_mod_const_get): symbol cannot be nested constant name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-22 11:31:13 +00:00
nobu 7815cbd7d0 object.c: defer creating string
* object.c (rb_mod_const_get): defer creating partinal name string
  until needed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-22 10:40:03 +00:00
nobu af1ca4cb13 object.c: check more strictly
* object.c (rb_mod_const_get): check more strictly.  [ruby-dev:46748]
  [Bug #7573]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-22 10:26:40 +00:00
usa e31b67700b * object.c (rb_obj_hash): shouldn't assume object_id can be long.
based on a patch by Heesob Park at [ruby-core:51060].
  cf. [Backport #7454]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-21 15:30:44 +00:00
nobu c3026b723c object.c: nul in const name
* object.c (rb_mod_const_get): nul byte is invalid as constant name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-19 10:34:13 +00:00
nobu 3738ebe15a * object.c (Init_Object): no needs to override with same method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-13 14:32:40 +00:00
charliesome c01f06089f * object.c (Init_Object): use rb_mod_init_copy for Class#initialize_copy
* class.c (rb_class_init_copy): rename to class_init_copy_check, performs type
	  checks on arguments to prevent reinitialization of initialized class
	  [ruby-core:50869] [Bug #7557]
	* class.c (rb_mod_init_copy): use class_init_copy_check if receiver is T_CLASS
	* test/ruby/test_class.rb (class TestClass): related test


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-13 14:11:01 +00:00
shugo 60d6038dda * revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
  definition, so ci->me is set to a method entry allocated in the
  stack, and it causes SEGV/ILL.  In this commit, a method entry
  with VM_METHOD_TYPE_REFINED holds the whole original method entry.
  Furthermore, rb_thread_mark() is changed to mark cfp->klass to
  avoid GC for iclasses created by copy_refinement_iclass().

* vm_method.c (rb_method_entry_make): add a method entry with
  VM_METHOD_TYPE_REFINED to the class refined by the refinement if
  the target module is a refinement.  When a method entry with
  VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
  the same name is searched in refinements.  If such a method is
  found, the method is invoked.  Otherwise, the original method in
  the refined class (rb_method_definition_t::body.orig_me) is
  invoked.  This change is made to simplify the normal method lookup
  and to improve the performance of normal method calls.

* vm_method.c (EXPR1, search_method, rb_method_entry),
  vm_eval.c (rb_call0, rb_search_method_entry): do not use
  refinements for method lookup.

* vm_insnhelper.c (vm_call_method): search methods in refinements if
  ci->me is VM_METHOD_TYPE_REFINED.  If the method is called by
  super (i.e., ci->call == vm_call_super_method), skip the same
  method entry as the current method to avoid infinite call of the
  same method.

* class.c (include_modules_at): add a refined method entry for each
  method defined in a module included in a refinement.

* class.c (rb_prepend_module): set an empty table to
  RCLASS_M_TBL(klass) to add refined method entries, because
  refinements should have priority over prepended modules.

* proc.c (mnew): use rb_method_entry_with_refinements() to get
  a refined method.

* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
  copy_refinement_iclass().

* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.

* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
  the test because it should pass successfully.

* test/ruby/test_refinement.rb (test_redefine_refined_method): new
  test for the case a refined method is redefined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 13:08:41 +00:00
nobu d4736bcf4d object.c: test bits at once
* object.c (rb_obj_clone): test TAINT and UNTRUSTED bits at once.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-03 10:21:46 +00:00
nobu 82ec3de020 object.c: make remove_instance_variable public
* object.c (Init_Object): make remove_instance_variable public.
  [Feature #6539]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-01 09:16:57 +00:00
shugo 9e44974874 * revert r37993 to avoid SEGV in tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 02:11:59 +00:00
shugo 421314cf4e * vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
  the target module is a refinement.  When a method entry with
  VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
  the same name is searched in refinements.  If such a method is
  found, the method is invoked.  Otherwise, the original method in
  the refined class (rb_method_definition_t::body.orig_def) is
  invoked.  This change is made to simplify the normal method lookup
  and to improve the performance of normal method calls.

* vm_method.c (EXPR1, search_method, rb_method_entry),
  vm_eval.c (rb_call0, rb_search_method_entry): do not use
  refinements for method lookup.

* vm_insnhelper.c (vm_call_method): search methods in refinements if
  ci->me is VM_METHOD_TYPE_REFINED.  If the method is called by
  super (i.e., ci->call == vm_call_super_method), skip the same
  method entry as the current method to avoid infinite call of the
  same method.

* class.c (include_modules_at): add a refined method entry for each
  method defined in a module included in a refinement.

* class.c (rb_prepend_module): set an empty table to
  RCLASS_M_TBL(klass) to add refined method entries, because
  refinements should have priority over prepended modules.

* proc.c (mnew): use rb_method_entry_with_refinements() to get
  a refined method.

* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
  the test because it should pass successfully.

* test/ruby/test_refinement.rb (test_redefine_refined_method): new
  test for the case a refined method is redefined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 12:50:10 +00:00
nobu 7bd638b7a4 object.c: suppress warning
* object.c (rb_obj_alloc): suppress unused variable warning.

* tool/gen_dummy_probes.rb: define dtrace disabling macro.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-16 17:02:39 +00:00
nobu b29b2962d2 adjust indent
* object.c (rb_obj_alloc): adjust indent.

* vm.c (vm_collect_usage_{insn,operand,register}): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-16 17:02:35 +00:00
tenderlove 4c740bae97 * probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.

* compile.c (rb_insns_name): allowing DTrace probes to access
  instruction sequence name.

* Makefile.in: translate probes.d file to appropriate header file.

* common.mk: declare dependencies on the DTrace header.

* configure.in: add a test for existence of DTrace.

* eval.c (setup_exception): add a probe for when an exception is
  raised.

* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
  end.

* hash.c (empty_hash_alloc): Add a probe for hash allocation.

* insns.def: Add probes for function entry and return.

* internal.h: function declaration for compile.c change.

* load.c (rb_f_load): add probes for `load` entry and exit, require
  entry and exit, and wrapping search_required for load path search.

* object.c (rb_obj_alloc): added a probe for general object creation.

* parse.y (yycompile0): added a probe around parse and compile phase.

* string.c (empty_str_alloc, str_new): DTrace probes for string
  allocation.

* test/dtrace/*: tests for DTrace probes.

* vm.c (vm_invoke_proc): add probes for function return on exception
  raise, hash create, and instruction sequence execution.

* vm_core.h: add probe declarations for function entry and exit.

* vm_dump.c: add probes header file.

* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
  function entry and return.

* vm_exec.c: expose instruction number to instruction name function.

* vm_insnshelper.c: add function entry and exit probes for cfunc
  methods.

* vm_insnhelper.h: vm usage information is always collected, so
  uncomment the functions.

12 19:14:50 2012  Akinori MUSHA  <knu@iDaemons.org>

* configure.in (isinf, isnan): isinf() and isnan() are macros on
  DragonFly which cannot be found by AC_REPLACE_FUNCS().  This
  workaround enforces the fact that they exist on DragonFly.

12 15:59:38 2012  Shugo Maeda  <shugo@ruby-lang.org>

* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
  vm_insnhelper.c (vm_search_method): revert r37616 because it's too
  slow.  [ruby-dev:46477]

* test/ruby/test_refinement.rb (test_inline_method_cache): skip
  the test until the bug is fixed efficiently.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-12 21:52:12 +00:00
nobu bd9b31e557 object.c: inadvertent symbol
* object.c (rb_mod_const_get): avoid inadvertent symbol creation.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-07 00:16:03 +00:00
tenderlove ac7f5157ac * object.c (rb_mod_const_get): Fix constant missing exception class
and message to maintain backwards compatibility. Constant search
  should start at Object when constant starts with '::'

* test/ruby/test_module.rb: test for fixes

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-06 11:42:24 +00:00
shugo b14e2b4401 * object.c (rb_mod_to_s): Module#{to_s,inspect}, when invoked on
a refinement, returns a string in the format #<refinement:C@M>,
  where C is a refined class and M is a module at which the refinemet
  is defined.

* eval.c (rb_mod_refine): store information on a refinement for the
  above change.

* test/ruby/test_refinement.rb: related test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-02 08:53:06 +00:00
tenderlove 909bc583a4 * object.c (rb_mod_const_get): make sure the constant name is
converted to a string before searching. [ruby-core:48405]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-27 01:51:58 +00:00
tenderlove 82af182e74 * object.c (rb_mod_const_get): const_get accepts qualified constant
strings.  e.g. Object.const_get("Foo::Bar::Baz") [ruby-core:41404]

* test/ruby/test_module.rb: tests for new behavior

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-26 21:31:23 +00:00
nari c3a46d6aca * include/ruby/ruby.h: add C APIs.
VALUE rb_newobj_of(VALUE klass, VALUE flags)
  #define NEWOBJ_OF(obj,type,klass,flags)
  These allow to change a allocation strategy depending on klass
  or flags.

* gc.c: ditto

* array.c: use new C API.
* bignum.c: ditto
* class.c: ditto
* complex.c: ditto
* ext/socket/ancdata.c: ditto
* ext/socket/option.c: ditto
* hash.c: ditto
* io.c: ditto
* marshal.c: ditto
* numeric.c: ditto
* object.c: ditto
* random.c: ditto
* range.c: ditto
* rational.c: ditto
* re.c: ditto
* string.c: ditto
* struct.c: ditto
  [Feature #7177][Feature #7047]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-20 06:57:51 +00:00
nobu 5fbfc21b67 internal.h: allocator function in rb_classext_t
* internal.h (struct rb_classext_struct): move allocator function into
  rb_classext_t from ordinary method table.  [ruby-dev:46121]
  [Feature #6993]
* object.c (rb_obj_alloc): call allocator function directly.
* vm_method.c (rb_define_alloc_func, rb_undef_alloc_func)
  (rb_get_alloc_func): use allocator function in rb_classext_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-08 09:52:26 +00:00