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

1626 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 3eb05a8071 fix compiler error on gcc 4.x
It seems gcc prior to 5 suffered from preprocessor bug.  We have to
provide workarounds.

See https://github.com/ruby/ruby/runs/591138012

----

Here is something interesting.  According to C99, strictly speaking,
the gcc behaviour was in fact legal(!) and everything else were
wrong.  This was not a bug of gcc, rather a bug of the ISO C Standard.
This defect was reported to the committee as DR#412, and fixed
accordingly.  All tested compilers now conform C17's updated
preprocessor description.

See http://www.open-std.org/JTC1/SC22/WG14/www/docs/dr_412.htm
2020-04-16 17:19:37 +09:00
卜部昌平 48273534c7 Support for FreeBSD <sys/cdefs.h>
FreeBSD's <sys/cdefs.h> is broken.  Cygwin is also affected by that.
We need to avoid using them.

See also:
d1c67819db
https://sourceware.org/git/?p=newlib-cygwin.git;a=commit;f=newlib/libc/include/sys/cdefs.h;h=44d6d53977e6bc82c2b1e6dbe8ae7f310b260604
2020-04-16 14:22:15 +09:00
卜部昌平 c37a357c13 include what you use.
This reverts commit 443389effc.
This reverts commit d94960f22e.

Inclusion of header files must be explicit.  Every file shall directly
include what is necessary.

https://github.com/include-what-you-use/include-what-you-use says:

> When every file includes what it uses, then it is possible to edit any
> file and remove unused headers, without fear of accidentally breaking
> the upwards dependencies of that file. It also becomes easy to
> automatically track and update dependencies in the source code.

Though we don't use iwyu itself, the principle quoted above is a good
thing that we can agree.

Now that include guards were added to every and all of the headers
inside of our project this changeset does not increase compile time, at
least on my machine.
2020-04-13 16:06:00 +09:00
卜部昌平 4ff3f20540 add #include guard hack
According to MSVC manual (*1), cl.exe can skip including a header file
when that:

- contains #pragma once, or
- starts with #ifndef, or
- starts with #if ! defined.

