aboutsummaryrefslogtreecommitdiffstats
path: root/proc.c
Commit message (Collapse)AuthorAgeFilesLines
* [DOC] Update Proc.new without a block [ci skip]Nobuyoshi Nakada2021-01-041-9/+6
| | | | | [Feature #10499] [Feature #15554]
* [DOC] Fix typo in proc.cMarcus Stollsteimer2020-12-261-1/+1
|
* Fix class of method in Method#inspect for singleton classes of classesJeremy Evans2020-12-231-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | Previously, due to a change to fix bug 15608, Method#inspect output changed for class methods: Ruby 2.7 "#<Method: String.prepend(*)>" Before change: "#<Method: #<Class:Object>(Module)#prepend(*)>" This is wrong because the Method object was created from String and not Object. This is because the fix for bug 15608 assumed it was being called on the singleton class of a instance, and would skip the first singleton class until it got to the class itself. For class methods, this results in always using the superclass. Fix behavior to not skip until the superclass if the singleton class is the singleton class of a module or class. After change: "#<Method: #<Class:Object>(Module)#prepend(*)>" Fixes [Bug #17428]
* Document Proc#==zverok2020-12-211-0/+26
|
* fix lambda's warning and testsKoichi Sasada2020-12-121-14/+22
| | | | | There are warning condition bugs and test bugs. b53ccb9c69abd24e3bdad66cbe4c7e7480eaef16
* show deprecation warning correctly for lambda(&b)Koichi Sasada2020-12-111-3/+11
| | | | | | | | | lambda(&b) where b is given block of method (like: def foo(&b)) should warn correctly. [Feature #17361] Also labmda(&labmda_block) or lambda(&:to_s) (Symbol#to_proc) should not warn (but I'm not sure who cares about it).
* Fix typo on Proc docsTomás Coêlho2020-11-161-1/+1
|
* Add `GC.auto_compact= true/false` and `GC.auto_compact`Aaron Patterson2020-11-021-4/+1
| | | | | | | | | | * `GC.auto_compact=`, `GC.auto_compact` can be used to control when compaction runs. Setting `auto_compact=` to true will cause compaction to occurr duing major collections. At the moment, compaction adds significant overhead to major collections, so please test first! [Feature #17176]
* check isolated Proc more strictlyKoichi Sasada2020-10-291-1/+8
| | | | | Isolated Proc prohibit to access outer local variables, but it was violated by binding and so on, so they should be error.
* Use proc_binding rather than rb_funcallChris Seaton2020-10-061-1/+2
| | | | FIX
* Moved rb_callable_receiver internalNobuyoshi Nakada2020-10-061-3/+6
|
* Warn on a finalizer that captures the object to be finalizedChris Seaton2020-09-161-0/+12
| | | | | Also improve specs and documentation for finalizers and more clearly recommend a safe code pattern to use them.
* Fix Method#super_method for aliased methodsJeremy Evans2020-08-271-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | Previously, Method#super_method looked at the called_id to determine the method id to use, but that isn't correct for aliased methods, because the super target depends on the original method id, not the called_id. Additionally, aliases can reference methods defined in other classes and modules, and super lookup needs to start in the super of the defined class in such cases. This adds tests for Method#super_method for both types of aliases, one that uses VM_METHOD_TYPE_ALIAS and another that does not. Both check that the results for calling super methods return the expected values. To find the defined class for alias methods, add an rb_ prefix to find_defined_class_by_owner in vm_insnhelper.c and make it non-static, so that it can be called from method_super_method in proc.c. This bug was original discovered while researching [Bug #11189]. Fixes [Bug #17130]
* add UNREACHABLE_RETURN卜部昌平2020-06-291-0/+2
| | | | | | Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities.
* proc_binding: do not goto into a branch卜部昌平2020-06-291-7/+4
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* rb_obj_singleton_method: do not goto into a branch卜部昌平2020-06-291-13/+24
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* rb_method_name_error: do not goto into a branch卜部昌平2020-06-291-4/+2
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* bind_local_variable_get: do not goto into a branch卜部昌平2020-06-291-6/+6
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* Removed space linesNobuyoshi Nakada2020-06-201-2/+0
|
* Remove unused variablesKazuki Tsujimoto2020-06-201-1/+0
|
* Implement Proc#== and #eql?Jeremy Evans2020-06-191-0/+62
| | | | | | | | | | Previously, these were not implemented, and Object#== and #eql? were used. This tries to check the proc internals to make sure that procs created from separate blocks are treated as not equal, but procs created from the same block are treated as equal, even when the lazy proc allocation optimization is used. Implements [Feature #14267]
* rb_method_name_error: delete unused code卜部昌平2020-06-171-1/+0
| | | | | | | | | | | If you look at the code flow (break -> goto), this assignment never makes any sense. Should just remove. I _guess_ this behaviour is unintended. Original code at commit 4dc1a2180946ab793adee5eb235fc4ee8fa4cefe did something. It might be the code flow that is buggy. However rubyspec already includes this particular edge case at ruby/core/module/undef_method_spec.rb. I don't think we can change the way it is any longer.
* Warn when passing a non-literal block to Kernel#lambdaJeremy Evans2020-06-111-0/+13
| | | | Implements [Feature #15973]
* Make proc/Proc.new without block an error instead of warningJeremy Evans2020-06-101-41/+1
| | | | The warning for these was added in 2.7.
* Work around infinite loop when overriding method visibility in prepended ↵Jeremy Evans2020-06-091-2/+2
| | | | | | | module (#3201) For ZSUPER methods with no defined class for the method entry, start the next lookup at the superclass of the origin class of the method owner, instead of the superclass of the method owner. Fixes [Bug #16942]
* [DOC] Separated Method#[] from Method#call [Bug #16813] [ci skip]Nobuyoshi Nakada2020-04-241-1/+13
|
* [DOC] Fixed explanation for Method#>> [Bug #16813] [ci skip]Nobuyoshi Nakada2020-04-241-2/+2
|
* Suppress -Wswitch warningsNobuyoshi Nakada2020-04-081-0/+3
|
* Merge pull request #2721 from jeremyevans/method-inspect-chain-alias-11188Jeremy Evans2020-03-221-2/+2
| | | Correctly show defined class for aliases of aliases
* `Proc` made by `Hash#to_proc` should be a lambda [Bug #12671]Yusuke Endoh2020-03-161-4/+4
| | | | Like `Symbol#to_proc` (f0b815dc670b61eba1daaa67a8613ac431d32b16)
* hash.c: Do not use the fast path (rb_yield_values) for lambda blocksYusuke Endoh2020-03-161-0/+35
| | | | | | | | | | | | | | | | | As a semantics, Hash#each yields a 2-element array (pairs of keys and values). So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception due to lambda's arity check. However, the optimization that avoids Array allocation by using rb_yield_values for blocks whose arity is more than 1 (introduced at b9d29603375d17c3d1d609d9662f50beaec61fa1 and some commits), seemed to overlook the lambda case, and wrongly allowed the code above to work. This change experimentally attempts to make it strict; now the code above raises an ArgumentError. This is an incompatible change; if the compatibility issue is bigger than our expectation, it may be reverted (until Ruby 3.0 release). [Bug #12706]
* proc.c: Remove non-sense /* fall through */Yusuke Endoh2020-03-161-1/+0
|
* Don't display singleton class in Method#inspect unless method defined thereJeremy Evans2020-03-091-1/+8
| | | | | | | | | | | Previously, if an object has a singleton class, and you call Object#method on the object, the resulting string would include the object's singleton class, even though the method was not defined in the singleton class. Change this so the we only show the singleton class if the method is defined in the singleton class. Fixes [Bug #15608]
* Proc from Symbol needs a receiverNobuyoshi Nakada2020-02-221-1/+2
| | | | | | | So its arity should be -2 instead of -1. [Bug #16640] https://bugs.ruby-lang.org/issues/16640#change-84337
* `Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]Nobuyoshi Nakada2020-02-221-1/+1
| | | | With refinements, too.
* `Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]Nobuyoshi Nakada2020-02-191-0/+1
|
* Check if bindable against the refined target [Bug #16617]Nobuyoshi Nakada2020-02-091-0/+5
|
* Fix wrong return value in proc documentation.Florian Heinle2020-01-301-1/+1
|
* Rename RUBY_MARK_NO_PIN_UNLESS_NULL to RUBY_MARK_MOVABLE_UNLESS_NULL0x005c2020-01-231-5/+5
|
* Fully separate positional arguments and keyword argumentsJeremy Evans2020-01-021-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | 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().
* Decide lambdaness of (f << g) using g (#2729)Alan Wu2019-12-301-2/+8
| | | | | | * Deciding lambdaness of (f << g) using g * Use version guards for spec changes
* decouple internal.h headers卜部昌平2019-12-261-2/+7
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* internal/imemo.h rework卜部昌平2019-12-261-1/+2
| | | | | | Arrange contents and eliminate macros, to make them readable. Macro IFUNC_NEW was deleted because there was only one usage.
* Adjust sentence in doc [ci skip]Alan Wu2019-12-221-1/+1
|
* Actualize Method#inspect docszverok2019-12-221-2/+21
|
* Document numbered block parameterszverok2019-12-221-0/+50
|
* Kernel#lambda: return forwarded block as non-lambda procAlan Wu2019-12-211-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | Before this commit, Kernel#lambda can't tell the difference between a directly passed literal block and one passed with an ampersand. A block passed with an ampersand is semantically speaking already a non-lambda proc. When Kernel#lambda receives a non-lambda proc, it should simply return it. Implementation wise, when the VM calls a method with a literal block, it places the code for the block on the calling control frame and passes a pointer (block handler) to the callee. Before this commit, the VM forwards block arguments by simply forwarding the block handler, which leaves the slot for block code unused when a control frame forwards its block argument. I use the vacant space to indicate that a frame has forwarded its block argument and inspect that in Kernel#lambda to detect forwarded blocks. This is a very ad-hoc solution and relies *heavily* on the way block passing works in the VM. However, it's the most self-contained solution I have. [Bug #15620]
* Added rb_warn_deprecatedNobuyoshi Nakada2019-12-191-2/+2
|
* Add Proc#ruby2_keywordsJeremy Evans2019-12-091-0/+65
| | | | | | | | | | | | This allows passing keywords through a normal argument splat in a Proc. While needing ruby2_keywords support for methods is more common, there is code that delegates keywords through normal argument splats in procs, including code in Rails. For that reason, it makes sense to expose this for procs as well. Internally, ruby2_keywords is not tied to methods, but iseqs, so this just allows for setting the ruby2_keywords for the iseq related to the proc.
* Make {Method,UnboundMethod}#super_method handle clone/bind/unbindJeremy Evans2019-12-041-5/+11
| | | | | | | | This wasn't working previously because the iclass entry wasn't being copied, and without an iclass entry, super_method returns nil. Fixes [Bug #15629]