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

385 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans 4e1f2283b4 Make Thread#thread_variable? similar to #thread_variable_get
Don't use rb_check_id, which only works for pinned symbols.
Switch inadvertent creation test for thread_variable? to
only check for pinned symbols, same as thread_variable_get
and thread_variable_set.

Make key variable name in thread_local_set match
thread_local_get and thread_variable?.

Fixes [Bug #16906]
2020-05-25 21:38:35 -07:00
Jean Boussier cbe4f75ef8 Fix rb_profile_frame_classpath to handle module singletons
Right now `SomeClass.method` is properly named, but `SomeModule.method`
is displayed as `#<Module:0x000055eb5d95adc8>.method` which makes
profiling annoying.
2020-05-07 08:46:36 -07:00
Alan Wu b385f7670f Clear all trace events during teardown
Since 0c2d81dada, not all trace events are cleared during VM teardown.
This causes a crash when there is a tracepoint for
`RUBY_INTERNAL_EVENT_GC_EXIT` active during teardown.

The commit looks like a refactoring commit so I think this change was
unintentional.

[Bug #16682]
2020-03-29 23:41:19 -04:00
Nobuyoshi Nakada daa04c5562
Word array instead of splitting 2020-03-08 17:39:22 +09:00
Nobuyoshi Nakada 72c02aa4b7
Moved not-implemented method tests [Bug #16662]
Test not-implemented method with the dedicated methods, instead of
platform dependent features.
2020-02-28 21:15:37 +09:00
Koichi Sasada b9007b6c54 Introduce disposable call-cache.
This patch contains several ideas:

(1) Disposable inline method cache (IMC) for race-free inline method cache
    * Making call-cache (CC) as a RVALUE (GC target object) and allocate new
      CC on cache miss.
    * This technique allows race-free access from parallel processing
      elements like RCU.
(2) Introduce per-Class method cache (pCMC)
    * Instead of fixed-size global method cache (GMC), pCMC allows flexible
      cache size.
    * Caching CCs reduces CC allocation and allow sharing CC's fast-path
      between same call-info (CI) call-sites.
(3) Invalidate an inline method cache by invalidating corresponding method
    entries (MEs)
    * Instead of using class serials, we set "invalidated" flag for method
      entry itself to represent cache invalidation.
    * Compare with using class serials, the impact of method modification
      (add/overwrite/delete) is small.
    * Updating class serials invalidate all method caches of the class and
      sub-classes.
    * Proposed approach only invalidate the method cache of only one ME.

See [Feature #16614] for more details.
2020-02-22 09:58:59 +09:00
Koichi Sasada f2286925f0 VALUE size packed callinfo (ci).
Now, rb_call_info contains how to call the method with tuple of
(mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and
mid+argc+flags only requires 64bits. So this patch packed
rb_call_info to VALUE (1 word) on such cases. If we can not
represent it in VALUE, then use imemo_callinfo which contains
conventional callinfo (rb_callinfo, renamed from rb_call_info).

iseq->body->ci_kw_size is removed because all of callinfo is VALUE
size (packed ci or a pointer to imemo_callinfo).

To access ci information, we need to use these functions:
vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci).

struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg.

rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc()
is temporary removed because cd->ci should be marked.
2020-02-22 09:58:59 +09:00
Koichi Sasada 53a8b1486b skip SEGV test if RUBY_ON_BUG is specified 2020-02-13 04:20:22 +09:00
Kenta Murata 5275d8bf4c
rb_rational_raw: convert num and den by to_int 2020-01-17 10:57:51 +09:00
Kenta Murata 47465ab1cc
rb_rational_raw: make a denominator always positive 2020-01-17 10:57:21 +09:00
Jeremy Evans ff96565686 Update tests for full keyword argument separation 2020-01-02 18:40:45 -08:00
Marc-Andre Lafortune 819b604037 Reword keyword arguments warning messages to convey these are deprecation warnings 2019-12-23 16:47:33 -05:00
Yusuke Endoh f7aee58498 vm_args.c: rephrase the warning message of keyword argument separation
(old)
test.rb:4: warning: The last argument is used as the keyword parameter
test.rb:1: warning: for `foo' defined here; maybe ** should be added to the call?

(new)
test.rb:4: warning: The last argument is used as keyword parameters; maybe ** should be added to the call
test.rb:1: warning: The called method `foo' is defined here
2019-12-20 19:41:15 +09:00
Nobuyoshi Nakada db16629008
Fixed misspellings
Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
2019-12-20 09:32:42 +09:00
Koichi Sasada 36da0b3da1 check interrupts at each frame pop timing.
Asynchronous events such as signal trap, finalization timing,
thread switching and so on are managed by "interrupt_flag".
Ruby's threads check this flag periodically and if a thread
does not check this flag, above events doesn't happen.

This checking is CHECK_INTS() (related) macro and it is placed
at some places (laeve instruction and so on). However, at the end
of C methods, C blocks (IMEMO_IFUNC) etc there are no checking
and it can introduce uninterruptible thread.

To modify this situation, we decide to place CHECK_INTS() at
vm_pop_frame(). It increases interrupt checking points.
[Bug #16366]

This patch can introduce unexpected events...
2019-11-29 17:47:02 +09:00
Yusuke Endoh 0c0278b90a test/-ext-/string/test_fstring.rb: suppress a warning for taint 2019-11-18 09:25:49 -06: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
Kazuki Tsujimoto 79f0e7aafd
Fix typos 2019-11-09 21:12:29 +09:00
NARUSE, Yui bea322a352 Revert "[EXPERIMENTAL] Make Symbol#to_s return a frozen String [Feature #16150]"
This reverts commit 6ffc045a81.
2019-11-05 17:30:54 +09:00
卜部昌平 11b6ff12af more use of RbConfig::LIMITS
`8 * RbConfig::SIZEOF` ... is not straight.
2019-10-08 11:21:20 +09:00
Jeremy Evans 3073404e74 Add rb_enumeratorize_with_size_kw and related macros
Currently, there is not a way to create a sized enumerator in C
with a different set of arguments than provided by Ruby, and
correctly handle keyword arguments.  This function allows that.

The need for this is fairly uncommon, but it occurs at least in
Enumerator.produce, which takes arugments from Ruby but calls
rb_enumeratorize_with_size with a different set of arguments.
2019-09-30 07:06:42 -07:00
Yusuke Endoh fc66947c61 test/-ext-/string/test_fstring.rb: suppress "possibly useless use of -@"
"in void context" by assigning the result to a dummy variable.
2019-09-30 20:22:29 +09:00
Jeremy Evans 649a64ae29 Add three more C-API functions for handling keywords
This adds rb_funcall_passing_block_kw, rb_funcallv_public_kw,
and rb_yield_splat_kw.  This functions are necessary to easily
handle cases where rb_funcall_passing_block, rb_funcallv_public,
and rb_yield_splat are currently used and a keyword argument
separation warning is raised.
2019-09-29 18:31:08 -07:00
Benoit Daloze 6ffc045a81 [EXPERIMENTAL] Make Symbol#to_s return a frozen String
* Always the same frozen String for a given Symbol.
* Avoids extra allocations whenever calling Symbol#to_s.
* See [Feature #16150]
2019-09-26 10:23:02 +02:00
Alan Wu 93faa011d3 Tag string shared roots to fix use-after-free
The buffer deduplication codepath in rb_fstring can be used to free the buffer
of shared string roots, which leads to use-after-free.

Introudce a new flag to tag strings that at one point have been a shared root.
Check for it in rb_fstring to avoid freeing buffers that are shared by
multiple strings. This change is based on nobu's idea in [ruby-core:94838].

The included test case test for the sequence of calls to internal functions
that lead to this bug. See attached ticket for Ruby level repros.

[Bug #16151]
2019-09-26 15:30:18 +09:00
Jeremy Evans 80b5a0ff2a
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.

This makes the following changes to : handling.

* Treats as **kw, prompting keyword argument separation warnings
  if called with a positional hash.

* Do not look for an option hash if empty keywords are provided.
  For backwards compatibility, treat an empty keyword splat as a empty
  mandatory positional hash argument, but emit a a warning, as this
  behavior will be removed in Ruby 3.  The argument number check
  needs to be moved lower so it can correctly handle an empty
  positional argument being added.

* If the last argument is nil and it is necessary to treat it as an option
  hash in order to make sure all arguments are processed, continue to
  treat the last argument as the option hash. Emit a warning in this case,
  as this behavior will be removed in Ruby 3.

* If splitting the keyword hash into two hashes, issue a warning, as we
  will not be splitting hashes in Ruby 3.

* If the keyword argument is required to fill a mandatory positional
  argument, continue to do so, but emit a warning as this behavior will
  be going away in Ruby 3.

* If keyword arguments are provided and the last argument is not a hash,
  that indicates something wrong. This can happen if a cfunc is calling
  rb_scan_args multiple times, and providing arguments that were not
  passed to it from Ruby.  Callers need to switch to the new
  rb_scan_args_kw function, which allows passing of whether keywords
  were provided.

This commit fixes all warnings caused by the changes above.

It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used.  If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.

In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby.  The last argument may or may not be a hash,
so we can't set keyword argument mode.  However, if it is a
hash, we don't want to warn when treating it as keywords.

In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args.  Also, make
sure not to pass nil in place of an option hash.

Work around Kernel#warn warnings due to problems in the Rubygems
override of the method.  There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.

Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 11:18:49 -07:00
Nobuyoshi Nakada ffdef3674a
Warn instance variable `E`
It is not dumped, as it is a short alias for `:encoding`.
2019-08-10 13:18:41 +09:00
卜部昌平 5d33f78716 fix tracepoint + backtrace SEGV
PC modification in gc_event_hook_body was careless.  There are (so
to say) abnormal iseqs stored in the cfp.  We have to check sanity
before we touch the PC.

This has not been fixed because there was no way to (ab)use the
setup from pure-Ruby.  However by using our official C APIs it is
possible to touch such frame(s), resulting in SEGV.

Fixes [Bug #14834].
2019-08-01 16:00:59 +09:00
Nobuyoshi Nakada 99dc885974
Fixed inadvertent ID creation in rb_iv_get 2019-07-01 13:56:55 +09:00
Nobuyoshi Nakada 75129c62eb
Suppress "statement not reached" warning 2019-06-30 11:53:02 +09:00
Nobuyoshi Nakada 4a063546e7
Suppress unused literal warnings in verbose mode 2019-06-30 11:49:40 +09:00
Nobuyoshi Nakada 5331932cd2
Removed unused variables 2019-06-28 17:08:21 +09:00
John Hawthorn 04bc4c0662 Resize capacity for fstring
When a string is #frozen, it's capacity is resized to fit (if it is much
larger), since we know it will no longer be mutated.

    > puts ObjectSpace.dump(String.new("a"*30, capacity: 1000))
    {"type":"STRING", "class":"0x7feaf00b7bf0", "bytesize":30, "capacity":1000, "value":"...
    > puts ObjectSpace.dump(String.new("a"*30, capacity: 1000).freeze)
    {"type":"STRING", "class":"0x7feaf00b7bf0", "frozen":true, "bytesize":30, "value":"...

(ObjectSpace.dump doesn't show capacity if capacity is equal to bytesize)

Previously, if we dedup into an fstring, using String#-@, capacity would
not be reduced.

    > puts ObjectSpace.dump(-String.new("a"*30, capacity: 1000))
    {"type":"STRING", "class":"0x7feaf00b7bf0", "frozen":true, "fstring":true, "bytesize":30, "capacity":1000, "value":"...

This commit makes rb_fstring call rb_str_resize, the same as
rb_str_freeze does.

Closes: https://github.com/ruby/ruby/pull/2256
2019-06-26 15:01:48 +09:00
Nobuyoshi Nakada 3840791b7e
Get rid of error with frozen string literal
[Bug #14194]
2019-06-23 07:56:43 +09:00
Hiroshi SHIBATA 464e55f1d0
Ignore warnings about argument prefix with operator symbol. 2019-06-01 15:20:21 +03:00
Nobuyoshi Nakada dc65e75101
Adjust indent 2019-05-10 22:00:22 +09:00
Alan Wu c06ddfee87
str_duplicate: Don't share with a frozen shared string
This is a follow up for 3f9562015e.
Before this commit, it was possible to create a shared string which
shares with another shared string by passing a frozen shared string
to `str_duplicate`.

Such string looks like:

```
 --------                    -----------------
 | root | ------ owns -----> | root's buffer |
 --------                    -----------------
     ^                             ^   ^
 -----------                       |   |
 | shared1 | ------ references -----   |
 -----------                           |
     ^                                 |
 -----------                           |
 | shared2 | ------ references ---------
 -----------
```

This is bad news because `rb_fstring(shared2)` can make `shared1`
independent, which severs the reference from `shared1` to `root`:

```c
/* from fstr_update_callback() */
str = str_new_frozen(rb_cString, shared2);  /* can return shared1 */
if (STR_SHARED_P(str)) { /* shared1 is also a shared string */
    str_make_independent(str);  /* no frozen check */
}
```

If `shared1` was the only reference to `root`, then `root` can be
reclaimed by the GC, leaving `shared2` in a corrupted state:

```
 -----------                         --------------------
 | shared1 | -------- owns --------> | shared1's buffer |
 -----------                         --------------------
      ^
      |
 -----------                         -------------------------
 | shared2 | ------ references ----> | root's buffer (freed) |
 -----------                         -------------------------
```

Here is a reproduction script for the situation this commit fixes.

```ruby
a = ('a' * 24).strip.freeze.strip
-a
p a
4.times { GC.start }
p a
```

 - string.c (str_duplicate): always share with the root string when
   the original is a shared string.
 - test_rb_str_dup.rb: specifically test `rb_str_dup` to make
   sure it does not try to share with a shared string.

[Bug #15792]

Closes: https://github.com/ruby/ruby/pull/2159
2019-05-09 10:04:19 +09:00
mame 76fc1ce0a7 The combination of non-Symbol keys and Symbol keys is now allowed again
Revert r64358.  [Bug #15658]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-11 12:48:33 +00:00
nobu e5f01dab9d numeric.c: fix infinite loop
* numeric.c (int_pow): fix infinite loop in the case of y equal 1
  and power of x does not overflow.
  [ruby-core:91734] [Bug #15651]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-11 01:37:16 +00:00
nobu 1598b5e7b3 Symbol creation is not a problem now unless pinned down
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-06 11:49:53 +00:00
normal 23444302d9 introduce rb_nogvl C-API to mark ubf as async-signal-safe
zlib and bignum both contain unblocking functions which are
async-signal-safe and do not require spawning additional
threads.

We can execute those functions directly in signal handlers
without incurring overhead of extra threads, so provide C-API
users the ability to deal with that.  Other C-API users may
have similar need.

This flexible API can supercede existing uses of
rb_thread_call_without_gvl and rb_thread_call_without_gvl2 by
introducing a flags argument to control behavior.

Note: this API is NOT finalized.  It needs approval from other
committers.  I prefer shorter name than previous
rb_thread_call_without_gvl* functions because my eyes requires
big fonts.

[Bug #15499]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-04 13:14:11 +00:00
k0kubun f9dc0fb649 test_iseq_load.rb: increase timeout for stressful roundtrip
Even 60s is short for our CI environments:
https://rubyci.org/logs/rubyci.s3.amazonaws.com/amazon/ruby-trunk/log/20181228T153002Z.fail.html.gz

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-29 01:53:10 +00:00
k0kubun 6e85a0ea7e test_iseq_load.rb: increase timeout for RubyCI
https://rubyci.org/logs/rubyci.s3.amazonaws.com/arch/ruby-trunk/log/20181228T090001Z.fail.html.gz

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-28 13:20:38 +00:00
mrkn 68bdef0041 Add test cases of rb_arithmetic_sequence_extract
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12 21:17:04 +00:00
nobu 98ff2bbd7a Show diff in failure messages
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 05:29:07 +00:00
k0kubun e38a0b4606 revisit more MJIT test skips
r65308 passed both trunk-mjit and trunk-mjit-wait CIs. MJIT copy job
looks working fine. Then this commit skips 5 more tests. Some of them
were skipped in a very early stage and may still need to be skipped, but
I want to confirm them since they haven't been changed for a long time.

And this prefers having inline information on `RubyVM::MJIT.enabled?`.
This commit makes it easier to confirm whether there's suspicious test
skip by RubyVM::MJIT.enabled? or not.

After this commit, tentatively we're not skipping tests for MJIT other
than `assert_no_memory_leak` ones.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22 15:49:22 +00:00
k0kubun e91be25644 revert revert of r65285
because CI was actually hitting another one.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21 23:20:32 +00:00
k0kubun cfa7e2707e revert r65285
because it didn't work. Partially leaving "sometimes fail" tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21 23:07:18 +00:00
k0kubun e6202c41b5 try to remove some test skips for MJIT
Eric Wong made some effort to keep compatibility around fd with MJIT.
Also I'm hoping r65279 (and r65280) eliminates major MJIT bugs, so I
want to start solely testing MJIT. Other test skips branched by MJIT
enablement seemed reasonable to me.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21 15:54:50 +00:00
svn 02cb9c932a * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-21 06:41:09 +00:00