aboutsummaryrefslogtreecommitdiffstats
path: root/include
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* a bit terse Doxygen comments [ci skip]卜部昌平2020-01-311-167/+35
| | | | | | Creative use of `@copydoc` Doxygen command and abusing its half-broken C parser let us delete some lines of documentations, while preserving document coverages.
* support C++ std::nullptr_t卜部昌平2020-01-311-1/+165
| | | | | | | 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.
* Fix a typo [ci skip]Kazuhiro NISHIYAMA2020-01-291-1/+1
|
* fix rb_define_global_function to take const VALUE*卜部昌平2020-01-281-1/+1
| | | | | It was unable for rb_define_global_function to take VALUE(*)(int argc, const VLAUE *argv, VALUE self) -style function. Test added.
* improved support for rb_f_notimplement卜部昌平2020-01-281-2/+18
| | | | | | rb_f_notimplement should be accepted for all possible arities. Test provided for that.
* delete duplicated function overload卜部昌平2020-01-281-2/+0
| | | | | The `using engine<...snip...>::define;` line already defines this function. We don't have to repeat.
* fix typo卜部昌平2020-01-281-4/+4
| | | | Add missing `*`.
* 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-282-9/+189
| | | | | | 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-282-202/+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-092-1/+4
| | | | | 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().
* re-add io.h and encoding.h into internal.h卜部昌平2019-12-262-8/+0
| | | | | | This is tentative. For the sake of simplicity we partially revert commits e9cb552ec96, ee85a6e72b and 51edb300425. Will decouple them once again when we are ready.
* 2.8.0 (tentative; to be 3.0.0) development has started.Yukihiro "Matz" Matsumoto2019-12-261-1/+1
|
* 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
* Fixed misspellingsNobuyoshi Nakada2019-12-201-21/+21
| | | | Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
* forward declare struct timespec卜部昌平2019-12-101-0/+1
| | | | | | | ... 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.
* Deprecate rb_eval_cmd, add rb_eval_cmd_kwJeremy Evans2019-11-181-0/+1
| | | | | | | | 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.
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-3/+1
| | | | | | 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.
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-182-12/+11
| | | | | | | | | | | | | | | | | 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.
* Remove duplicate codeAaron Patterson2019-11-061-2/+1
| | | | | | These functions are the same, so remove one. Co-authored-by: John Hawthorn <john@hawthorn.email>
* mark functions that do not return NULL as such.卜部昌平2019-11-011-10/+19
| | | | Apply __attribute__((__returns_nonnull__)) when available.
* RUBY_ATTR_ALOC_SIZE for clang卜部昌平2019-11-011-1/+6
| | | | | clang also supports __attribute__((__alloc_size__)) so why not use it when the compiler says it does.
* Check for nonnull attribute in configureNobuyoshi Nakada2019-10-291-0/+3
|
* include/ruby/backward/cxxanyargs.hpp: call `va_end` before returnYusuke Endoh2019-10-241-1/+2
| | | | Coverity Scan complains it.
* 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-122-4/+4
|
* Moved RB_METHOD_DEFINITION_DECL to intern.hNobuyoshi Nakada2019-10-122-82/+96
| | | | This macro is used here before defined in ruby.h.
* annotate malloc-ish functions卜部昌平2019-10-091-3/+12
| | | | | Make them gcc friendly. Note that realloc canot be __malloc__ attributed, according to the GCC manual.
* 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.
* array.c (rb_mem_clear): remove "register" from argumentsYusuke Endoh2019-10-041-1/+1
| | | | | | | | | | | | | | | | 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); ^~~~~~~~~ ```
* Add rb_enumeratorize_with_size_kw and related macrosJeremy Evans2019-09-301-0/+11
| | | | | | | | | | 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.
* 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
|
* Fix keyword argument separation issues in Enumerator::Generator#eachJeremy Evans2019-09-261-0/+1
| | | | This requires adding rb_proc_call_kw to pass the keyword flag.
* Fix keyword argument separation issues in Fiber#resumeJeremy Evans2019-09-261-0/+2
|
* Fix keyword argument separation issues in Proc#{<<,>>}Jeremy Evans2019-09-261-0/+1
| | | | This requires adding rb_proc_call_with_block_kw.
* 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.
* st.c: Use rb_st_* prefix instead of st_* (#2479)Yusuke Endoh2019-09-222-41/+79
| | | | | | | | | | | 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.
* Disable method definition type checks on WindowsNobuyoshi Nakada2019-09-211-1/+1
|