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

1800 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 722a1e479f RBIMPL_ALIGNAS: reorder #ifdef blocks
Since r63443, `-std=gnu99 -D_XOPEN_SOUCE=x00` is added to Solaris'
`CPPFLAGS`.  `CPPFLAGS` is shared among `CC` / `CXX`.  This results in
both `__STDC_VERSION__` and `__cplusplus` to be defined at the same time
for a C++ compilation, only on Solaris.

It seems the `CPPFLAGS` addition is intentional.  We sould not touch
that part.  Instead we need to reroute this by always check for
`__cplusplus` first.
2020-09-26 00:30:36 +09:00
Kenta Murata c04c34df47
memory_view.h: brush up the description in the comment 2020-09-25 21:32:00 +09:00
Kenta Murata 890bc2cdde
Buffer protocol proposal (#3261)
* Add buffer protocol

* Modify for some review comments

* Per-object buffer availability

* Rename to MemoryView from Buffer and make compilable

* Support integral repeat count in memory view format

* Support 'x' for padding bytes

* Add rb_memory_view_parse_item_format

* Check type in rb_memory_view_register

* Update dependencies in common.mk

* Add test of MemoryView

* Add test of rb_memory_view_init_as_byte_array

* Add native size format test

* Add MemoryView test utilities

* Add test of rb_memory_view_fill_contiguous_strides

* Skip spaces in format string

* Support endianness specifiers

* Update documentation

* Support alignment

* Use RUBY_ALIGNOF

* Fix format parser to follow the pack format

* Support the _ modifier

* Parse count specifiers in get_format_size function.

* Use STRUCT_ALIGNOF

* Fix test

* Fix test

* Fix total size for the case with tail padding

* Fix rb_memory_view_get_item_pointer

* Fix rb_memory_view_parse_item_format again
2020-09-25 20:32:02 +09:00
Koichi Sasada fde136152e should not check taint flag on rubyspec.
Now taint flag is obsolete and it is used fro shareaable flag.
So we should not check this flag.
2020-09-25 12:52:53 +09:00
卜部昌平 c6c241e49c enrich comment
Added description and URL about nested flexible array member.
2020-09-25 11:38:33 +09:00
卜部昌平 e75aed7abb RBIMPL_ALIGNOF: do not use constexpr
Was definitely a bad idea to use constexpr.  It is not ubiquitous.
2020-09-25 11:38:33 +09:00
卜部昌平 873fb1aa4c ALLOCA_N: do not use RUBY_ALIGNOF
Now that RUBY_ALIGNOF behaves like C11's _Alignof.  This is not
necessarily the best stack arrangement.  We can just give up using
__builtin_alloca_with_align(), and let alloca choose what is optimal.
2020-09-25 11:38:33 +09:00
卜部昌平 e9fb2bc873 RBIMPL_ALIGNOF: do not use __alignof__
It is reported that on a system of i386 System V ABI, GCC returns 8 for
__alignof__(double).  OTOH the ABI defines alignments of double to be 4,
and ISO/IEC 9899:2011 reads that _Alignof(double) shall return 4 on such
machine.  What we want in ruby is 4 instead of 8 there.  We cannot use
__alignof__.

Additionally, both old GCC / old clang return 8 for _Alignof(double) on
such platforms.  They are their bugs, and already fixed in recent
versions.  But we have to support older compilers for a while.  Shall
check sanity of _Alignof.
2020-09-25 11:38:33 +09:00
Hiroshi SHIBATA e380f78851 Removed rb_find_file_ext_safe and rb_find_file_safe 2020-09-23 09:09:36 +09:00
Chris Seaton 8e173d8b27 Warn on a finalizer that captures the object to be finalized
Also improve specs and documentation for finalizers and more clearly
recommend a safe code pattern to use them.
2020-09-16 13:52:24 -07:00
Samuel Williams 7fca274198 Rework console to use `rb_io_wait`. 2020-09-14 16:44:09 +12:00
Samuel Williams 701dcbb3ca Add support for hooking `IO#read`. 2020-09-14 16:44:09 +12:00
Samuel Williams d387029f39 Standardised scheduler interface. 2020-09-14 16:44:09 +12:00
Samuel Williams 905e9c8093 Simplify bitmasks for IO events. 2020-09-14 16:44:09 +12:00
Samuel Williams 6747cb5754 Add RB_ prefix to `GetOpenFile` and `MakeOpenFile`. 2020-09-14 16:44:09 +12:00
Nobuyoshi Nakada 2b07b24bdf Added `rb_random_base_init`
To enclose the initialization of Random::Base part.
2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada 4924011262 Added WITH_REAL macros
Added `WITH_REAL` versions to `RB_RANDOM_INTERFACE` macros.  Also
these macros including "without real" versions no longer contain
the terminator (semicolon and comma).
2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada d6ec0ef59b Added `get_real` interface 2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada c449b9b02f Added rb_int_pair_to_real 2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada af5e87ab21 separate rb_random_t
* random.c: separate abstract rb_random_t and rb_random_mt_t for
  Mersenne Twister implementation.

* include/ruby/random.h: the interface for extensions of Random
  class.

* DLL imported symbol reference is not constant on Windows.

* check if properly initialized.
2020-09-07 20:08:01 +09:00
Samuel Williams c12b2703bc Add `RB_` prefix for size_t to number conversion. 2020-09-06 15:37:54 +12:00
Koichi Sasada 79df14c04b Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.

[Feature #17100]

This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.

I hope this feature can help programmers from thread-safety issues.
2020-09-03 21:11:06 +09:00
Yukihiro "Matz" Matsumoto 21c62fb670
Version number bumped to 3.0.0 from 2.8.0 (tentative).
We have decided to go forward to 3.0 this year.
2020-08-31 16:38:13 +09:00
Kazuhiro NISHIYAMA c2011d1a51
Fix a typo [ci skip] 2020-08-29 12:31:05 +09:00
卜部昌平 5ca44076f4 include/ruby/backward/2/rmodule.h: deprecate
Only one function in only one file uses contents of this public header.
That is not a wise idea.  Let's just free the header's soul.
2020-08-27 16:42:06 +09:00
卜部昌平 1035a3b202 RUBY_SHOW_COPYRIGHT_TO_DIE: flip the default
Commit 7aab062ef3 says:

> ruby_show_version() will no longer exits the process, if
> RUBY_SHOW_COPYRIGHT_TO_DIE is set to 0.  This will be the default in
> the future.

3.0 is a good timing for that "future".
2020-08-27 15:04:00 +09:00
卜部昌平 cd1d6d9029 include/ruby/backward/2/r_cast.h: deprecate
Remove all usages of RCAST() so that the header file can be excluded
from ruby/ruby.h's dependency.
2020-08-27 15:03:36 +09:00
卜部昌平 442525527e improve deprecation warning
We should not recommend RBIMPL_*.
2020-08-27 15:02:52 +09:00
卜部昌平 21b3bc10d3 DEPRECATED_TYPE: is deprecated
Nobody uses this macro any longer.
2020-08-27 15:02:52 +09:00
卜部昌平 3437e6247d RClassDeprecated: delete
It has been deprecated for 5 years since 1f22556040.
2020-08-27 15:02:52 +09:00
卜部昌平 5ae2c1b093 git rm include/ruby/backward/rubyio.h 2020-08-27 14:27:21 +09:00
卜部昌平 6ec6dd3ed7 git rm include/ruby/backward/rubysig.h 2020-08-27 14:11:59 +09:00
卜部昌平 5ca7b6abde git rm include/ruby/backward/{st,util}.h 2020-08-27 14:09:18 +09:00
卜部昌平 4bc3846389 git rm include/ruby/backward/classext.h 2020-08-27 14:08:04 +09:00
卜部昌平 0da2a3f1fc sed -i '\,2/extern.h,d' 2020-08-27 14:07:49 +09:00
卜部昌平 b2e1688e7d git rm include/ruby/backward/2/extern.h 2020-08-27 14:07:49 +09:00
卜部昌平 8b022da518 HAVE_STMT_AND_DECL_IN_EXPR: not for Sun C++
Because we check HAVE_STMT_AND_DECL_IN_EXPR in configure, it is peoven
to work in C.  But C++ situation can be different.  Oracle Developer
Studio is another example of such things.
2020-08-21 11:04:54 +09:00
卜部昌平 01826b3fda RBIMPL_HAS_CPP_ATTRIBUTE: handle SunPro
Oracle Developer Studio's C++ preprocessor started to understand
__has_cpp_attribute since version 12.5, and is broken.  After looking
around for a while I found Boost and ICU also had this issue before.
Let me add workaround for it.
2020-08-21 11:04:54 +09:00
卜部昌平 6649677eb9 ROBJECT_IV_INDEX_TBL: convert into an inline function
Former ROBJECT_IV_INDEX_TBL macro included RCLASS_IV_INDEX_TBL, which is
not disclosed to extension libraies.  The macro was kind of broken.  Why
not just deprecate it, and convert the internal use into an inline
function.
2020-08-19 14:30:57 +09:00
卜部昌平 ff30358d13 RARRAY_AREF: convert into an inline function
RARRAY_AREF has been a macro for reasons.  We might not be able to
change that for public APIs, but why not relax the situation internally
to make it an inline function.
2020-08-15 12:09:26 +09:00
AGSaidi 511b55bcef
Enable arm64 optimizations that exist for power/x86 (#3393)
* Enable unaligned accesses on arm64

64-bit Arm platforms support unaligned accesses.

Running the string benchmarks this change improves performance
by an average of 1.04x, min .96x, max 1.21x, median 1.01x

* arm64 enable gc optimizations

Similar to x86 and powerpc optimizations.

|       |compare-ruby|built-ruby|
|:------|-----------:|---------:|
|hash1  |       0.225|     0.237|
|       |           -|     1.05x|
|hash2  |       0.110|     0.110|
|       |       1.00x|         -|

* vm_exec.c: improve performance for arm64

|                               |compare-ruby|built-ruby|
|:------------------------------|-----------:|---------:|
|vm_array                       |     26.501M|   27.959M|
|                               |           -|     1.06x|
|vm_attr_ivar                   |     21.606M|   31.429M|
|                               |           -|     1.45x|
|vm_attr_ivar_set               |     21.178M|   26.113M|
|                               |           -|     1.23x|
|vm_backtrace                   |       6.621|     6.668|
|                               |           -|     1.01x|
|vm_bigarray                    |     26.205M|   29.958M|
|                               |           -|     1.14x|
|vm_bighash                     |    504.155k|  479.306k|
|                               |       1.05x|         -|
|vm_block                       |     16.692M|   21.315M|
|                               |           -|     1.28x|
|block_handler_type_iseq        |       5.083|     7.004|
|                               |           -|     1.38x|
2020-08-14 02:15:54 +09:00
卜部昌平 504e632a15
sync NDEBUG, RUBY_DEBUG, and RUBY_NDEBUG (#3327)
- When NDEBUG is defined that shall be honoured.
- When RUBY_DEBUG is defined that shall be honoured.
- When both are defined and they conflict, warnings shall be rendered.
- When nothing is specified, nothing shall happen.
2020-08-07 14:01:13 +09:00
卜部昌平 c4fc737f75 include/ruby/util.h: delete unused codes
- util.h includes defines.h,
- ... which includes ruby/backward/2/stdarg.h,
- ... which always defines _.

This `#ifndef _` must never happen.
2020-07-23 14:30:12 +09:00
Samuel Williams 1b3a6847be Move declarations to private `internal/thread.h` header. 2020-07-20 13:20:58 +12:00
Samuel Williams f3462d99a3 Rename `rb_current_thread_scheduler` to `rb_thread_scheduler_if_nonblocking`.
Correctly capture thread before releasing GVL and pass as argument to
`rb_thread_scheduler_if_nonblocking`.
2020-07-20 13:20:58 +12:00
卜部昌平 1ce9c37257 Revert "RBIMPL_UNREACHABLE_RETURN: evaluate the argument"
This reverts commit c8dc2bf140.

No longer necessary.
2020-06-29 12:33:17 +09:00
卜部昌平 c8dc2bf140 RBIMPL_UNREACHABLE_RETURN: evaluate the argument
Prevent casual typos inside of UNREACHABLE_RETURN(...).
2020-06-29 11:05:41 +09:00
Koichi Sasada d300a73441 RUBY_ASSERT_NOASSUME
If __builtin_assume() is enables and RUBY_DEBUG=0, RUBY_ASSERT(expr)
will be compiled to __builtin_assume(expr) and compiler can assume
expr is true and apply aggressive optimizations. However we observed
doubtful behavior because of compiler optimizations, we introduce
new macro RUBY_ASSERT_NOASSUME to disable __builtin_assume().
With this macro, we can try without __builtin_assume().
2020-05-29 13:50:58 +09:00
Nobuyoshi Nakada 4cabd77e33
Removed a trailing space [ci skip] 2020-05-27 14:30:45 +09:00
Nobuyoshi Nakada 17d17de0e8
Get rid of redefinition of memcpy on mingw 2020-05-26 16:58:40 +09:00
Koichi Sasada 4ac42874bc Update include/ruby/assert.h
Co-authored-by: 卜部昌平 <shyouhei@ruby-lang.org>
2020-05-26 03:21:14 +09:00
Koichi Sasada 21991e6ca5 Use RUBY_DEBUG instead of NDEBUG
Assertions in header files slows down an interpreter, so they should be
turned off by default (simple `make`). To enable them, define a macro
`RUBY_DEBUG=1` (e.g. `make cppflags=-DRUBY_DEBUG` or use `#define` at
the very beggining of the file. Note that even if `NDEBUG=1` is defined,
`RUBY_DEBUG=1` enables all assertions.
[Feature #16837]
related: https://github.com/ruby/ruby/pull/3120

`assert()` lines in MRI *.c is not disabled even if `RUBY_DEBUG=0` and
it can be disabled with `NDEBUG=1`. So please consider to use
`RUBY_ASSERT()` if you want to disable them when `RUBY_DEBUG=0`.
2020-05-26 03:21:14 +09:00
卜部昌平 06321ea26c RBIMPL_ATTR_DEPRECATED: disable for GCC10
GCC 10.x seems buggy here.  See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95302
2020-05-25 10:17:51 +09:00
Nobuyoshi Nakada 62b47196e4
Added UNREACHABLE_RETURN
To get rid of a void function at the end of non-void function.
2020-05-21 13:31:36 +09:00
卜部昌平 43725c6091 rb_scan_args_set: make it slightly readable
This is a pure refactoring that improves understanding of what is going
on.  Not a big win though.
2020-05-21 09:58:54 +09:00
Koichi Sasada 67d259c5dc Use __bultin_assume() from clang-7
We observed combination of multiple __builtin_assume() can cause
strange compile results on clang-6 (-DNDEBUG exposed this issue).
To avoid this problem, __builtin_assume() is from clang-7.
https://github.com/ruby/ruby/pull/3120#issuecomment-630821333
2020-05-20 10:29:38 +09:00
Samuel Williams 0e3b0fcdba
Thread scheduler for light weight concurrency. 2020-05-14 22:10:55 +12:00
Nobuyoshi Nakada 237bee9d40
Removed extra stringization
Argument of RUBY_ASSERT_FAIL is already stringized message, so no
more extra stringization should be applied.
2020-05-12 10:23:33 +09:00
卜部昌平 4fbb344156 fix sunpro pragma
SunPro's #pragma does_not_return(...) needs an argument.  That does not
fit the attribute syntax we employ.
2020-05-11 16:47:25 +09:00
卜部昌平 233c2018f1 drop varargs.h support
This header file is simply out of date (for decades since at least
1989).  It's the 21st century.  Just stop using it.
2020-05-11 14:56:51 +09:00
卜部昌平 534277fa7b rb_str_new: hoist RB_CONSTANT_P out of function
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html says:

> GCC never returns 1 when you call the inline function with a string
> constant or ...

Because rb_str_new and familiy take string constants, it was a bad idea
for them to contain RB_CONSTANT_P.  We should instead do so in
corresponding macros. [ruby-core:98212]
2020-05-11 11:07:37 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 b85fd1d690 mv include/ruby/{impl,internal}
Devs do not love "impl".
2020-05-11 09:24:08 +09:00
卜部昌平 0d88fe3a72 spaces in comments [ci skip] 2020-05-11 09:24:08 +09:00
卜部昌平 122f96c362 sed -i s/ruby3/rbimpl/g 2020-05-11 09:24:08 +09:00
卜部昌平 97672f669a sed -i s/RUBY3/RBIMPL/g
Devs do not love "3".  The only exception is RUBY3_KEYWORDS in parse.y,
which seems unrelated to our interests.
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
卜部昌平 dca234a5dc mv include/ruby/{3,impl}
Devs do not love "3".
2020-05-11 09:24:08 +09:00
Marc-Andre Lafortune adf709a785 Classes made from Struct should have default `new` singleton method.
[Bug #16465] [Bug #16801]
[Fix GH-2795] [Fix GH-2944] [Fix GH-3045] [Fix GH-3093]

Note: Backporting shouldn't modify object.h and instead can use
struct_new_kw which is basically a duplicate implementation of
rb_class_new_instance_pass_kw

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: Adam Hess <HParker@github.com>
Co-authored-by: Jose Cortinas <jacortinas@gmail.com>
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2020-05-08 04:18:45 -04:00
Nobuyoshi Nakada 76d9be9ce9
Get rid of -Wgnu-zero-variadic-macro-arguments errors
As zero variadic macro argument, `rb_scan_args(argc, argv, "")`
(or `"0"`), means 0-arity method and should be defined so, that
case doesn't need to consider.
2020-05-01 18:39:08 +09:00
Jeremy Evans 5a9d2da76e Remove deprecated rb_require_safe 2020-04-30 10:32:27 -07:00
Nobuyoshi Nakada fefb5fafbc
More enums are mandatory for rp in lldb_cruby.py 2020-04-25 17:52:27 +09:00
Kazuhiro NISHIYAMA 4b86194177
Fix typos [ci skip] 2020-04-21 12:38:36 +09:00
Nobuyoshi Nakada 0f7d3e4e40
RUBY_SPECIAL_SHIFT and RUBY_FL_USHIFT are mandatory for rp in lldb_cruby.py 2020-04-18 17:07:56 +09:00
卜部昌平 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
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
卜部昌平 ec931ee9e1 forward declare struct timespec
... like we do so for struct timeval at several hundreds of lines above.
Depending on OS/Compiler, this can be the first place for the struct to
appear.  To make sure the struct is global, we need a forward
declaration at this point.
2019-12-10 11:43:55 +09:00
Jeremy Evans c257303ae7 Deprecate rb_eval_cmd, add rb_eval_cmd_kw
rb_eval_cmd takes a safe level, and now that $SAFE is deprecated,
it should be deprecated as well.

Replace with rb_eval_cmd_kw, which takes a keyword flag.  Switch
the two callers to this function.
2019-11-18 01:00:25 +02: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
Aaron Patterson d0d743ad45
Remove duplicate code
These functions are the same, so remove one.

Co-authored-by: John Hawthorn <john@hawthorn.email>
2019-11-06 16:31:55 -08:00
卜部昌平 72f997edf6 mark functions that do not return NULL as such.
Apply __attribute__((__returns_nonnull__)) when available.
2019-11-01 16:58:19 +09:00
卜部昌平 2c889e9b05 RUBY_ATTR_ALOC_SIZE for clang
clang also supports __attribute__((__alloc_size__)) so why not use
it when the compiler says it does.
2019-11-01 16:58:19 +09:00
Nobuyoshi Nakada ad4da86669
Check for nonnull attribute in configure 2019-10-29 16:38:15 +09:00
Yusuke Endoh 281f754126 include/ruby/backward/cxxanyargs.hpp: call `va_end` before return
Coverity Scan complains it.
2019-10-24 08:30:33 +09:00
Nobuyoshi Nakada 1d91feaf13
Limit strict RUBY_METHOD_FUNC in C++
Limit strict function signature check with RUBY_METHOD_FUNC in C++
to bundled libraries only.  [Bug #16271]
2019-10-23 20:18:32 +09:00
Nobuyoshi Nakada 7ebf9da788
Also moved fallback definition of __has_attribute 2019-10-12 22:09:49 +09:00
Nobuyoshi Nakada 710bc00379
Moved RB_METHOD_DEFINITION_DECL to intern.h
This macro is used here before defined in ruby.h.
2019-10-12 17:47:28 +09:00
卜部昌平 a220410be7 annotate malloc-ish functions
Make them gcc friendly.  Note that realloc canot be __malloc__
attributed, according to the GCC manual.
2019-10-09 12:12:28 +09:00
Jeremy Evans c0eae130b1 Note RB_PASS_EMPTY_KEYWORDS and RB_SCAN_ARGS_EMPTY_KEYWORDS will be removed
There is no need for these in Ruby 3.0, and the plan is to
remove them.
2019-10-07 13:51:21 -07:00
Yusuke Endoh 113bef6976 array.c (rb_mem_clear): remove "register" from arguments
to suppress the following warning:

```
compiling cxxanyargs.cpp
In file included from cxxanyargs.cpp:1:
In file included from ../../.././include/ruby/ruby.h:2150:
../../.././include/ruby/intern.h:56:19: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
void rb_mem_clear(register VALUE*, register long);
                  ^~~~~~~~~
../../.././include/ruby/intern.h:56:36: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
void rb_mem_clear(register VALUE*, register long);
                                   ^~~~~~~~~
```
2019-10-04 16:07:46 +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
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
Jeremy Evans 660c7e050f Fix more keyword separation issues
This fixes instance_exec and similar methods. It also fixes
Enumerator::Yielder#yield, rb_yield_block, and a couple of cases
with Proc#{<<,>>}.

This support requires the addition of rb_yield_values_kw, similar to
rb_yield_values2, for passing the keyword flag.

Unlike earlier attempts at this, this does not modify the rb_block_call_func
type or add a separate function type.  The functions of type
rb_block_call_func are called by Ruby with a separate VM frame, and we can
get the keyword flag information from the VM frame flags, so it doesn't need
to be passed as a function argument.

These changes require the following VM functions accept a keyword flag:

* vm_yield_with_cref
* vm_yield
* vm_yield_with_block
2019-09-26 19:24:58 -07:00
Nobuyoshi Nakada 0c6f36668a
Adjusted spaces [ci skip] 2019-09-27 10:20:56 +09:00
Jeremy Evans 37f9213f89 Fix keyword argument separation issues in Enumerator::Generator#each
This requires adding rb_proc_call_kw to pass the keyword flag.
2019-09-26 15:30:51 -07:00
Jeremy Evans b193041b99 Fix keyword argument separation issues in Fiber#resume 2019-09-26 08:01:53 -07:00
Jeremy Evans 760893d2f8 Fix keyword argument separation issues in Proc#{<<,>>}
This requires adding rb_proc_call_with_block_kw.
2019-09-26 08:01:53 -07:00
Yusuke Endoh 1fe73dc860 include/ruby/ruby.h: suppress a false-positive warning of GCC
GCC emits a lot of false positives for rb_scan_args because:

* `rb_scan_args(argc, argv, "*:", NULL, &opts);` makes `n_mand == 0`,
* `n_mand == argc + 1` implies `argc == -1`, and
* `memcpy(ptr, argv, sizeof(VALUE)*argc);` explodes

However, we know that argc is never so big, thus this is a false
positive.  This change suppresses it by adding a condition `n_mand > 0`.

```
In file included from /usr/include/string.h:494,
                 from ./include/ruby/defines.h:145,
                 from ./include/ruby/ruby.h:29,
                 from ./include/ruby/encoding.h:27,
                 from dir.c:14:
In function 'memcpy',
    inlined from 'ruby_nonempty_memcpy.part.0' at ./include/ruby/ruby.h:1763:17,
    inlined from 'ruby_nonempty_memcpy' at ./include/ruby/ruby.h:1760:1,
    inlined from 'rb_scan_args_set' at ./include/ruby/ruby.h:2594:9,
    inlined from 'dir_s_aref' at dir.c:2774:12:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:34:10: warning: '__builtin___memcpy_chk' pointer overflow between offset 0 and size [-8, 9223372036854775807] [-Warray-bounds]
   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:34:10: warning:
'__builtin___memcpy_chk' specified size 18446744073709551608 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
```
2019-09-26 11:35:01 +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