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

1626 Коммитов

Автор SHA1 Сообщение Дата
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
Yusuke Endoh 5f35b8ca30
st.c: Use rb_st_* prefix instead of st_* (#2479)
The original st.c was public domain hash table implementation, but
Ruby's st.c is highly modified, and its data structure is not
compatiblie with the original one.

Therefore, when creating an extension library to wrap C code that uses
the original st.c, the symbols conflict, which leads to segfault.

This changes the prefix `st_*` of st.c functions to `rb_st_*` for
reflecting that they are specific to Ruby's, and avoid symbol conflicts.
2019-09-22 22:12:18 +09:00
Nobuyoshi Nakada daa4ad8ed7
Disable method definition type checks on Windows 2019-09-21 00:48:24 +09:00
Jeremy Evans c9f2b790ad Handle keyword argument separation for Enumerator#size
When Object#to_enum is passed a block, the block is called to get
a size with the arguments given to to_enum.  This calls the block
with the same keyword flag as to_enum is called with.

This requires adding rb_check_funcall_kw and
rb_check_funcall_default_kw to handle keyword flags.
2019-09-20 07:45:18 -07:00
Nobuyoshi Nakada 740a98fe10
Fix for explicit cast without RUBY_METHOD_FUNC 2019-09-20 19:12:36 +09:00
Nobuyoshi Nakada cb1f9fe918
Check various method defitions in C++ 2019-09-20 19:12:35 +09:00
Nobuyoshi Nakada 17a1366399 Overload variable definition functions
Define overloading functions of rb_define_virtual_variable and
rb_define_hooked_variable, for combinations with and without
ANYARGS casts.
2019-09-20 01:29:48 +09:00
Nobuyoshi Nakada 9c0d5e51cb Check method functions in C++
By using template and overloading, instead of transparent union.
2019-09-20 01:29:48 +09:00
卜部昌平 4a403e3f98 oops [ci skip]
Fixing typo.  It seems I failed to press the shift key.
2019-09-15 23:22:41 +09:00
Nobuyoshi Nakada 44d594189a
rb_scan_args_count_lead: use arguments instead of magic numbers 2019-09-15 13:29:12 +09:00
Jeremy Evans b78a345bd6 Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from Ruby
It is not safe to set this in C functions that can be called from
other C functions, as in the non argument-delegation case, you
can end up calling a Ruby method with a flag indicating keywords
are set without passing keywords.

Introduce some new *_kw functions that take a kw_splat flag and
use these functions to set RB_PASS_CALLED_KEYWORDS in places where
we know we are delegating methods (e.g. Class#new, Method#call)
2019-09-14 01:49:33 -07:00
Jeremy Evans 3cfbfa9628 Consolidate empty keyword handling
Remove rb_add_empty_keyword, and instead of calling that every
place you need to add empty keyword hashes, run that code in
a single static function in vm_eval.c.

Add 4 defines to include/ruby/ruby.h, these are to be used as
int kw_splat values when calling the various rb_*_kw functions:

RB_NO_KEYWORDS :: Do not pass keywords
RB_PASS_KEYWORDS :: Pass final argument (which should be hash) as keywords
RB_PASS_EMPTY_KEYWORDS :: Add an empty hash to arguments and pass as keywords
RB_PASS_CALLED_KEYWORDS :: Passes same keyword type as current method was
                           called with (for method delegation)

rb_empty_keyword_given_p needs to stay.  It is required if argument
delegation is done but delayed to a later point, which Enumerator
does.

Use RB_PASS_CALLED_KEYWORDS in rb_call_super to correctly
delegate keyword arguments to super method.
2019-09-13 16:42:27 -07:00
卜部昌平 20e428ec40 fix CentOS 6 compile error
See also https://rubyci.org/logs/rubyci.s3.amazonaws.com/centos6/ruby-master/log/20190910T003005Z.fail.html.gz
2019-09-10 12:25:36 +09:00
Masaki Matsushita 0e9d56f5e7 Support timeout for Addrinfo
Addrinfo.getaddrinfo and .foreach now accepts :timeout in seconds as
a keyword argument. If getaddrinfo_a(3) is available, the timeout will be
applied for name resolution. Otherwise, it will be ignored.

Socket.tcp accepts :resolv_timeout to use this feature.

This commit is retry of 6382f5cc91.
Test was failed on Solaris machines which don't have "http" in
/etc/services. In this commit, use "ssh" instead.
2019-09-10 10:10:59 +09:00
卜部昌平 150f514e19 workaround for C++ 98 const union problem.
Not the case of recent compilers, but compilers before C++11
rejected ruby.h, like https://ci.appveyor.com/project/ruby/ruby/builds/27225706/job/qjca7dpe204dytbd

This is supposedly because a struct with a member qualified with
a const effectively deletes its default copy constructor, which
is considered as being user-defined somehow.  Not sure where
exactly is the phrase in the C++98 standard who allows such C /
C++ incompatibility though.
2019-09-09 21:27:40 +09:00
Masaki Matsushita c4efbf663e Revert "Support timeout for Addrinfo"
This reverts commit 6382f5cc91.
test failed on Solaris.
2019-09-09 20:34:51 +09:00
Masaki Matsushita 6382f5cc91 Support timeout for Addrinfo
Addrinfo.getaddrinfo and .foreach now accepts :timeout in seconds as
a keyword argument. If getaddrinfo_a(3) is available, the timeout will be
applied for name resolution. Otherwise, it will be ignored.

Socket.tcp accepts :resolv_timeout to use this feature.
2019-09-09 14:34:05 +09:00
Jeremy Evans 80e679ef2d Fix keyword argument separation warnings for enumerators
This makes objects created via #to_enum and related methods pass
keyword arguments as keywords.

To implement this, add a kw_splat member of struct enumerator and
struct iter_method_arg, and add rb_block_call_kw, which is the
same as rb_block_call_kw with a flag for whether the last argument
is keyword options.
2019-09-06 19:41:23 -07:00
Jeremy Evans 37a2c660aa Convert keyword argument to required positional hash argument for Class#new, Method#call, UnboundMethod#bind_call
Also add keyword argument separation warnings for Class#new and Method#call.

To allow for keyword argument to required positional hash converstion in
cfuncs, add a vm frame flag indicating the cfunc was called with an empty
keyword hash (which was removed before calling the cfunc).  The cfunc can
check this frame flag and add back an empty hash if it is passing its
arguments to another Ruby method.  Add rb_empty_keyword_given_p function
for checking if called with an empty keyword hash, and
rb_add_empty_keyword for adding back an empty hash to argv.

All of this empty keyword argument support is only for 2.7.  It will be
removed in 3.0 as Ruby 3 will not convert empty keyword arguments to
required positional hash arguments.  Comment all of the relevent code
to make it obvious this is expected to be removed.

Add rb_funcallv_kw as an public C-API function, just like rb_funcallv
but with a keyword flag.  This is used by rb_obj_call_init (internals
of Class#new).  This also required expected call_type enum with
CALL_FCALL_KW, similar to the recent addition of CALL_PUBLIC_KW.

Add rb_vm_call_kw as a internal function, used by call_method_data
(internals of Method#call and UnboundMethod#bind_call). Add tests
for UnboundMethod#bind_call keyword handling.
2019-09-06 19:41:23 -07:00
卜部昌平 7516c48b27 fix Visual Studio compilation error
See also https://github.com/ruby/ruby/runs/213964487
2019-09-06 16:33:30 +09:00
卜部昌平 a569bc09e2 add include/ruby/backward/cxxanyargs.hpp
Compilation of extension libraries written in C++ are reportedly
broken due to https://github.com/ruby/ruby/pull/2404

The root cause of this issue was that the definition of ANYARGS
differ between C and C++, and that of C++ is incompatible with the
updated ones.

We are using the incompatibility against itself.  In C++ two distinct
function prototypes can be overloaded.  We provide the old, ANYARGSed
prototypes in addition to the current granular ones; and let the
older ones warn about types.
2019-09-06 15:50:58 +09:00
Jeremy Evans 7fc874bf4c Add rb_funcall_with_block_kw
This is needed for C functions to call methods with keyword arguments.
This is a copy of rb_funcall_with_block with an extra argument for
the keyword flag.

There isn't a clean way to implement this that doesn't involve
changing a lot of function signatures, because rb_call doesn't
support a way to mark that the call has keyword arguments.  So hack
this in using a CALL_PUBLIC_KW call_type, which we switch for
CALL_PUBLIC later in the call stack.

We do need to modify rm_vm_call0 to take an argument for whether
keyword arguments are used, since the call_type is no longer
available at that point.  Use the passed in value to set the
appropriate keyword flag in both calling and ci_entry.
2019-09-05 17:47:12 -07:00
卜部昌平 dd2b9d4a96 hide rb_funcallv_with_cc from public
Requested by ko1.  Also, because now that this function is internal
use only, why not just directly use struct rb_call_cache to purge
the ZALLOC.
2019-09-05 12:13:07 +09:00
Urabe, Shyouhei 2a6457b5b7 add rb_funcallv_with_cc()
Why not cache the method entry at each caller site.  The void**
is in fact a method entry, but this struct is hidden from ruby.h
so intentionally left opaque.
2019-09-04 14:08:40 +09:00
Jeremy Evans 39c3252cd1
Merge pull request #2422 from jeremyevans/rb_keyword_given_p
Add rb_keyword_given_p to the C-API
2019-09-03 11:32:02 -07:00
d0 (Daisuke Fujimura) 355ccdeae5
Disable method definition type checks on Cygwin too
[Bug #16134]
2019-09-03 12:59:08 +09:00
卜部昌平 4868ad7e5b fix CI failures in x64-mingw32
For insatnce
https://ci.appveyor.com/project/ruby/ruby/builds/27086475/job/mb9whkiygemlfy93
2019-08-31 15:30:10 +09:00
卜部昌平 43ab88c737 Workaround for https://reviews.llvm.org/D25824
This changeset make it possible to use very old clang.
2019-08-30 11:20:43 +09:00
卜部昌平 e4be2fda3d Rule out gcc on Windows
It seems the combination fails at the moment.  Don't know exactly
why but I suspect there can be issues in resolving weak references.
Let's rule them out for now.

https://ci.appveyor.com/project/ruby/ruby/builds/27036383/job/x3c5d54839aacoyt
2019-08-29 18:34:09 +09:00
卜部昌平 3df37259d8 drop-in type check for rb_define_singleton_method
We can check the function pointer passed to
rb_define_singleton_method like how we do so in rb_define_method.
Doing so revealed many arity mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 bfe5d22f89 drop-in type check for rb_define_private_method
We can check the function pointer passed to rb_define_private_method
like how we do so in rb_define_method.  Doing so revealed some
problematic usages of rb_obj_dummy.  They had to be split according
to their arity.
2019-08-29 18:34:09 +09:00
卜部昌平 9b429eb3b1 drop-in type check for rb_define_protected_method
We can check the function pointer passed to
rb_define_protected_method like how we do so in rb_define_method.
This changeset revealed no prototypes mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 0b81e7d6e2 drop-in type check for rb_define_method_id
We can check the function pointer passed to rb_define_method_id
like how we do so in rb_define_method.  This method is relatively
rarely used so there are less problems found than the other APIs.
2019-08-29 18:34:09 +09:00
卜部昌平 7bcfd9189a drop-in type check for rb_define_global_function
We can check the function pointer passed to rb_define_global_function
like we do so in rb_define_method.  It turns out that almost anybody
is misunderstanding the API.
2019-08-29 18:34:09 +09:00
卜部昌平 7b6fde4258 drop-in type check for rb_define_module_function
We can check the function pointer passed to rb_define_module_function
like how we do so in rb_define_method.  The difference is that this
changeset reveales lots of atiry mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 9ef51b0b89 drop-in type check for rb_define_method
The rb_define_method function takes a pointer to ANYARGS-ed functions,
which in fact varies 18 different prototypes.  We still need to
preserve ANYARGS for storages but why not check the consistencies if
possible.

Q&As:

Q: Where did the magic number "18" came from in the description above?

A: Count the case branch of vm_method.c:call_cfunc_invoker_func().
   Note also that the 18 branches has lasted for at least 25 years.
   See also 200e0ee2fd.

Q: What is this __weakref__ thing?

A: That is a kind of function overloading mechanism that GCC provides.
   In this case for instance rb_define_method0 is an alias of
   rb_define_method, with a strong type.

Q: What is this __transparent_union__ thing?

A: That is another kind of function overloading mechanism that GCC
   provides.  In this case the attributed function pointer is either
   VALUE(*)(int,VALUE*,VALUE) or VALUE(*)(int,const VALUE*,VALUE).

   This is better than void* or ANYARGS because we can reject all
   other possibilities than the two.

Q: What does this rb_define_method macro mean?

A: It selects appropriate alias of the rb_define_method function,
   depending on the arity.

Q: Why the prototype change of rb_f_notimplement?

A: Function pointer to rb_f_notimplement is special cased in
   vm_method.c:rb_add_method_cfunc().  That should be handled by the
   __builtin_choose_expr chain inside of rb_define_method macro
   expansion.  In order to do so, comparison like (func ==
   rb_f_notimplement) is inappropriate for __builtin_choose_expr's
   expression (which must be a compile-time integer constant but the
   address of rb_f_notimplement is not fixed until the linker).  So
   instead we are using __builtin_types_compatible_p, and in doing so
   we need to distinguish rb_f_notimplement from others, by type.
2019-08-29 18:34:09 +09:00
卜部昌平 79d280a5e8 rb_ivar_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit adds a function
prototype for rb_ivar_foreach.  Luckily this change revealed no
problematic usage of the function.
2019-08-27 15:52:26 +09:00
卜部昌平 50f5a0a8d6 rb_hash_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit adds function prototypes
for rb_hash_foreach / st_foreach_safe.  Also fixes some prototype
mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平 ae2dc3f217 rb_define_hooked_variable now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit uses rb_gvar_getter_t /
rb_gvar_setter_t for rb_define_hooked_variable /
rb_define_virtual_variable which revealed lots of function prototype
inconsistencies.  Some of them were literally decades old, going back
to dda5dc00cf.
2019-08-27 15:52:26 +09:00
卜部昌平 78628618da struct st_hash_type now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit adds function prototypes
for struct st_hash_type.  Honestly I don't understand why they were
commented out at the first place.
2019-08-27 15:52:26 +09:00
卜部昌平 6dd60cf114 st_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
st_foreach.  I strongly believe that this commit should have had come
with b0af0592fd, which added extra
parameter to st_foreach callbacks.
2019-08-27 15:52:26 +09:00
卜部昌平 e3fc30564e rb_thread_create now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_thread_create, which seems very safe to do.
2019-08-27 15:52:26 +09:00
卜部昌平 bc3e7924bc rb_proc_new / rb_fiber_new now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_proc_new / rb_fiber_new, and applies RB_BLOCK_CALL_FUNC_ARGLIST
wherever necessary.
2019-08-27 15:52:26 +09:00
卜部昌平 af5e256640 rb_catch now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_catch, and fixes some bugs revealed by that.
2019-08-27 15:52:26 +09:00
卜部昌平 703783324c rb_ensure now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_ensure, which also revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平 5c7c2d9951 rb_rescue / rb_rescue2 now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_rescue / rb_rescue2, which revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平 3cae73133c rb_iterate now takes rb_block_call_func_t
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit makes rb_iterate free
from ANYARGS.
2019-08-27 15:52:26 +09:00
卜部昌平 7329b3339a #define RB_BLOCK_CALL_FUNC_STRICT 1
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  Let's start from making
rb_block_call_func_t strict, and apply RB_BLOCK_CALL_FUNC_ARGLIST liberally.
2019-08-27 15:52:26 +09:00
Nobuyoshi Nakada 1bd60c66d3
Fix FL_USER19
* include/ruby/ruby.h: cast via `unsigned int` explicitly, to get
  rid of signed extension by implicit integer promotion.
2019-08-19 15:55:53 +09:00
Nobuyoshi Nakada c744b62698
io.c: export rb_io_extract_modeenc
* include/ruby/io.h (rb_io_enc_t): add typedef.

* io.c (rb_io_extract_modeenc): export.
2019-08-14 11:20:58 +09:00
Nobuyoshi Nakada 0c2d81dada
Renamed ruby_finalize_{0,1}
And pass rb_execution_context_t as an argument.
2019-08-13 09:47:08 +09:00
Aaron Patterson aac4d9d6c7
Rename rb_gc_mark_no_pin -> rb_gc_mark_movable
Renaming this function.  "No pin" leaks some implementation details.  We
just want users to know that if they mark this object, the reference may
move and they'll need to update the reference accordingly.
2019-08-12 16:44:54 -04:00
Nobuyoshi Nakada 0d0ff8277f
rb_trap_exec has been removed since 1.9 2019-08-12 15:14:01 +09:00
Nobuyoshi Nakada 4daff3a603
The value of rb_scan_args_verify is never used 2019-08-06 12:06:03 +09:00
Nobuyoshi Nakada 5cff9968ae
Distinguish bad scan format from no argument variables 2019-08-06 11:52:42 +09:00
Nobuyoshi Nakada fb9dd6182a
Use negative-sized array instead of zero-division 2019-08-05 23:26:19 +09:00
Nobuyoshi Nakada 4c15b241f8
Unused macro argument `varc` 2019-08-05 23:26:19 +09:00
Nobuyoshi Nakada d6ac5c53d4
Revert "Always evaluate the expression RUBY_ASSERT_MESG_WHEN just once"
It caused a significant benchmark fall.  Some assertions seem to
use expressions with side-effects which cannot be inlined.

This reverts commit b452c03a14.
2019-08-05 08:55:09 +09:00
Nobuyoshi Nakada 0a63c4d5fb
Fix errno at seeking socket/pipe on Windows
[Bug #12230]
2019-07-25 06:39:40 +09:00
Koichi Sasada 1feda1c2b0 constify again.
Same as last commit, make some fields `const`.

include/ruby/ruby.h:
* Rasic::klass
* RArray::heap::aux::shared_root
* RRegexp::src
internal.h:
* rb_classext_struct::origin_, redefined_class
* vm_svar::cref_or_me, lastline, backref, others
* vm_throw_data::throw_obj
* vm_ifunc::data
* MEMO::v1, v2, u3::value

While modifying this patch, I found write-barrier miss on
rb_classext_struct::redefined_class.

Also vm_throw_data::throw_state is only `int` so change the type.
2019-07-22 17:53:10 +09:00
git a44ad9a145 * expand tabs. 2019-07-19 13:10:08 +09:00
Koichi Sasada 182ae1407b fix shared array terminology.
Shared arrays created by Array#dup and so on points
a shared_root object to manage lifetime of Array buffer.
However, sometimes shared_root is called only shared so
it is confusing. So I fixed these wording "shared" to "shared_root".

* RArray::heap::aux::shared -> RArray::heap::aux::shared_root
* ARY_SHARED() -> ARY_SHARED_ROOT()
* ARY_SHARED_NUM() -> ARY_SHARED_ROOT_REFCNT()

Also, add some debug_counters to count shared array objects.

* ary_shared_create: shared ary by Array#dup and so on.
* ary_shared: finished in shard.
* ary_shared_root_occupied: shared_root but has only 1 refcnt.
  The number (ary_shared - ary_shared_root_occupied) is meaningful.
2019-07-19 13:07:59 +09:00
Nobuyoshi Nakada b452c03a14
Always evaluate the expression RUBY_ASSERT_MESG_WHEN just once 2019-07-15 17:45:37 +09:00
Nobuyoshi Nakada a7fdb22373
Enable RUBY_ASSERT_MESG_WHEN when RUBY_DEBUG is turned on 2019-07-15 11:01:53 +09:00
Koichi Sasada f6f09cbc76 introduce RUBY_ASSERT_ALWAYS(expr).
RUBY_ASSERT_ALWAYS(expr) ignores NDEBUG (we cannot remove this
assertion).
2019-07-15 10:21:41 +09:00
Nobuyoshi Nakada 08c2a9dc59
Introduce RUBY_DEBUG flag macro
When RUBY_DEBUG is turned on, all RUBY_ASSERT() macros will be
enabled regardless RUBY_NDEBUG.
2019-07-14 17:58:06 +09:00
Nobuyoshi Nakada 715955ff27
Include ruby/assert.h in ruby/ruby.h so that assertions can be there 2019-07-14 17:58:03 +09:00
git 73904abb95 * expand tabs. 2019-07-14 17:45:52 +09:00
Nobuyoshi Nakada 32f0135144
Split RUBY_ASSERT and so on under include/ruby 2019-07-14 17:45:21 +09:00
Samuel Williams d17344cfc5 Remove IA64 support. 2019-06-19 23:30:04 +12:00
Nobuyoshi Nakada c8b001858e
Revert "marshal.c: new functions for extensions"
This reverts a commit miss, 24a96a0228.
2019-06-04 19:06:19 +09:00
Nobuyoshi Nakada 24a96a0228
marshal.c: new functions for extensions
* marshal.c (rb_marshal_dump_limited): new function for extension
  libraries to dump object with limited nest level.

* marshal.c (rb_marshal_load_with_proc): new function for extension
  libraries to load object with hook proc.
2019-06-04 18:59:03 +09:00
Nobuyoshi Nakada fb568fe724
Added missing predicate macros 2019-05-28 23:46:30 +09:00
Koichi Sasada 8a2b497e3b remove obsolete rb_gc_finalize_deferred().
rb_gc_finalize_deferred() is remained for compatibility with
C-extensions. However, this function is no longer working
from Ruby 2.4 (crash with SEGV immediately).
So remove it completely.
2019-05-28 15:57:20 +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