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

554 Коммитов

Автор SHA1 Сообщение Дата
S.H dc9112cf10
Using NIL_P macro instead of `== Qnil` 2021-10-03 22:34:45 +09:00
S.H b8c3a84bdd
Refactor and Using RBOOL macro 2021-09-15 08:11:05 +09:00
卜部昌平 dddc618d30 suppress GCC's -Wsuggest-attribute=format
I was not aware of this because I use clang these days.
2021-09-10 20:00:06 +09:00
卜部昌平 1b6245ccdc include/ruby/internal/error.h: add doxygen
Must not be a bad idea to improve documents.
2021-09-10 20:00:06 +09:00
Kazuki Tsujimoto 4568ba0711
Show verbose error messages when single pattern match fails
[0] => [0, *, a]
    #=> [0] length mismatch (given 1, expected 2+) (NoMatchingPatternError)

Ignore test failures of typeprof caused by this change for now.
2021-08-15 09:38:24 +09:00
Nobuyoshi Nakada 97efd48fb1
Get rid of unintented recursion when RUBY_DEBUG 2021-08-14 23:12:31 +09:00
Nobuyoshi Nakada 1bd021a789 Mark internal class names 2021-08-14 23:11:58 +09:00
Nobuyoshi Nakada 58d82eacef Add some "cold" marks 2021-08-14 23:11:58 +09:00
Nobuyoshi Nakada edd27e120e A comment for typed data in `rb_check_type` [ci skip] 2021-08-14 23:11:58 +09:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
Kazuhiro NISHIYAMA 2e67043041
Use UNREACHABLE instead of fall through 2021-07-20 14:46:46 +09:00
Kazuhiro NISHIYAMA 036f26a4e2
Add `fall through`
Pointed out by Coverity Scan

