aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
Commit message (Collapse)AuthorAgeFilesLines
* Clear all trace events during teardownAlan Wu2020-03-301-1/+2
| | | | | | | | | | | | | Since 0c2d81dada, not all trace events are cleared during VM teardown. This causes a crash when there is a tracepoint for `RUBY_INTERNAL_EVENT_GC_EXIT` active during teardown. The commit looks like a refactoring commit so I think this change was unintentional. [Bug #16682] (cherry picked from commit b385f7670ffa420790bc548747fa4b58c4c5d8f6)
* Kernel#abort without arguments should print error infoNobuyoshi Nakada2019-12-161-3/+3
| | | | [Bug #16424]
* Make prepending a refined module after inclusion not break refinementsJeremy Evans2019-11-281-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | After the previous commit, this was still broken. The reason it was broken is that a refined module that hasn't been prepended to yet keeps the refined methods in the module's method table. When prepending, the module's method table is moved to the origin iclass, and then the refined methods are moved from the method table to a new method table in the module itself. Unfortunately, that means that if a class has included the module, prepending breaks the refinements, because when the methods are moved from the origin iclass method table to the module method table, they are removed from the method table from the iclass created when the module was included earlier. Fix this by always creating an origin class when including a module that has any refinements, even if the refinements are not currently used. I wasn't sure the best way to do that. The approach I choose was to use an object flag. The flag is set on the module when Module#refine is called, and if the flag is present when the module is included in another module or class, an origin iclass is created for the module. Fixes [Bug #13446]
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-181-1/+0
| | | | | | | | | | | | | | | | | 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.
* Suppress "clobbered" warnings by gcc 9.2.0Nobuyoshi Nakada2019-10-121-2/+8
|
* Adjusted spaces [ci skip]Nobuyoshi Nakada2019-09-271-2/+2
|
* Revert eval.c in e81a3e6df54842b5a836dad7055a4295cf4155bcNobuyoshi Nakada2019-09-211-4/+3
| | | | | Inadvertently merged change to suppress warnings by gcc 9.2. Pointed out by Alan Wu.
* Allows calling a private method only with bare `self`Nobuyoshi Nakada2019-09-201-3/+4
|
* Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from RubyJeremy Evans2019-09-141-1/+8
| | | | | | | | | | | 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-14/+1
| | | | | | | | | | | | | | | | | | | | | | 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.
* 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.
* eval.c (rb_rescue2): fix a probably wrong returnYusuke Endoh2019-09-071-1/+2
| | | | | This return skips `va_end(ap)`, which is not intended, I guess. Coverity Scan found this.
* add include/ruby/backward/cxxanyargs.hpp卜部昌平2019-09-061-3/+15
| | | | | | | | | | | | | | 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.
* Merge pull request #2422 from jeremyevans/rb_keyword_given_pJeremy Evans2019-09-031-0/+8
| | | Add rb_keyword_given_p to the C-API
* Unify SUPPORT_JOKE and OPT_SUPPORT_JOKETakashi Kokubun2019-09-031-1/+1
| | | | | | | | | | for simplicity and consistency. Now SUPPORT_JOKE needs to be prefixed with OPT_ to make the config visible in `RubyVM::VmOptsH`, and the inconsistency was introduced. As it has never been available for override in configure (no #ifndef guard), it should be fine to rename the config.
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-2/+2
| | | | | | 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.
* move docs around [ci skip]卜部昌平2019-08-291-22/+64
| | | | To properly generate documents.
* drop-in type check for rb_define_global_function卜部昌平2019-08-291-8/+32
| | | | | | 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_define_hooked_variable now free from ANYARGS卜部昌平2019-08-271-2/+2
| | | | | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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 dda5dc00cff334cac373096d444a0fd59e716124.
* rb_ensure now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches.
* rb_rescue / rb_rescue2 now free from ANYARGS卜部昌平2019-08-271-4/+4
| | | | | | 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.
* Make it as clear as possible that RubyVM is MRI-specific and only exists on ↵Benoit Daloze2019-08-191-1/+1
| | | | | | | | | | | | | MRI (#2113) [ci skip] * Make it clear as possible that RubyVM is MRI-specific and only exists on MRI * See [Bug #15743]. * Use "CRuby VM" instead of "Ruby VM" for clarity. * Use YARV rather than "CRuby VM" for documenting RubyVM::InstructionSequence * Avoid introducing a new "CRuby VM" term in documentation
* Suppress Uninitialized variables by Coverity ScanKazuhiro NISHIYAMA2019-08-141-1/+1
| | | | | | | | | | | | | Coverity Scan says: ``` ** CID 1452284: Uninitialized variables (UNINIT) /eval.c: 223 in rb_ec_cleanup() ``` ``` >>> CID 1452284: Uninitialized variables (UNINIT) >>> Using uninitialized value "errs[1]". ```
* Pass rb_execution_context_t* in ruby_run_nodeNobuyoshi Nakada2019-08-131-18/+28
|
* * expand tabs.git2019-08-131-4/+4
|
* Renamed ruby_finalize_{0,1}Nobuyoshi Nakada2019-08-131-18/+21
| | | | And pass rb_execution_context_t as an argument.
* Adjust documentation for Kernel#raise [ci skip]Jeremy Evans2019-07-221-14/+14
| | | | | | | Mention how each of the arguments are retrievable from the generated Exception object. Fixes [Bug #10110]
* constify again.Koichi Sasada2019-07-221-5/+5
| | | | | | | | | | | | | | | | | | | | 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.
* * expand tabs.git2019-07-141-1/+1
|
* Prefer `rb_error_arity` to `rb_check_arity` when it can be usedYusuke Endoh2019-07-141-2/+1
|
* Include inspect value of object in FrozenError messagesJeremy Evans2019-06-041-1/+1
| | | | | | | | | | FrozenError#receiver was added recently for getting the related object programmatically. However, there are cases where FrozenError is raised and not handled, and in those cases the resulting error messages lack detail, which makes debugging the error more difficult, especially in cases where the error is not easily reproducible. This includes the inspect value of the frozen object in FrozenError messages, which should make debugging simpler.
* * expand tabs.git2019-05-271-1/+1
|
* Add FrozenError#receiverJeremy Evans2019-05-261-1/+1
| | | | | | | | | | | | | | | | | 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]
* Introduce pattern matching [EXPERIMENTAL]ktsj2019-04-171-1/+1
| | | | | | [ruby-core:87945] [Feature #14912] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] fix markups [ci skip]nobu2019-03-221-18/+18
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* eval.c: clear internal errinfonobu2019-03-101-0/+1
| | | | | | | * eval.c (ruby_cleanup): clear internal error info when invoking end procs. [ruby-core:91731] [Bug #15650] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* mjit.c: use boolean type for boolean variablesk0kubun2019-01-101-1/+1
| | | | | | | | | | and functions to clarify the intention and make sure it's not used in a surprising way (like using 2, 3, ... other than 0, 1 even while it seems to be a boolean). This is a retry of r66775. It included some typos... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert "mjit.c: use boolean type for boolean variables"k0kubun2019-01-101-1/+1
| | | | | | | | This reverts commit bb1a1aeab0f2a5fe437c89b841a887ba56653453. We hit something on ci.rvm.jp, reverting until investigation is done. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* mjit.c: use boolean type for boolean variablesk0kubun2019-01-101-1/+1
| | | | | | | | and functions to clarify the intention and make sure it's not used in a surprising way (like using 2, 3, ... other than 0, 1 even while it seems to be a boolean). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Document the "cause" keyword argument for raiseknu2018-12-241-4/+9
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Prohibit circular causes [Bug #15447]nobu2018-12-231-0/+15
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Restrict cause to an exception object [Bug #15447]nobu2018-12-231-0/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c: avoid dlclose before execk0kubun2018-11-261-1/+1
| | | | | | | | | | because JIT-ed code may still be on stack at this time, unlike in ruby_cleanup(). This hopes to fix: (take 2) http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480207 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2018-11-051-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Don't set throw data as cause [Bug #15282]naruse2018-11-051-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c: add a map from encoded insn to insn datamame2018-08-231-1/+1
| | | | | | | | | | This enhances rb_vm_insn_addr2insn which retrieves a decoded insn number from encoded insn. The insn data table include not only decoded insn number, but also its len, trace and non-trace version of encoded insn. This table can be used to simplify trace instrumentation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* eval.c: rename "rb_frozen_class_p" to "rb_class_modify_check"mame2018-07-271-1/+1
| | | | | | | | | | Just refactoring. Despite its name, the function does NOT return a boolean but raises an exception when the class given is frozen. I don't think the new name "rb_class_modify_check" is the best, but it follows the precedeint "rb_ary_modify_check", and is definitely better than "*_p". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* UNREACHABLE_RETURNnobu2018-07-241-1/+1
| | | | | | | * include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end of non-void functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rb_vm_insn_addr2insn: use st to perform addr2insn mappingnormal2018-06-061-0/+1
| | | | | | | | | | | | | | | | | The current VM_INSTRUCTION_SIZE is 198, so the linear search painful during a major GC phase. I noticed rb_vm_insn_addr2insn2 showing up at the top of some profiles while working on some malloc-related stuff, so I decided to attack it. Most notably, the benchmark/bm_vm3_gc.rb improves by over 40%: https://80x24.org/spew/20180602220554.GA9991@whir/raw [ruby-core:87361] [Feature #14814] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* share :cause variablenobu2018-05-151-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e