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

473 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 0e8219f591 make functions static
These functions are used from within a compilation unit so we can
make them static, for better binary size.  This changeset reduces
the size of generated ruby binary from 26,590,128 bytes to
26,584,472 bytes on my macihne.
2019-11-19 12:36:19 +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
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.

This modifies some internal functions that took a safe level argument
to no longer take the argument.

rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.

One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd.  We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
2019-11-18 01:00:25 +02:00
卜部昌平 c9ffe751d1 delete unused functions
Looking at the list of symbols inside of libruby-static.a, I found
hundreds of functions that are defined, but used from nowhere.

There can be reasons for each of them (e.g. some functions are
specific to some platform, some are useful when debugging, etc).
However it seems the functions deleted here exist for no reason.

This changeset reduces the size of ruby binary from 26,671,456
bytes to 26,592,864 bytes on my machine.
2019-11-14 20:35:48 +09:00
卜部昌平 3f413896c3 forgot to delete unused #incude line 2019-10-10 18:15:33 +09:00
卜部昌平 2d393bf125 guard rb_fatal against non-GVL call
Suggested by ko1.  rb_fatal requires GVL so just in case one lacks,
print that information and let the process die.  As commented,
we cannot print the given messages on such situations.
2019-10-10 17:49:31 +09:00
卜部昌平 f1ce4897f2 make rb_raise a GVL-only function again
Requested by ko1 that ability of calling rb_raise from anywhere
outside of GVL is "too much".  Give up that part, move the GVL
aquisition routine into gc.c, and make our new gc_raise().
2019-10-10 17:10:21 +09:00
卜部昌平 d96f04d73a add "[FATAL]" marker on abort
Indicate that the situation is fatal.
2019-10-10 17:10:21 +09:00
卜部昌平 9c3153e0da allow rb_raise from outside of GVL
Now that allocation routines like ALLOC_N() can raise exceptions
on integer overflows.  This is a problem when the calling thread
has no GVL.  Memory allocations has been allowed without it, but
can still fail.

Let's just relax rb_raise's restriction so that we can call it
with or without GVL.  With GVL the behaviour is unchanged.  With
no GVL, wait for it.

Also, integer overflows can theoretically occur during GC when
we expand the object space.  We cannot do so much then.  Call
rb_memerror and let that routine abort the process.
2019-10-10 12:07:38 +09:00
Nobuyoshi Nakada 29e6782f5d
Share ruby_sighandler_t definition 2019-10-09 23:39:58 +09:00
Yusuke Endoh 891cbd66a4 signal.c: save the original sighandlers for fatal signals
On Android, a signal handler that is not SIG_DFL is set by default for
SIGSEGV.  Ruby's install_sighandler inserts Ruby's handler only when the
signal has no handler, so it does not insert Ruby's SEGV report handler,
which caused some test failures.

This changeset forces to install Ruby's handler for some fatal signals
(sigbus, sigsegv, and sigill).  They keep the original handlers, and
call them when the interpreter receives the signals.
2019-10-09 23:22:15 +09:00
Yusuke Endoh dd477df411 error.c (rb_bug_for_fatal_signal): renamed from rb_bug_context
Just refactoring.

The name "rb_bug_context" is completely unclear for me.
(Can you see that "context" means "machine register context"?)
The context is available only when a fatal signal (sigbus, sigsegv, or
sigill) is received; in fact, the function is used only for fatal
signals.  So, I think the name should be changed.
2019-10-09 23:02:22 +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
Jeremy Evans 00744a03d5 Update documentation for Exception [ci skip]
Mostly from burdettelamar@yahoo.com (Burdette Lamar).