```
** CID 1487522: Control flow issues (MISSING_BREAK)
/error.c: 1273 in exc_full_message()
```
2021-07-19 17:21:45 +09:00
Nobuyoshi Nakada 8a6ef5ef8f
Make boolean expected messages more consitent 2021-07-18 20:51:30 +09:00
Nobuyoshi Nakada 94bd3bde81 Specify version to remove as bare numbers 2021-06-30 10:47:01 +09:00
Nobuyoshi Nakada 0b726924a4 Show the removal version 2021-06-30 10:47:01 +09:00
Nobuyoshi Nakada 8118d435d0 rb_warn_deprecated_to_remove_at [Feature #17432]
At compilation time with RUBY_DEBUG enabled, check if the removal
version has been reached.
2021-06-30 10:47:01 +09:00
Adam Daniels f64d7674f6 Fix example for custom warn method
Regexp has a match? method.

[ci skip]
2021-04-30 17:13:04 -07:00
S-H-GAMELINKS e398a0e53a Remove unneeded rb_ident_hash_new function declaration 2021-03-28 08:50:25 +09:00
Kenichi Kamiya 0a544c0c35
Fix segmentation fault when `Module#name` returns non string value [Bug #17754]
* Add test for NoMethodError#to_s does not segfault

* Ensure no segfault even if Module#name is overridden
2021-03-28 08:47:42 +09:00
Garen Torikian 34c422b678 Fix grammatical error 2021-02-06 13:02:17 -05:00
Nobuyoshi Nakada 1cdae49d39 Implement NameError::message#clone for Ractor 2021-02-01 19:54:21 +09:00
xtkoba (Tee KOBAYASHI) 0e5fbec816
Fixed varargs in `rb_bug_without_die` [Bug #17603] 2021-02-01 13:47:35 +09:00
Nobuyoshi Nakada 2556cd3f51 Bypass check for warning_category on internal calls 2020-12-28 12:44:03 +09:00
Kazuki Tsujimoto 31b17a14ab
Make NoMatchingPatternError a subclass of StandardError 2020-12-23 02:31:02 +09:00
卜部昌平 c30f03d328 Data: delete
Has been deprecated since 684bdf6171.

Matz says in [ruby-core:83954] that Data should be an alias of Object.
Because rb_cData has not been deprecated, let us deprecate the constant
to make it a C-level synonym of rb_cObject.
2020-12-22 02:51:49 +09:00
Jeremy Evans 7e2dbbda35 Use category: :experimental in warnings that are related to experimental features
This adds rb_category_compile_warn in order to emit compiler warnings
with categories.  Note that Ripper currently ignores the category
for these warnings, but by default it ignores the warnings completely,
so this shouldn't matter.
2020-12-18 09:54:11 -08:00
Jeremy Evans 6ced55b07c Make warning_categories a map of category symbols to category numbers
Use this to simplify rb_warning_category_from_name.

This also adds support for using the :experimental category in
Kernel#warn and Warning.warn.
2020-12-18 09:54:11 -08:00
Jeremy Evans 52fb696ee7 Switch rb_category_warn{,ing} to accept an rb_warning_category_t
Since we decided to only allowing specific warning categories,
there is no reason to have an API that accepts a general string,
as it is more error-prone.  Switch to only allowing the specific
warning categories.

As rb_category_warn{,ing} are public API, this requires making
rb_warning_category_t public API as well.
2020-12-18 09:54:11 -08:00
Nobuyoshi Nakada ce6fafb8cc
Cache warning category IDs 2020-12-15 15:19:23 +09:00
Alan Wu befa24488c Help RDoc find Exception [ci skip]
This was on top of `Init_Exception()`.
2020-12-14 20:01:01 -05:00
Nobuyoshi Nakada 2749123e21
Supported category option in Warning#warn 2020-12-08 22:50:45 +09:00
Nobuyoshi Nakada d7a16670c3
[DOC] Fixed RDoc directives [ci skip] 2020-12-08 18:02:31 +09:00
Takashi Kokubun 4dbf6f1e51
Call rb_bug_without_die on CI
when GC.compact's SEGV handler is installed
2020-11-26 20:09:57 -08:00
Benoit Daloze cffdacb15a Ignore <internal: entries from core library methods for Kernel#warn(message, uplevel: n)
* Fixes [Bug #17259]
2020-10-26 08:47:33 +01:00
Nobuyoshi Nakada 5a77e90fe8
Use rb_intern_const instead of rb_intern in Init functions
```
find . -name \*.o -exec nm {} + |&
sed '/Init_.*\.rbimpl_id/!d;s/^.* b //;s/\.[1-9][0-9]*$//;s/\.rbimpl_id$//' |
uniq
```
should be empty.
2020-10-21 12:46:53 +09:00
Benoit Daloze d0778cb264 Update example to handle keywords passed to Warning.warn 2020-10-03 13:19:24 +02:00
Benoit Daloze 112254d185 Improve docs of the Warning module 2020-10-02 18:32:42 +02:00
Jeremy Evans 346301e232 Add rb_category_warn{,ing} for warning messages with categories
This adds the following C-API functions that can be used to emit
warnings with categories included:

```c
void rb_category_warn(const char *, const char*, ...)
void rb_category_warning(const char*, const char*, ...)
```

Internally in error.c, there is an rb_warn_category function
that will call Warning.warn with the string and the category
keyword if it doesn't have an arity of 1, and will call
Warning.warn with just the string if it has an arity of 1.
This refactors the rb_warn_deprecated{,_to_remove} functions
to use rb_warn_category.

This makes Kernel#warn accept a category keyword and pass it
to Warning.warn, so that Ruby methods can more easily emit
warnings with categories.  rb_warn_category makes sure that
the passed category is a already defined category symbol
before calling Warning.warn.

The only currently defined warning category is :deprecated,
since that is what is already used.  More categories can be
added in later commits.
2020-09-28 08:38:06 -07:00
Jeremy Evans 92c3ad9c27 Make Warning.warn accept only category keyword
In general accepting arbitrary keywords is a bad idea unless you are
delegating keywords or acting on arbitrary keywords.  In this case,
the category keyword is ignored, and it's less error prone to not
ignore all keywords.
2020-09-28 08:38:06 -07:00
Nobuyoshi Nakada 996af2ce08 Disable deprecation warning by the default [Feature #16345]
And `-w` option turns it on.
2020-09-25 09:50:33 +09:00
Kazuhiro NISHIYAMA b2b855f486
Fix `warning: instance variable bt_locations not initialized` 2020-09-15 14:03:41 +09:00
Kazuhiro NISHIYAMA f3754dfc2e
Fix missing `"` [ci skip] 2020-09-15 14:03:22 +09:00
Yusuke Endoh 369cfabd59 Make it possible to dump and load an exception object
A backtrace object in an exception had never supported marshalling
correctly: `Marshal.load(Marshal.dump(exc)).backtrace_locations` dumped
core.

An Exception object has two hidden instance varibles for backtrace data:
one is "bt", which has an Array of Strings, and the other is
"bt_locations", which has an Array of Thread::Backtrace::Locations.
However, Exception's dump outputs data so that the two variables are the
same Array of Strings. Thus, "bt_locations" had a wrong-type object.

For the compatibility, it is difficult to change the dump format.  This
changeset fixes the issue by ignoring data for "bt_locations" at the
loading phase if "bt_locations" refers to the same object as "bt".

Future work: Exception's dump should output "bt_locations"
appropriately.

https://bugs.ruby-lang.org/issues/17150
2020-09-06 13:57:41 +09:00
Nobuyoshi Nakada eeb5325d3b
Hoisted out warn_deprecated 2020-09-03 18:51:48 +09:00
eileencodes eada635033 Add category to `rb_warn_deprecated`
PR https://github.com/ruby/ruby/pull/3418 added a category to
`rb_warn_deprecated_to_remove` but not to `rb_warn_deprecated`. This
adds the same code to `rb_warn_deprecated` so that those warnings also
get a category.

This change also adds tests for `rb_warn_deprecated` and updates the
tests for `rb_warn_deprecated_to_remove` to have clearer names.

I've fixed the call to `rb_method_entry` as we need to be using the
instance method, not singleton.

Feature: https://bugs.ruby-lang.org/issues/17122
2020-09-02 12:44:33 -07:00
eileencodes 6e8ec9ab6d Support passing a category to `Warning.warn`
This change adds a `category` kwarg to make it easier to monkey patch
`Warning.warn`. Warnings already have a category, but that warning isn't
exposed. This implements a way to get the category so that warnings with
a specific category, like deprecated, can be treated differently than
other warnings in an application.

The change here does an arity check on the method to support backwards
compatibility for applications that may already have a warning monkey
patch.

For our usecase we want to `raise` for deprecation warnings in order to
get the behavior for the next Ruby version. For example, now that we
fixed all our warnings and deployed Ruby 2.7 to production, we want to
be able to have deprecation warnings behave like they would in 3.0: raise
an error. For other warnings, like uninialized constants, that behavior
won't be removed from Ruby in the next version, so we don't need to
raise errors.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2020-09-01 16:16:06 -07:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平 801752f577 builtin_class_name: add variant that return VALUE
Found that `if (builtin_class_name) { printf } else { printf }` happens
twice.  It would be better if we could eliminate those if statements.
2020-06-29 11:05:41 +09:00
卜部昌平 a2677815f5 rb_check_typeddata: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Nobuyoshi Nakada a447563cf8
[DOC] Added Exception.exception to Exception.new [ci skip] 2020-06-18 11:36:21 +09:00