aboutsummaryrefslogtreecommitdiffstats
path: root/include/ruby/ruby.h
Commit message (Collapse)AuthorAgeFilesLines
* include/ruby/backward/2/rmodule.h: deprecate卜部昌平2020-08-271-1/+0
| | | | | 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.
* include/ruby/backward/2/r_cast.h: deprecate卜部昌平2020-08-271-1/+0
| | | | | Remove all usages of RCAST() so that the header file can be excluded from ruby/ruby.h's dependency.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-27/+27
| | | | To fix build failures.
* sed -i s/RUBY3/RBIMPL/g卜部昌平2020-05-111-3/+3
| | | | | Devs do not love "3". The only exception is RUBY3_KEYWORDS in parse.y, which seems unrelated to our interests.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-27/+27
| | | | This shall fix compile errors.
* add #include guard hack卜部昌平2020-04-131-15/+13
| | | | | | | | | | | | | | | | | | | | | | 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
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-2755/+39
| | | Split ruby.h
* Removed non-RUBY_INTEGER_UNIFICATION codeNobuyoshi Nakada2020-03-211-6/+0
|
* rb_check_safe_obj no longer exists卜部昌平2020-03-071-1/+0
| | | | | | | Commit e91c39f1c0f7d5e670266d9593d533fd444957f6 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.
* kill USE_RGENGC=0卜部昌平2020-02-261-17/+3
| | | | | | This compile-time option has been broken for years (at least since commit 49369ef17316cd5d5819b038f286e1d951972b52, according to git bisect). Let's delete codes that no longer works.
* comma at the end of enum is a C++11ism卜部昌平2020-02-201-1/+1
| | | | | | | 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.
* Consitified `rb_scan_args_set`Nobuyoshi Nakada2020-02-141-2/+2
|
* Parenthesized macro argumentsNobuyoshi Nakada2020-02-031-14/+14
|
* Make `rb_scan_args_kw` inline tooNobuyoshi Nakada2020-02-031-6/+38
|
* Removed no longer used variable `last_hash`Nobuyoshi Nakada2020-02-021-6/+2
| | | | | | | | | 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.
* delete RB_METHOD_DEFINITION_DECL_1卜部昌平2020-01-281-50/+33
| | | | This macro is no longer useful. Just expand it.
* delete unreachable branch卜部昌平2020-01-281-70/+2
| | | | | Case of __cplusplus is handled in cxxanyargs.hpp now. These deleted codes no longer reachable.
* template metaprogramming instead of macros卜部昌平2020-01-281-8/+4
| | | | | | 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.
* move macros around卜部昌平2020-01-281-0/+194
| | | | Would like to edit them in forthcoming commit.
* Remove special handling of $SAFE and related C-APIsJeremy Evans2020-01-221-36/+0
| | | | These were all deprecated in Ruby 2.7.
* Moved the definition of `rb_define_method_if_constexpr`Nobuyoshi Nakada2020-01-091-1/+0
| | | | | Inside the block where `RB_METHOD_DEFINITION_DECL` family are defined.
* include/ruby/ruby.h: remove a variable tmp_buffer as it does not changeYusuke Endoh2020-01-051-3/+0
| | | | | It is no longer used due to beae6cbf0fd8b6619e5212552de98022d4c4d4d4. Coverity Scan found this.
* include/ruby/ruby.h: remove last_idx that is no longer variableYusuke Endoh2020-01-051-5/+5
| | | | | | Due to beae6cbf0fd8b6619e5212552de98022d4c4d4d4, 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.
* Fully separate positional arguments and keyword argumentsJeremy Evans2020-01-021-74/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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().
* Reword keyword arguments warning messages to convey these are deprecation ↵Marc-Andre Lafortune2019-12-231-3/+3
| | | | warnings
* vm_args.c: rephrase the warning message of keyword argument separationYusuke Endoh2019-12-201-1/+1
| | | | | | | | | | (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
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-181-9/+7
| | | | | | | | | | | | | | | | | 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.
* Limit strict RUBY_METHOD_FUNC in C++Nobuyoshi Nakada2019-10-231-1/+1
| | | | | Limit strict function signature check with RUBY_METHOD_FUNC in C++ to bundled libraries only. [Bug #16271]
* Also moved fallback definition of __has_attributeNobuyoshi Nakada2019-10-121-4/+0
|
* Moved RB_METHOD_DEFINITION_DECL to intern.hNobuyoshi Nakada2019-10-121-82/+6
| | | | This macro is used here before defined in ruby.h.
* Note RB_PASS_EMPTY_KEYWORDS and RB_SCAN_ARGS_EMPTY_KEYWORDS will be removedJeremy Evans2019-10-071-2/+2
| | | | | There is no need for these in Ruby 3.0, and the plan is to remove them.
* Add three more C-API functions for handling keywordsJeremy Evans2019-09-291-0/+3
| | | | | | | | 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.
* Fix more keyword separation issuesJeremy Evans2019-09-261-1/+2
| | | | | | | | | | | | | | | | | | | | | 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
* Adjusted spaces [ci skip]Nobuyoshi Nakada2019-09-271-2/+2
|
* include/ruby/ruby.h: suppress a false-positive warning of GCCYusuke Endoh2019-09-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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=] ```
* Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans2019-09-251-20/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Disable method definition type checks on WindowsNobuyoshi Nakada2019-09-211-1/+1
|
* Fix for explicit cast without RUBY_METHOD_FUNCNobuyoshi Nakada2019-09-201-1/+7
|
* Check various method defitions in C++Nobuyoshi Nakada2019-09-201-10/+26
|
* Check method functions in C++Nobuyoshi Nakada2019-09-201-64/+83
| | | | By using template and overloading, instead of transparent union.
* rb_scan_args_count_lead: use arguments instead of magic numbersNobuyoshi Nakada2019-09-151-5/+7
|
* Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from RubyJeremy Evans2019-09-141-0/+1
| | | | | | | | | | | 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)
* Consolidate empty keyword handlingJeremy Evans2019-09-131-0/+4
| | | | | | | | | | | | | | | | | | | | | | 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.
* workaround for C++ 98 const union problem.卜部昌平2019-09-091-1/+6
| | | | | | | | | | | 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.
* Fix keyword argument separation warnings for enumeratorsJeremy Evans2019-09-061-0/+1
| | | | | | | | | | 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.
* Convert keyword argument to required positional hash argument for Class#new, ↵Jeremy Evans2019-09-061-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* add include/ruby/backward/cxxanyargs.hpp卜部昌平2019-09-061-0/+5
| | | | | | | | | | | | | | 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.
* Add rb_funcall_with_block_kwJeremy Evans2019-09-051-0/+1
| | | | | | | | | | | | | | | | | 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.
* hide rb_funcallv_with_cc from public卜部昌平2019-09-051-14/+1
| | | | | | 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.
* add rb_funcallv_with_cc()Urabe, Shyouhei2019-09-041-1/+14
| | | | | | 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.