GCC has a similar trick (*2), but it acts more stricter (e. g. there
must be _no tokens_ outside of #ifndef...#endif).

Sun C lacked #pragma once for a looong time.  Oracle Developer Studio
12.5 finally implemented it, but we cannot assume such recent version.

This changeset modifies header files so that each of them include
strictly one #ifndef...#endif.  I believe this is the most portable way
to trigger compiler optimizations. [Bug #16770]

*1: https://docs.microsoft.com/en-us/cpp/preprocessor/once
*2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
2020-04-13 16:06:00 +09:00
Nobuyoshi Nakada 4c8e3f1241
Make rb_scan_args implementations same
between rb_scan_args_set and rb_scan_args_assign +
rb_scan_args_result.
2020-04-12 23:29:22 +09:00
卜部昌平 108d392efd RUBY3_HAS_ATTRIBUTE: fix fallbacks
Same as 133ae0807d
2020-04-10 23:07:23 +09:00
卜部昌平 b18a6b648e include/ruby/3: do not skip RUBY3_UNREACHABLE_RETURN
Revert "Revert "include/ruby/3/core/rtypeddata.h: Use 0 instead of NULL for C++ compiler""
Revert "include/ruby/3/core/rtypeddata.h: Use 0 instead of NULL for C++ compiler"
Revert "include/ruby/3: Skip RUBY3_UNREACHABLE_RETURN for icc"
Revert "include/ruby/3: Stop RUBY3_UNREACHABLE_RETURN to suppress a SunC warning"

This reverts commit b965e7e05e.
This reverts commit d2bb2e066b.
This reverts commit 8ab4c55e7a.
This reverts commit 78eec3cdc5.

After https://github.com/ruby/ruby/pull/3011, we no longer need these
ifdef guards.
2020-04-10 22:12:19 +09:00
卜部昌平 4e7d84cf87 ruby3_rstring_getmem: suppres warning
icc warns at this line.

> include/ruby/3/core/rstring.h(126): warning #413: variable "retval" has an uninitialized const field
>           struct RString retval;
>                          ^

This must not be a problem because uninitialized const field is not used
at all.  But the warnings are annoying.  Let us suppress them.
2020-04-10 16:17:30 +09:00
卜部昌平 3e92785fd6 RUBY3_ASSUME: suppress warnings on icc
icc warns side effects for RUBY3_ASSUME like this:

> ./include/ruby/3/value_type.h(202): warning #2261: __assume expression with side effects discarded
>           RUBY3_ASSUME(RB_FLONUM_P(obj));
>                        ^

Which is a false positive (RB_FLONUM_P has no side effect).  It seems
there is no way for us to tell icc that a functin is safe inside of
__assume.   Just suppress the warning instead.
2020-04-10 16:17:30 +09:00
卜部昌平 133ae0807d RUBY3_HAS_BUILTIN: fix __builtin_unreachable
This macro has to be truthy, otherwise the `+0` trick above evalues
RUBY3_HAS_BUILTIN(__builtin_unreachable) to be always false.
2020-04-10 16:17:30 +09:00
Koichi Sasada 443389effc reduce duplicate include.
Without this patch, 20k files are opened (openat syscall) because
of duplicate includes. This patch reduced it to 3k and build time
was reduced compile time of range.o from 15sec -> 3sec on my machine.
[Bug #16772]
2020-04-10 14:53:25 +09:00
Yusuke Endoh b965e7e05e Revert "include/ruby/3/core/rtypeddata.h: Use 0 instead of NULL for C++ compiler"
This reverts commit d2bb2e066b.

It didn't work:

https://rubyci.org/logs/rubyci.s3.amazonaws.com/icc-x64/ruby-master/log/20200409T050004Z.log.html.gz#end
```
In file included from ../../.././include/ruby/3/core.h(32),
                 from ../../.././include/ruby/ruby.h(28),
                 from ../../.././include/ruby.h(33),
                 from init.c(1):
../../.././include/ruby/3/core/rtypeddata.h(164): warning #967: conversion from "int" to "const struct rb_data_type_struct *"; sizes do not match
          RUBY3_UNREACHABLE_RETURN(0);
```
2020-04-09 14:24:23 +09:00
Yusuke Endoh d2bb2e066b include/ruby/3/core/rtypeddata.h: Use 0 instead of NULL for C++ compiler
NULL in C++ is esoteric
2020-04-09 12:50:53 +09:00
Yusuke Endoh 8ab4c55e7a include/ruby/3: Skip RUBY3_UNREACHABLE_RETURN for icc
I'm unsure why, but it fails on icc.

https://rubyci.org/logs/rubyci.s3.amazonaws.com/icc-x64/ruby-master/log/20200408T220004Z.log.html.gz
```
In file included from ../../.././include/ruby/3/core.h(32),
                 from ../../.././include/ruby/ruby.h(28),
                  from cxxanyargs.cpp(1):
../../.././include/ruby/3/core/rtypeddata.h(163): error: return value type does not match the function type
            RUBY3_UNREACHABLE_RETURN(NULL);
```
2020-04-09 08:19:00 +09:00
Yusuke Endoh 78eec3cdc5 include/ruby/3: Stop RUBY3_UNREACHABLE_RETURN to suppress a SunC warning
I don't find how to suppress a false positive "unreachable" warning of
the Sun compiler:

```
"./include/ruby/3/core/rtypeddata.h", line 163: warning: statement not
reached
"./include/ruby/3/memory.h", line 256: warning: statement not reached
```

This warnings make mkmf test fail:

https://rubyci.org/logs/rubyci.s3.amazonaws.com/solaris10-sunc/ruby-master/log/20200408T170004Z.fail.html.gz
```

  1) Failure:
TestMkmf::TestConvertible#test_typeof_builtin
[/export/home/users/chkbuild/cb-sunc/tmp/build/20200408T170004Z/ruby/test/mkmf/test_convertible.rb:9]:
convertible_int: checking for convertible type of short...
-------------------- short

--------------------

convertible_int: checking for convertible type of int...
-------------------- int

--------------------

convertible_int: checking for convertible type of long...
-------------------- long

--------------------

convertible_int: checking for convertible type of signed short...
-------------------- failed

...

"cc -I.
-I/export/home/users/chkbuild/cb-sunc/tmp/build/20200408T170004Z/ruby/.ext/include/sparc-solaris2.10
-I/export/home/users/chkbuild/cb-sunc/tmp/build/20200408T170004Z/ruby/include
-I./test  -I/opt/csw/include -D_XOPEN_SOURCE=600   -DFFI_NO_RAW_API  -g
-c conftest.c"
"/export/home/users/chkbuild/cb-sunc/tmp/build/20200408T170004Z/ruby/include/ruby/3/core/rtypeddata.h",
line 163: warning: statement not reached
"/export/home/users/chkbuild/cb-sunc/tmp/build/20200408T170004Z/ruby/include/ruby/3/memory.h",
line 256: warning: statement not reached
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: typedef signed short rbcv_typedef_;
4:
5: extern rbcv_typedef_ foo();
6: extern short foo();
/* end */
```
2020-04-09 07:37:53 +09:00
卜部昌平 dd04b8034b RARRAY_EMBED_LEN/RSTRING_EMBED_LEN: add RUBY3_CAST
RUBY3_CAST is a macro to suppress g++/clang++ warnings about C-style
casts.  Though Ruby core don't have to bother C++ situations, extension
libraries can benefit from this.
2020-04-08 22:32:02 +09:00
卜部昌平 ec1b3464da RUBY3_HAS_BUILTIN: icc has broken __has_builtin
It turned out that compilation errors in icc were due to their having
broken __has_builtin.  Let's just skip such situations.
2020-04-08 22:30:14 +09:00
Nobuyoshi Nakada 11d5a8318d
Suppress C4244 "possible loss of data" warnings 2020-04-08 18:03:46 +09:00
卜部昌平 6163a4e1b3 RUBY3_HAS_BUILTIN: fix for nonexistent builtin
Trying to fix icc breakage:
https://rubyci.org/logs/rubyci.s3.amazonaws.com/icc-x64/ruby-master/log/20200408T050004Z.fail.html.gz

It seems the macro had problems when a builtin does not exist for the
target compiler.  Force evaluete to 0 then, by adding 0 to the
expression.
2020-04-08 16:18:59 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Derek Argueta ba3eccd9b5 fix typo in documentation 2020-04-06 11:29:12 +12:00
Nobuyoshi Nakada 5b287481be
Removed non-RUBY_INTEGER_UNIFICATION code 2020-03-21 16:59:55 +09:00
K.Takata e89ebdcb87
Fix typos (#2958)
* Fix a typo

* Fix typos in st.[ch]
2020-03-11 00:43:12 -07:00
卜部昌平 ada2f71c70 rb_check_safe_obj no longer exists
Commit e91c39f1c0 deleted definition of it.
Though I'm not sure if we can delete public API like this, it no longer
works nontheless.  Having declaration without definiton is worse than
having nothing at all.  Just delete the declartion too.
2020-03-07 19:06:10 +09:00
卜部昌平 62c2b8c74e kill USE_RGENGC=0
This compile-time option has been broken for years (at least since
commit 49369ef173, according to git
bisect).  Let's delete codes that no longer works.
2020-02-26 16:00:10 +09:00
卜部昌平 7586355423 comma at the end of enum is a C++11ism
Comma at the end of enum is allowed in C since C99. We can use them
internally.  However when it comes to extension libraries, they could be
written in different C++ versions.  We cannot assume sometihng.  Public
headers shall keep compatibilities.
2020-02-20 11:46:54 +09:00
Nobuyoshi Nakada 0742585e7e
Consitified `rb_scan_args_set` 2020-02-14 15:56:37 +09:00
Jeremy Evans 50065dad7f Remove rb_eval_cmd
This was related to $SAFE, and was deprecated in 2.7.  I missed it
earlier when removing the other $SAFE-related code.
2020-02-11 08:46:44 -08:00
Nobuyoshi Nakada db69c50987
Parenthesized macro arguments 2020-02-03 14:19:02 +09:00
Nobuyoshi Nakada 0ab7f2f222
Make `rb_scan_args_kw` inline too 2020-02-03 13:07:34 +09:00
Nobuyoshi Nakada fae537259d
Removed no longer used variable `last_hash`
1. By substituting `n_var` with its initializer, `0 < n_var` is
   equivalent to `argc > argi + n_trail`.
2. As `argi` is non-negative, so `argi + n_trail >= n_trail`, and
   the above expression is equivalent to `argc > n_trail`.
3. Therefore, `f_last` is always false, and `last_hash` is no
   longer used.
2020-02-02 23:09:25 +09:00
卜部昌平 f31dc8a458 a bit terse Doxygen comments [ci skip]
Creative use of `@copydoc` Doxygen command and abusing its half-broken C
parser let us delete some lines of documentations, while preserving
document coverages.
2020-01-31 13:10:55 +09:00
卜部昌平 cdd75d4e7f support C++ std::nullptr_t
C++ keyword `nullptr` represents a null pointer (note also that NULL is
an integer in C++ due to its design flaw).  Its type is `std::nullptr_t`,
defined in <cstddef> standard header.  Why not support it when the
backend implementation can take a null pointer as an argument.
2020-01-31 13:01:52 +09:00
Kazuhiro NISHIYAMA 3023696505
Fix a typo [ci skip] 2020-01-29 08:30:39 +09:00
卜部昌平 83d6487ae5 fix rb_define_global_function to take const VALUE*
It was unable for rb_define_global_function to take VALUE(*)(int argc,
const VLAUE *argv, VALUE self) -style function.  Test added.
2020-01-28 17:29:57 +09:00
卜部昌平 3c3eb418f9 improved support for rb_f_notimplement
rb_f_notimplement should be accepted for all possible arities.

Test provided for that.
2020-01-28 17:09:42 +09:00
卜部昌平 7cf5d547e4 delete duplicated function overload
The `using engine<...snip...>::define;` line already defines this
function.  We don't have to repeat.
2020-01-28 17:09:42 +09:00
卜部昌平 03df02e871 fix typo
Add missing `*`.
2020-01-28 17:09:42 +09:00
卜部昌平 0a2e0db483 delete RB_METHOD_DEFINITION_DECL_1
This macro is no longer useful.  Just expand it.
2020-01-28 15:42:57 +09:00
卜部昌平 31fc34c969 delete unreachable branch
Case of __cplusplus is handled in cxxanyargs.hpp now.  These deleted
codes no longer reachable.
2020-01-28 15:42:57 +09:00
卜部昌平 01825e8bff template metaprogramming instead of macros
C++ (and myself) hates macros.  If we could do the same thing in both
preprocessor and template, we shall choose template.  This particular
part of the ruby header is one of such situations.
2020-01-28 15:42:57 +09:00
卜部昌平 ab33b3d691 move macros around
Would like to edit them in forthcoming commit.
2020-01-28 15:42:57 +09:00
Jeremy Evans e91c39f1c0 Remove special handling of $SAFE and related C-APIs
These were all deprecated in Ruby 2.7.
2020-01-22 09:09:47 -08:00
Nobuyoshi Nakada 661e07c97e
Moved the definition of `rb_define_method_if_constexpr`
Inside the block where `RB_METHOD_DEFINITION_DECL` family are
defined.
2020-01-09 21:32:26 +09:00
Yusuke Endoh 44a164c26f include/ruby/ruby.h: remove a variable tmp_buffer as it does not change
It is no longer used due to beae6cbf0f.
Coverity Scan found this.
2020-01-05 11:39:35 +09:00
Yusuke Endoh c7f01d889b include/ruby/ruby.h: remove last_idx that is no longer variable
Due to beae6cbf0f, the variable last_idx
is no longer changed and always -1.  This change simplifies the code by
removing the variable.  Coverity Scan pointed out this.
2020-01-05 11:39:35 +09:00
Jeremy Evans beae6cbf0f Fully separate positional arguments and keyword arguments
This removes the warnings added in 2.7, and changes the behavior
so that a final positional hash is not treated as keywords or
vice-versa.

To handle the arg_setup_block splat case correctly with keyword
arguments, we need to check if we are taking a keyword hash.
That case didn't have a test, but it affects real-world code,
so add a test for it.

This removes rb_empty_keyword_given_p() and related code, as
that is not needed in Ruby 3.  The empty keyword case is the
same as the no keyword case in Ruby 3.

This changes rb_scan_args to implement keyword argument
separation for C functions when the : character is used.
For backwards compatibility, it returns a duped hash.
This is a bad idea for performance, but not duping the hash
breaks at least Enumerator::ArithmeticSequence#inspect.

Instead of having RB_PASS_CALLED_KEYWORDS be a number,
simplify the code by just making it be rb_keyword_given_p().
2020-01-02 18:40:45 -08:00
卜部昌平 1dd149d3b1 re-add io.h and encoding.h into internal.h
This is tentative.  For the sake of simplicity we partially revert
commits e9cb552ec9, ee85a6e72b and 51edb30042.  Will decouple them
once again when we are ready.
2019-12-26 20:45:12 +09:00
Yukihiro "Matz" Matsumoto 537a1cd5a9 2.8.0 (tentative; to be 3.0.0) development has started. 2019-12-26 10:55:58 +09:00
Marc-Andre Lafortune 819b604037 Reword keyword arguments warning messages to convey these are deprecation warnings 2019-12-23 16:47:33 -05:00