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

320 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 689dd3aecb parse_rat: 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
卜部昌平 d7eec15f8e rb_rational_cmp: 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
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平 32623150cd reroute redefinition of NDEBUG
NDEBUG can be defined via a command-line argument.  Should take care of
such situations.
2020-04-21 13:07:19 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +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
Kenta Murata 07ce51c5aa
internal/rational.h: insert assertions in RATIONAL_SET_{NUM,DEN} 2020-01-17 10:06:58 +09:00
Kenta Murata fbc00c2d86
rational.c: remove nurat_s_new 2020-01-17 10:06:19 +09:00
Kenta Murata 019a0ed0c7
Make RATIONAL_SET_{NUM,DEN} static inline functions 2020-01-17 10:04:19 +09:00
卜部昌平 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
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 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 52bd4716b4
rb_numeric_quo: support Complex 2019-08-10 23:19:24 +09:00
Nobuyoshi Nakada 4ea5c5610a
Predefine some IDs 2019-08-03 10:18:39 +09:00
Nobuyoshi Nakada 9921b63ac4
Make float_decode_internal mantissa int 2019-08-02 19:04:38 +09:00
Nobuyoshi Nakada 6640eeb6db
Deduplicate common code 2019-08-02 18:11:05 +09:00
Nobuyoshi Nakada 19006b711d
Expanded f_quo 2019-08-02 11:28:24 +09:00
Nobuyoshi Nakada f9a0492b76
Expanded f_ceil 2019-08-02 11:26:58 +09:00
Nobuyoshi Nakada ffe4a6ebf9
Use RB_INTEGER_TYPE_P 2019-08-02 11:26:58 +09:00
Nobuyoshi Nakada 6de61fb9ed
Expanded f_mod 2019-08-02 11:26:51 +09:00
Nobuyoshi Nakada ca524bcd49
Expanded f_numerator 2019-07-16 08:15:05 +09:00
Nobuyoshi Nakada 34019a22eb
Expanded f_denominator 2019-07-16 07:59:30 +09:00
Nobuyoshi Nakada 3e7d002118
Check exception flag as a bool [Bug #15987] 2019-07-11 20:04:29 +09:00
nobu 62c17a2f21 No TypeError at nil if exception: false
[ruby-core:91021] [Bug #15525]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-12 05:02:58 +00:00
nobu bc27f87889 Remove duplicate macro definition
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 08:43:50 +00:00
mrkn 673ff731c1 complex.c: Optimize Complex#* and Complex#**
Optimize f_mul for the core numeric class components.
This change improves the computation time of Complex#* and Complex#**.

```
$ make benchmark ITEM=complex_float_ COMPARE_RUBY=/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby
generating known_errors.inc
known_errors.inc unchanged
/Users/mrkn/src/github.com/ruby/ruby/revision.h unchanged
/Users/mrkn/.rbenv/shims/ruby --disable=gems -rrubygems -I/Users/mrkn/src/github.com/ruby/ruby/benchmark/lib /Users/mrkn/src/github.com/ruby/ruby/benchmark/benchmark-driver/exe/benchmark-driver \
                    --executables="compare-ruby::/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby -I.ext/common --disable-gem" \
                    --executables="built-ruby::./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common  -r/Users/mrkn/src/github.com/ruby/ruby/prelude --disable-gem" \
                    $(find /Users/mrkn/src/github.com/ruby/ruby/benchmark -maxdepth 1 -name '*complex_float_*.yml' -o -name '*complex_float_*.rb' | sort)
Calculating -------------------------------------
                     compare-ruby  built-ruby
   complex_float_add       6.558M     13.012M i/s -      1.000M times in 0.152480s 0.076850s
   complex_float_div     576.821k    567.969k i/s -      1.000M times in 1.733640s 1.760660s
   complex_float_mul       1.690M      2.628M i/s -      1.000M times in 0.591786s 0.380579s
   complex_float_new       1.350M      1.268M i/s -      1.000M times in 0.740669s 0.788762s
 complex_float_power       1.571M      1.835M i/s -      1.000M times in 0.636507s 0.544909s
   complex_float_sub       8.635M      8.779M i/s -      1.000M times in 0.115814s 0.113906s

Comparison:
                complex_float_add
          built-ruby:  13012361.7 i/s
        compare-ruby:   6558237.1 i/s - 1.98x  slower

                complex_float_div
        compare-ruby:    576821.0 i/s
          built-ruby:    567968.8 i/s - 1.02x  slower

                complex_float_mul
          built-ruby:   2627575.4 i/s
        compare-ruby:   1689800.0 i/s - 1.55x  slower

                complex_float_new
        compare-ruby:   1350130.8 i/s
          built-ruby:   1267809.6 i/s - 1.06x  slower

              complex_float_power
          built-ruby:   1835168.8 i/s
        compare-ruby:   1571074.6 i/s - 1.17x  slower

                complex_float_sub
          built-ruby:   8779168.8 i/s
        compare-ruby:   8634534.7 i/s - 1.02x  slower
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-03 06:19:17 +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
shyouhei bc64df876e delete emacs mode lines [ci skip]
These settings are now covered by .dir-locals.el.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-27 06:12:09 +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
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 4b85e88174 Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04 02:24:15 +00:00
nobu ed778c2a89 rational.c (nurat_div): use the dedicated function nurat_to_f
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-14 14:12:30 +00:00
svn 33758ded08 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-14 09:53:13 +00:00
shyouhei a6e887153e numeric.c: avoid division by zero
same as r65642.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-14 09:53:11 +00:00
nobu 17e9667fe9 refine parse_rat
* rational.c (read_num): return the exponent instead of the
  divisor, to get rid of huge bignums.

* rational.c (parse_rat): subtract exponents instead of reduction
  of powers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 02:25:44 +00:00
nobu b4bbfe4bb9 complex.c: small optimization of Complex#**
* complex.c (rb_complex_pow): calculate power of a Fixnum without
  allocating intermediate Complex objects, and avoid unexpected
  NaNs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 02:49:18 +00:00
nobu 6918746e46 Remove wrong conversion
* rational.c (nurat_to_double): should return `double`, not `Float`.
  fix r64897.  [Bug #15189]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64919 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-05 00:37:40 +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 36c4713e31 rational.c: may be float
* rational.c (f_muldiv): Integer#** can return Rational with Float
  right now.  [ruby-core:89212] [Bug #15175]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-29 00:45:41 +00:00
nobu 85aee954f8 Split assertion expressions
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-29 00:43:29 +00:00
nobu 52a23d56ad rational.c: remove duplicate macros
* rational.c (RRATIONAL_SET_{NUM,DEN}): also defined in internal.h
  since r53887.

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-01 07:34:31 +00:00
mrkn 0dc74b94c2 Add `exception:` keyword in Kernel#Rational()
Support `exception:` keyword argument in `Kernel#Rational()`.
If `exception:` is `false`, `Kernel#Rational()` returns `nil` if the given
value cannot be interpreted as a rational 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@62759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15 07:19:46 +00:00
nobu 576b245ffa Removed useless assertions [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-09 03:51:04 +00:00
nobu 00f82af5ed rational.c: removed redundant conditions
Fixnums can be compared by object values themselves only.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-09 03:02:08 +00:00
nobu b479a2d439 complex.c, rational.c: no backref
Since r37702, parsing complex and rational do not use regexp.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07 11:49:24 +00:00
nobu 6010d756c0 complex.c, rational.c: adjust indent
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07 11:49:23 +00:00