aboutsummaryrefslogtreecommitdiffstats
path: root/vm_eval.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove rb_eval_cmdJeremy Evans2020-02-111-7/+0
| | | | | This was related to $SAFE, and was deprecated in 2.7. I missed it earlier when removing the other $SAFE-related code.
* script_compiled event on compile error.Koichi Sasada2020-01-061-6/+8
| | | | | | script_compiled event for TracePoint should not be invoked on compile error (SyntaxError) because it is not "compiled". [Bug #16459]
* Make eval(code, binding) use (eval) as __FILE__ and 1 as __LINE__Jeremy Evans2020-01-031-6/+0
| | | | | | | | | This removes the warning that was added in 3802fb92ff8c83eed3e867db20f72c53932f542d, and switches the behavior so that the eval does not use the binding's __FILE__ and __LINE__ implicitly. Fixes [Bug #4352]
* Fully separate positional arguments and keyword argumentsJeremy Evans2020-01-021-89/+17
| | | | | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | warnings
* delete rb_vm_call()卜部昌平2019-12-181-6/+0
| | | | Nobody uses it any longer.
* per-method serial number卜部昌平2019-12-181-1/+1
| | | | | | | | | | | | | | | | | Methods and their definitions can be allocated/deallocated on-the-fly. One pathological situation is when a method is deallocated then another one is allocated immediately after that. Address of those old/new method entries/definitions can be the same then, depending on underlying malloc/free implementation. So pointer comparison is insufficient. We have to check the contents. To do so we introduce def->method_serial, which is an integer unique to that specific method definition. PS: Note that method_serial being uintptr_t rather than rb_serial_t is intentional. This is because rb_serial_t can be bigger than a pointer on a 32bit system (rb_serial_t is at least 64bit). In order to preserve old packing of struct rb_call_cache, rb_serial_t is inappropriate.
* ensure cc->def == cc->me->def卜部昌平2019-12-161-9/+12
| | | | | | | The equation shall hold for every call cache. However prior to this changeset cc->me could be updated without also updating cc->def. Let's make it sure by introducing new macro named CC_SET_ME which sets cc->me and cc->def at once.
* Make rb_eval_string_wrap specify a cref so constant setting works correctlyJeremy Evans2019-12-051-1/+21
| | | | Fixes [Bug #10466]
* make functions static卜部昌平2019-11-191-1/+3
| | | | | | | These functions are used from within a compilation unit so we can make them static, for better binary size. This changeset reduces the size of generated ruby binary from 26,590,128 bytes to 26,584,472 bytes on my macihne.
* Deprecate rb_eval_cmd, add rb_eval_cmd_kwJeremy Evans2019-11-181-3/+10
| | | | | | | | 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.
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-181-8/+1
| | | | | | | | | | | | | | | | | 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.
* extend rb_call_cache卜部昌平2019-11-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | Prior to this changeset, majority of inline cache mishits resulted into the same method entry when rb_callable_method_entry() resolves a method search. Let's not call the function at the first place on such situations. In doing so we extend the struct rb_call_cache from 44 bytes (in case of 64 bit machine) to 64 bytes, and fill the gap with secondary class serial(s). Call cache's class serials now behavies as a LRU cache. Calculating ------------------------------------- ours 2.7 2.6 vm2_poly_same_method 2.339M 1.744M 1.369M i/s - 6.000M times in 2.565086s 3.441329s 4.381386s Comparison: vm2_poly_same_method ours: 2339103.0 i/s 2.7: 1743512.3 i/s - 1.34x slower 2.6: 1369429.8 i/s - 1.71x slower
* refactor assign variables卜部昌平2019-10-261-8/+5
| | | | | | For readability. Requested by ko1. See: https://github.com/ruby/ruby/commit/356e203a3acd4d3d20ba12f956fd22e17b6363e9#r35661401
* more on struct rb_call_data卜部昌平2019-10-251-33/+31
| | | | | Replacing adjacent struct rb_call_info and struct rb_call_cache into a struct rb_call_data.
* vm_eval.c (rb_adjust_argv_kw_splat): avoid memcpy with zero lengthYusuke Endoh2019-10-091-1/+1
| | | | | | | | | A method call is often with `argc = 1` and `argv = &v` where v is a VALUE, and some functions shift the arguments by `argc-1` and `argv+1` (for example, rb_sym_proc_call). I'm unsure whether it is safe or not to pass a pointer `argv+1` to memcpy with zero length, but Coverity Scan complains it. So this attempts to suppress the warning by explicit check of the length.
* Make parser_params have parent_iseq instead of base_blockYusuke Endoh2019-10-041-1/+1
| | | | | | | | | | | | The parser needs to determine whether a local varaiable is defined or not in outer scope. For the sake, "base_block" field has kept the outer block. However, the whole block was actually unneeded; the parser used only base_block->iseq. So, this change lets parser_params have the iseq directly, instead of the whole block.
* Issue keyword flag warning even with no argumentsJeremy Evans2019-09-301-1/+1
| | | | | | If the keyword flag is set, there should be at least one argument, if there isn't, that is a sign the keyword flag was passed when it should not have been.
* Add three more C-API functions for handling keywordsJeremy Evans2019-09-291-0/+33
| | | | | | | | 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.
* Remove VM_NO_KEYWORDS, replace with RB_NO_KEYWORDSJeremy Evans2019-09-291-3/+3
| | | | | VM_NO_KEYWORDS was introduced first in vm_core.h, but it is best to only use a single definition for this.
* Make direct calls to rb_{obj_instance,mod_module}_{eval,exec} not pass keywordsJeremy Evans2019-09-291-14/+39
| | | | | | | | | | | | In general RB_PASS_CALLED_KEYWORDS should only be set if we are sure the arguments passed come directly from Ruby. For direct calls to these C functions, we should not assume that keywords are passed. Add static *_internal versions of these functions that Kernel#instance_{eval,exec} and Module#{class,module}_{eval,exec} call that set RB_PASS_CALLED_KEYWORDS. Also, change struct.c back to calling rb_mod_module_eval, now that the call is safe.
* Fix more keyword separation issuesJeremy Evans2019-09-261-11/+39
| | | | | | | | | | | | | | | | | | | | | 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
* Make public_send and rb_f_send handle keyword argument separationJeremy Evans2019-09-231-2/+25
| | | | | Kernel#send takes a different optimized code path that was already handled.
* Call rb_vm_call_kw insted of rb_vm_call0 in a few casesJeremy Evans2019-09-201-25/+11
| | | | | | | | | | rb_vm_call_kw handles the tmp buffer for you. Also, change method_missing so it also calls rb_vm_call_kw to handle the kw_splat flag, instead of requiring callers to handle kw_splat flag before calling method_missing. This may fix other cases where method_missing is currently called without the kw_splat being handled.
* Handle keyword argument separation for Enumerator#sizeJeremy Evans2019-09-201-6/+22
| | | | | | | | | 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.
* Make passing empty keywords to dig pass empty keywords to next dig methodJeremy Evans2019-09-201-9/+22
| | | | | | | | | | | | | | | | If defined in Ruby, dig would be defined as def dig(arg, *rest) end, it would not use keywords. If the last dig argument was an empty hash, it could be treated as keyword arguments by the next dig method. Allow dig to pass along the empty keyword flag if called with an empty keyword, to suppress the previous behavior and force treating the hash as a positional argument and not keywords. Also handle the case where dig calls method_missing, passing the empty keyword flag to that as well. This requires adding rb_check_funcall_with_hook_kw functions, so that dig can specify how arguments are treated. It also adds kw_splat arguments to a couple static functions.
* refactor reuse existing on-stack structs卜部昌平2019-09-191-1/+12
| | | | | | rb_vm_call0 allocates its own struct call_info etc. But they are already there in case of rb_funcallv_with_cc. Let's just pass the existing ones, instead of re-creation.
* Fix keyword argument separation issues with sym procs when using refinementsJeremy Evans2019-09-171-7/+7
| | | | | | | | | | | | Make sure that vm_yield_with_cfunc can correctly set the empty keyword flag by passing 2 as the kw_splat value when calling it in vm_invoke_ifunc_block. Make sure calling.kw_splat is set to 1 and not 128 in vm_sendish, so we can safely check for different kw_splat values. vm_args.c needs to call add_empty_keyword, and to make JIT happy, the function needs to be exported. Rename the function to rb_adjust_argv_kw_splat to more accurately reflect what it does, and mark it as MJIT exported.
* Pass keyword argument flag when rb_call_super_kw calls method_missingJeremy Evans2019-09-171-11/+12
| | | | | | | | This makes method_missing take a flag for whether keyword arguments were passed. Adds tests both for rb_call_super_kw usage as well as general usage of super calling method_missing in Ruby methods.
* Issue a warning if invalid kw_splat is passed to *_kw functionJeremy Evans2019-09-141-0/+6
| | | | | | This should only happen if the API is misused. It's much better to warn here and fix the problem, versus to try to debug TypeErrors or segfaults later.
* Keep the reference of imemo while argv may be usedTakashi Kokubun2019-09-141-13/+25
| | | | | To prevent the `v` reference from being eliminated before argv is used, calling `rb_free_tmp_buffer` against `v` explicitly.
* Fixed one-off errorNobuyoshi Nakada2019-09-141-1/+1
| | | | Needs another room to append an empty hash.
* Fix memory leak when adding empty keyword hashesJeremy Evans2019-09-141-2/+3
| | | | | | | nagachika pointed out that ALLOC_N is actually just malloc, so this memory wasn't being freed. This shouldn't be a performance sensitive code path, and will be going away after 2.7, so just allocate a temp buffer that will be freed later by Ruby GC.
* Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from RubyJeremy Evans2019-09-141-3/+12
| | | | | | | | | | | 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)
* * remove trailing spaces. [ci skip]git2019-09-141-1/+1
|
* Consolidate empty keyword handlingJeremy Evans2019-09-131-1/+25
| | | | | | | | | | | | | | | | | | | | | | 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.
* Correctly handle keywords for Method#call for cfuncs, send, and attr_*Jeremy Evans2019-09-131-4/+35
| | | | | | | | | This sets the correct VM frame flags when using Method#call to call funcs, and handles empty keyword hashes for cfuncs, attr_reader, and attr_writer. It also fixes calls to send through Method#call. It adds tests for all of those, as well as tests for using Method#call to call define_method, lambda, and sym_procs (which didn't require code changes).
* Fix keyword argument separation warnings for enumeratorsJeremy Evans2019-09-061-1/+19
| | | | | | | | | | 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-1/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* doxygen update [ci skip]卜部昌平2019-09-061-1/+2
|
* Add rb_funcall_with_block_kwJeremy Evans2019-09-051-12/+30
| | | | | | | | | | | | | | | | | 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.
* Propagate kw_splat informationYusuke Endoh2019-09-051-1/+2
| | | | | | | The kw_splat flag is whether the original call passes keyword or not. Some types of methods (e.g., bmethod and sym_proc) drops the information. This change tries to propagate the flag to the final callee, as far as I can.
* hide rb_funcallv_with_cc from public卜部昌平2019-09-051-24/+9
| | | | | | 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.
* use existing vm_search_method()卜部昌平2019-09-051-16/+10
| | | | | | | | | | Ko1 plans to implement Guild. That can interface the caching mechanism introduced here. To prevent future breakage we would better avoid rolling our own code here. Instead use the existing vm_search_method() which would be modified by him. This commit deletes some asserions, but they are in fact checked inside of vm_search_method().
* add rb_funcallv_with_cc()Urabe, Shyouhei2019-09-041-0/+50
| | | | | | 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.
* delete ruby_eval_string_from_file_protect卜部昌平2019-09-031-21/+0
| | | | Not used from anywhere.
* drop-in type check for rb_define_global_function卜部昌平2019-08-291-3/+3
| | | | | | 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.
* rb_catch now free from ANYARGS卜部昌平2019-08-271-3/+3
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_catch, and fixes some bugs revealed by that.
* rb_rescue / rb_rescue2 now free from ANYARGS卜部昌平2019-08-271-3/+5
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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.
* rb_iterate now takes rb_block_call_func_t卜部昌平2019-08-271-1/+1
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit makes rb_iterate free from ANYARGS.