Implements [Misc #16156]
2019-09-09 15:23:26 -07:00
Nobuyoshi Nakada 8b2e1ca10e
Do not clear backtrace in Exception#exception
[Bug #15558]
2019-09-02 16:47:12 +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
Nobuyoshi Nakada b4daa44270
Use modifier for pid_t 2019-08-19 16:32:57 +09:00
Koichi Sasada 53a55aeff3
introduce RUBY_ON_BUG envval. (#2331)
`rb_bug()` is called at critical bug, MRI can't run anymore.
To make debug easy, this patch introduces RUBY_ON_BUG environment
variable to specify the process which is called with pid.
[Feature #16090] [GH #2331]

  RUBY_ON_BUG='gdb -p' ruby xxx.rb

In this case, if ruby interpreter causes critical bug, and call
rb_bug(), then "gdb -p [PID]' is called by system(3). You can
debug on invoked gdb.

This feature is limited on RUBY_DEVEL build.
2019-08-15 13:48:58 +09:00
Steven Harman 7da40d74e1 backtrace and backtrace_locations can be nil (#2358)
Exception#backtrace and Exception#backtrace_locations can both be nil if
not set. The former can be set via `Exception#set_backtrace`, but the
later is only ever set at runtime via `setup_backtrace`.
2019-08-14 10:35:47 -04:00
Jeremy Evans 404850e134 Remove documentation that fatal cannot be rescued [ci skip]
You can rescue it:

f = ObjectSpace.each_object(Class){|c| break c if c.name == 'fatal'}
begin
  raise f
rescue f
  2
end # => 2

It's not a good idea to rescue fatal exceptions you didn't generate
yourself, though.

Fixes [Bug #10691]
2019-08-12 09:56:35 -07:00
Nobuyoshi Nakada 4ea5c5610a
Predefine some IDs 2019-08-03 10:18:39 +09:00
git bdc8b3789a * expand tabs. 2019-06-13 18:07:19 +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
Nobuyoshi Nakada 1624d77f3e
error.c: avoid infinite recursion at inspecting the frozen object 2019-06-05 13:31:09 +09:00
git 7c776038ec * expand tabs. 2019-06-05 11:29:04 +09:00
Jeremy Evans f1f04caf60 Include inspect value of object in FrozenError messages
FrozenError#receiver was added recently for getting the related
object programmatically.  However, there are cases where FrozenError
is raised and not handled, and in those cases the resulting error
messages lack detail, which makes debugging the error more difficult,
especially in cases where the error is not easily reproducible.
This includes the inspect value of the frozen object in FrozenError
messages, which should make debugging simpler.
2019-06-04 19:25:03 -07:00
git 5a6c77bbe8 * expand tabs. 2019-05-27 03:10:15 +09:00
Jeremy Evans 39eadca76b Add FrozenError#receiver
Similar to NameError#receiver, this returns the object on which
the modification was attempted.  This is useful as it can pinpoint
exactly what is frozen.  In many cases when a FrozenError is
raised, you cannot determine from the context which object is
frozen that you attempted to modify.

Users of the current rb_error_frozen C function will have to switch
to using rb_error_frozen_object or the new rb_frozen_error_raise
in order to set the receiver of the FrozenError.

To allow the receiver to be set from Ruby, support an optional
second argument to FrozenError#initialize.

Implements [Feature #15751]
2019-05-26 11:09:21 -07:00
ktsj 9738f96fcf Introduce pattern matching [EXPERIMENTAL]
[ruby-core:87945] [Feature #14912]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 06:48:03 +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
naruse a8c0f27276 Remove message to recommend to repot bug
This message is showed on SEGV, but it is usually caused by 3rd party
libraries and we don't help reporters well. I concluded this message
doesn't help users as expected.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67061 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-13 04:32:03 +00:00
svn 497075b3a1 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-08 09:08:37 +00:00
nobu 50784a0a44 Defer escaping control char in error messages
* eval_error.c (print_errinfo): defer escaping control char in
  error messages until writing to stderr, instead of quoting at
  building the message.  [ruby-core:90853] [Bug #15497]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-08 09:08:31 +00:00
nobu 2eee74ef54 Update NoMethodError/NameError docs [ci skip]
[ruby-core:90796] [Bug #15481]

From: zverok (Victor Shepelev) <zverok.offline@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-29 23:40:15 +00:00
nobu 75584ceb56 A couple of small English fixes [ci skip]
[Fix GH-2052]

From: Jon Burgess <jkburges@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-20 21:17:11 +00:00
nobu 98e65d9d92 Prefer rb_check_arity when 0 or 1 arguments
Especially over checking argc then calling rb_scan_args just to
raise an ArgumentError.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 07:49:24 +00:00
nobu 8748fe7cf0 Fix documentation for Warning.warn [ci skip]
Warning.warn does not add any newlines to the message argument.
[Bug #15379]

From: Olle Jonsson <olle.jonsson@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05 01:19:23 +00:00
nobu b549d14c00 Add rb_typeddata_is_instance_of
Similar to rb_typeddata_is_kind_of, except for that inherited type
is not an instance.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27 03:19:06 +00:00
nobu fa8b08b424 Prefer `rb_fstring_lit` over `rb_fstring_cstr`
The former states explicitly that the argument must be a literal,
and can optimize away `strlen` on all compilers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13 09:59:22 +00:00
kazu 1a38555cda Use https instead of http
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11 09:46:49 +00:00
nobu 985961769d Fix message when `order` was an invalid value
The symbol that can be used is `:bottom`, not `:down`.
Ref: e39b2cff8a/error.c (L1061)

[Fix GH-1916]

From: yuuji.yaginuma <yuuji.yaginuma@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-17 01:22:32 +00:00
kazu 400e5e332e [DOC] Update doc of NameError.new [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-16 15:06:14 +00:00
eregon fe7ec526f3 Fix condition in Kernel#warn when using uplevel
* It causes SEGV on `warn("foo", uplevel: 100)`.
* Found in a ruby/spec added by @andrykonchin in
  https://github.com/ruby/spec/pull/605

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-13 21:17:48 +00:00
nobu 02c1358be5 share :cause variable
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-15 07:45:24 +00:00
nobu 6f0de6ed98 error.c: check redefined backtrace result
* error.c (rb_get_backtrace): check the result of `backtrace` even
  if the method is redefined.  [ruby-core:87013] [Bug #14756]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-14 08:33:14 +00:00
stomar f10a13484a error.c: [DOC] minor fixes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-14 16:46:58 +00:00
nobu 8ef4ff1b15 error.c: fix for DRb
* error.c (name_err_init_attr): hide the receiver object from
  Marshal, as DRb depends on it.

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

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

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-12 03:48:48 +00:00
nobu aa2b32ae4b eval_error.c: fix loop on exception in message
* error.c (rb_get_message): accessor to the message.

* eval_error.c (rb_ec_error_print): handle exceptions on fetching
  the message.  [Bug #14566]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-11 08:03:43 +00:00
nobu bae19b5547 error.c: prepend "warning: " always
* error.c (rb_warn_m): prepend the string "warning: " if uplevel
  keyword is given, even if caller file and line information are
  not available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-02 11:39:10 +00:00